/*-------------------------------------------------------------------------
 * Name:   gci.h
 * Author: ITEX C-Code Generator
 *
 * Copyright 1999-2000 Telelogic AB, All rights reserved.
 * 
 * This Program is owned by Telelogic and is protected by national
 * copyright laws and international copyright treaties. Telelogic
 * grants you the right to use this Program on one computer or in one
 * local computer network at any one time.  Under this License you may
 * only modify the source code for the purpose of adapting it to your
 * environment. You must reproduce and include any copyright and
 * trademark notices on all copies of the source code.  You may not
 * use, copy, merge, modify or transfer the Program except as provided
 * in this License.  Telelogic does not warrant that the Program will
 * meet your requirements or that the operation of the Program will be
 * uninterrupted and error free. You are solely responsible that the
 * selection of the Program and the modification of the source code
 * will achieve your intended results and that the results are
 * actually obtained.
 */
#ifndef GCI_H
#define GCI_H
#include <stdio.h>
#include "gcidefs.h"
#include "egci.h"

/*-------------------------------------------------------------------------
 *      Constructors and access methods for (atomic) GciValues.
 */

GciValue*       GciMkINTEGER(long);
long              GciGetINTEGER(GciValue *);
GciValue*       GciMkBOOLEAN(int);
Bool              GciGetBOOLEAN(GciValue *);
GciValue*       GciMkREAL(int, int, int);
/*GciReal*      GciGetREAL(GciValue *);*/
GciValue*       GciGetREAL(GciValue *);
GciValue*       GciMkBIT_STRING(const char *);
char*           GciGetBIT_STRING(GciValue *);
GciValue*       GciMkHEXSTRING(const char *);
char*             GciGetHEXSTRING(GciValue *);
GciValue*       GciMkOCTET_STRING(const char *);
char*             GciGetOCTET_STRING(GciValue *);
GciValue*       GciMkNumericString(const char *);
char*             GciGetNumericString(GciValue *);
GciValue*       GciMkPrintableString(const char *);
char*             GciGetPrintableString(GciValue *);
GciValue*       GciMkTeletexString(const char *);
char*             GciGetTeletexString(GciValue *);
GciValue*       GciMkVideotexString(const char *);
char*             GciGetVideotexString(GciValue *);
GciValue*       GciMkVisibleString(const char *);
char*           GciGetVisibleString(GciValue *);
GciValue*       GciMkIA5String(const char *);
char*           GciGetIA5String(GciValue *);
GciValue*       GciMkT61String(const char *);
char*           GciGetT61String(GciValue *);
GciValue*       GciMkISO646String(const char *);
char*             GciGetISO646String(GciValue *);
GciValue*       GciMkGraphicString(const char *);
char*             GciGetGraphicString(GciValue *);
GciValue*       GciMkGeneralString(const char *);
char*             GciGetGeneralString(GciValue *);
GciValue*       GciMkGeneralizedTime(char *);
char*             GciGetGeneralizedTime(GciValue *);
GciValue*       GciMkUTCTime(char *);
char*           GciGetUTCTime(GciValue *);


/*-------------------------------------------------------------------------
 *      Constructors and access methods for (special) GciValues.
 */

GciValue*       GciMkENUMERATED(int);
int                 GciGetENUMERATED(GciValue *);
GciValue*       GciMkCHOICE(char *, GciValue *);
GciValue*       GciGetCHOICE(GciValue *);
const char* GciGetCHOICEName(GciValue *);

GciValue*       GciMkObjectDescriptor(const char *);
char*             GciGetObjectDescriptor(GciValue *);
GciValue*       GciMkNULL(void);
int                 GciGetNULL(GciValue *);
GciValue*       GciMkANY(GciValue *);
GciValue*       GciGetANY(GciValue *);
GciValue*       GciMkR_TYPE(int);
int                 GciGetR_TYPE(GciValue *);
GciValue*       GciMkPDU(GciValue *);
GciValue*       GciGetPDU(GciValue *);

GciValue*  GciMkOBJECT_IDENTIFIER(void);
GciValue*  GciAddOBJECT_IDENTIFIERComponent(GciValue*, int comp); 
int        GciOBJECT_IDENTIFIERSize(GciValue*);
int        GciGetOBJECT_IDENTIFIERComponent(GciValue*, int index);
/*-------------------------------------------------------------------------
 *      Constructors and access methods for (composite) GciValues.
 */

GciValue*       GciMkSEQUENCE(int);
GciValue*       GciSetField(GciValue *, int, GciValue *);
GciValue*       GciGetField(GciValue *, int);
int                 GciSeqSize(GciValue *);
GciValue*       GciMkSEQUENCEOF(void);
GciValue*       GciAddElem(GciValue *, GciValue *);
GciValue*       GciGetElem(GciValue *, int);
int                 GciSeqOfSize(GciValue *);
GciValue* GciMkSET(int);
GciValue* GciMkSETOF(void);

/*-------------------------------------------------------------------------
 *      Type, Tag and Class retrieval and manipulation functions.
 */
int               GciGetType(GciValue *);
int               GciGetBaseType(GciValue * );
GciValue*         GciSetType(int, GciValue *);
GciValue*         GciTagType(char, int, Bool, GciValue *);

int               GciGetTag(GciValue *, int);
char              GciGetClass(GciValue *, int);
Bool              GciGetImplicit(GciValue *, int);

const char*     GciGetTypeNameString(int);

int GciGetTypeDescriptor(const char *type_name);

/*-------------------------------------------------------------------------
 *
 */

