/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
/*************************************************************************/
/* module:          SyncML internal API of the MGR module                */
/*                                                                       */   
/* file:            mgr.h                                                */
/* target system:   all                                                  */
/* target OS:       all                                                  */   
/*                                                                       */   
/* Description:                                                          */   
/* Definitions for internal use within the SyncML implementation         */
/*************************************************************************/


#ifndef _MGR_H
  #define _MGR_H


/*************************************************************************
 *  Definitions
 *************************************************************************/


#include <smldef.h>
#include <sml.h>
#include "wsm.h"
#include <xlttagtbl.h>


/**
 * ========================================
 * Definitions used for Instance Management
 * ========================================
 **/



/**
 * Current instance status
 **/
typedef enum {
  MGR_IDLE,                                   // instance is idle (available for usage by applications)
  MGR_USED,                                   // instance is in use, but currently inactive
  MGR_RECEIVE,                                // actively used for receiving (locked by application)
  MGR_SEND,                                   // actively used for sending (locked by application)
  MGR_ENCODING,                               // actively used for encoding (locked by SyncML)
  MGR_DECODING                                // actively used for decoding (locked by SyncML)
} InstanceStatus_t;



/** 
 * structure describing the current status of an instance,
 **/
typedef struct instance_info_s {
  InstanceID_t             id;                // unique ID of the instance
  MemPtr_t                 workspaceHandle;   // handle to the  first position of the assigned workspace memory
  InstanceStatus_t         status;            // current internal state of instance
  SmlCallbacksPtr_t        callbacks;         // Defined callback refererences for this Instance
  SmlInstanceOptionsPtr_t  instanceOptions;   // Defined options for this Instance (e.g. encoding type)
  VoidPtr_t                userData;          // Pointer to a structure, which is passed to the invoked callback functions  
  VoidPtr_t                workspaceState;	  // Pointer to a structure defining the current workspace status
  VoidPtr_t                encoderState;	    // Pointer to a structure defining the current encoder status
  VoidPtr_t                decoderState;	    // Pointer to a structure defining the current decoder status
  struct instance_info_s*  nextInfo;          // Pointer to next Instance Info in a list
} *InstanceInfoPtr_t, InstanceInfo_t;


/* Pointers to store the global Tag tables */
typedef struct tokeninfo_s {
    TagPtr_t  SyncML;
    TagPtr_t  MetInf;
    TagPtr_t  DevInf;
    /*
     * Change to support TNDS. 
     */
    TagPtr_t  Tnds;
} *TokenInfoPtr_t, TokenInfo_t;

/** 
 * structure describing the current status of the global syncml module
 * (holds all global variables within SyncML)
 **/
typedef struct syncml_info_s {
  InstanceInfoPtr_t        instanceListAnchor;// Anchor of the global list of known SyncML instances
  SmlOptionsPtr_t          syncmlOptions;     // Options valid for this SyncML Process
  WsmGlobalsPtr_t          wsmGlobals;        // Workspace global variables
  TokenInfoPtr_t           tokTbl;
} *SyncMLInfoPtr_t, SyncMLInfo_t;






/*************************************************************************
 *  External Function Declarations
 *************************************************************************/


/**
 * FUNCTION:  mgrGetSyncMLInfo
 * Retrieves a pointer to the structure holding all global informations within SyncML
 *
 * RETURN:    SyncMLInfoPtr_t         
 *            Pointer to the pGlobalAnchor
 */
SyncMLInfoPtr_t mgrGetSyncMLAnchor(void);


/**
 * FUNCTION:  mgrGetInstanceListAnchor
 * Retrieves a pointer to the list holding all instance informations
 *
 * RETURN:    InstanceInfoPtr_t         
 *            Pointer to the pInstanceListAnchor
 */
InstanceInfoPtr_t mgrGetInstanceListAnchor(void);


/**
 * FUNCTION:  mgrSetInstanceListAnchor
 * Set the pointer to the list holding all instance informations
 *
 * IN:        InstanceInfoPtr_t         
 *            Pointer to the pInstanceListAnchor
 */
void mgrSetInstanceListAnchor(InstanceInfoPtr_t newListAnchor);

 
#endif