Bool GciGetOMIT(GciValue *value);

/*-------------------------------------------------------------------------
 *      Retrieval of some static attributes from the TTCN suite, and also
 *      index/descriptor translation.
 */

const char * GciGetTimerName(int TimerD);
int GciGetNoOfTimers(void);

char * GciGetPCOName(int PCOD);
int GciGetNoOfPCOs(void);
int GciGetPCO( int index );

int GciGetPCOType( int pco );

int             GciGetPCOIndex( int desc );

int             GciGetTimer( int index );
int             GciGetTimerIndex( int desc );

/*-------------------------------------------------------------------------
 @func This function returns the number of components in a given configuration.
 @parm GciConf  | conf  | The current GCI configuration object.

 @rdesc The number of components.
 */
unsigned int GciGetNoOfComponents(GciConf conf);

/*-------------------------------------------------------------------------
 @func This function returns the indexed component from a given configuration.
 @parm GciConf  | conf  | The current GCI configuration object.
 @parm int      | index | The component index.
 
 @rdesc A handle to the component object, or NULL on error.
 */
GciComponent* GciGetComponent(GciConf conf, unsigned int index);


/*-------------------------------------------------------------------------
 @func  This function returns the name of the given component.
 @parm  GciComponent*  | comp  | The component handle.
 @rdesc The component name or NULL.
 */
char* GciGetComponentName(GciComponent* comp);

/*-------------------------------------------------------------------------
 @func This function returns the descriptor of the given component.
 @parm  GciComponent*  | comp  | The component handle.
 @rdesc The component descriptor ID or 0.
 */

int GciGetComponentDescriptor(GciComponent* comp);


/*-------------------------------------------------------------------------
 @func This function returns the type of the given component.
 @parm  GciComponent*  | comp  | The component handle.
 @rdesc The component descriptor type (GciMTC or GciPTC) or error.
 */

GciTCType GciGetComponentType(GciComponent* comp);


/*--------------------------------------------------------------------
  @func Returns a list of the available test groups.  
  @rdesc Array of test groups names.
*/
GciTCList* GciGetTestCaseGroupList(void);

/*-----------------------------------------------------------------------
  @func Call to initialize the TTCN runtime behaviour.
  @rdesc GciOk on success.
 */
GciStatus GciInit(void);

/*-----------------------------------------------------------------------
  @func Call to shut down the TTCN runtime behaviour..
  @rdesc GciOk on success.
 */
GciStatus GciExit(void);

/*--------------------------------------------------------------------
  @func Returns a list of the available test cases.  
  @rdesc Array of test case names.
*/
GciTCList* GciGetTestCaseList(void);

/*--------------------------------------------------------------------
  @func Call to start the given test case or group.
  @parm const char* | test_case_or_group_name | Name of the test case or group.
  @rdesc A GCI verdict depicting the result of the command.
 */
GciVerdict GciStartTestCase(const char* test_case_or_group_name);


/*--------------------------------------------------------------------
  @func This function unpacks the argument list and starts the local tree,
        making the assumption that the tree is the behaviour of a test case
        component. Failing to call this function with such arguments, will
        be pretty likely to cause a crash..

  @parm char*     | tree_name | Name of the test step to start.
  @parm GciValue* | args      | The arguments to the test step (?)

  @rdesc The result of the test as a verdict.
 */

GciVerdict GciStartTestComponent(char* tree_name, GciValue** args);
/*-----------------------------------------------------------------------
  @func Call to notify that an object has been received.
  @parm int       | pcoID | The PCO ID.
  @parm GciValue* | value | The received GCI value. 
  @rdesc GciOk on success.
 */
GciStatus GciReceive(int pcoID, GciValue* value);

/*-----------------------------------------------------------------------
  ATTENTION: GciDone is OBSOLETE!!!
*/

GciStatus GciDone(int comp);

/*--------------------------------------------------------------------
  @func  This function evaluates the selection expression for a given Test 
         Case or Test Group and returns: 
  @parm  const char* | test_case_or_group_name | Name of the test case or group.

  @rdesc (int) 1 if the test cases/groups selection expression evaluates to TRUE
  @rdesc (int) 0 if it evaluates to FALSE or if the object is of the wrong type 
                 or not present in the suite.
 */
int GciIsSelected(const char* test_case_or_group_name);

/*--------------------------------------------------------------------
   @func Return the value of a given object in the active context.
   @parm const char* | name | The name of the identifier.
   @rdesc The GCI value or NULL.
 */
GciValue* GciGetValue(const char* name);

/*-----------------------------------------------------------------------
  @func Call to notify that a timer has expired.
  @parm int | timerID | The timer ID.
  @rdesc GciOk on success.
 */
GciStatus GciTimeout(GciTimerID timerID);

/*-------------------------------------------------------------------------
  @func This function returns the names of all CPs used by the given component.
  @parm GciComponent  | component | The component data.
  @rdesc An array of function names, or NULL on failure.
 */
const char* const* GciGetComponentCPs(GciComponent* component);


/*-------------------------------------------------------------------------
  @func This function returns the names of all PCOs used by the given component.
  @parm GciComponent  | component | The component data.
  @rdesc An array of function names, or NULL on failure.
 */
const char* const* GciGetComponentPCOs(GciComponent* component);

GciStatus GciLog (int logId, const char *logString);


extern void (*TaskInit)(void);
extern void (*TaskCreate)(void *(*function)(void *),void *args);
extern void (*TaskDelete)(void);
extern void (*TaskReschedule)(void);
extern void (*TaskCleanup)(void);

#endif
