#ifndef TRI_TCI_CHANNEL
#define TRI_TCI_CHANNEL

#include "TciTM/TciTM.h"
#include "Shared/CommonTri.h"


#define SA_ENABLED 1
#define PA_ENABLED 2
#define TM_ENABLED 4

typedef void (*FTciTMTestCaseStarted)(TciTestCaseIdType testCaseId, TciParameterListType parameterList, double timer);
typedef void (*FTciTMTestCaseTerminated)(VerdictValue verdict, TciParameterListType parameterlist);
typedef void (*FTciTMControlTerminated)(void);
typedef Value (*FTciTMGetModulePar)(TciModuleParameterIdType parameterId);
typedef void (*FTciTMLog)(String message);
typedef void (*FTciTMError)(String message);


// Initiation
int openDefaultTriTciChannel (int nInterfaceFlags, wchar_t * wszSutName);
int openDefaultTriTciChannelTimeout(int nInterfaceFlags, wchar_t * wszSutName, unsigned int nTimeout);
int openTriTciChannel (char * pszAddr, int nPort, int nInterfaceFlags, 
	wchar_t * wszSutName);
int openTriTciChannelTimeout(char * pszAddr, int nPort, int nInterfaceFlags, 
	wchar_t * wszSutName, unsigned int nTimeout);


// Clean-up
void closeTriChannel (void);

// Methods called by the SUT
void triEnqueueMessage (const TriPortId * tsiPortId,
	const TriAddress * sutAddress, const TriComponentId * componentId,
	const TriMessage * receivedMessage);

void triEnqueueCall (const TriPortId * tsiPortId,
	const TriAddress * sutAddress, const TriComponentId * componentId,
	const TriSignatureId * signatureId, const TriParameterList * parameterList);

void triEnqueueReply (const TriPortId * tsiPortId,
	const TriAddress * sutAddress, const TriComponentId * componentId,
	const TriSignatureId * signatureId, const TriParameterList * parameterList,
	const TriParameter * returnValue);

void triEnqueueException (const TriPortId * tsiPortId,
	const TriAddress * sutAddress, const TriComponentId * componentId,
	const TriSignatureId * signatureId, const TriException * exception);

void triTimeout (const TriTimerId * timerId);

//  Callbacks
// TciTM pCallbacks
void setTciTMTestCaseStartedCallback(FTciTMTestCaseStarted pCallback);
void setTciTMTestCaseTerminatedCallback(FTciTMTestCaseTerminated pCallback);
void setTciTMGetModuleParCallback(FTciTMGetModulePar pCallback);
void setTciTMControlTerminatedCallback(FTciTMControlTerminated pCallback);
void setTciTMLogCallback(FTciTMLog pCallback);
void setTciTMErrorCallback(FTciTMError pCallback);

// Copying functions
// Note: The following functions are used for full-scale copying of the source 
// structures. If the copied structure contains pointers, new memory is allocated
// on the heap. The only expception are external data in the aux field - only the
// pointer is copied in this case. The allocated memory should be properly disposed
// when no longer needed. There are dedicated disposing functions defined in this
// header file.

// Disposing funcions
// Note: These functions are complement of the copying functions defined in this header
// file. They can work well in other cases too provided that all pointers within the 
// disposed content point to dynamically allocated memory. The functions don't dispose
// external data in aux fields.
// The disposing functions don't dispose memory at the address passed to them. Only the 
// dynamic content inside the passed structure is disposed. This allows to clean up 
// content of structures allocated on the stack.

void clearObjectidValue(TciObjidValue * pObjidVal);
void clearCString(TciCharStringValue * pCString);
void clearUCString(TciUCStringValue *pUCString);
void clearTciParameterType(TciParameterType *parType);
void clearTciParamList(TciParameterListType * parList);
void clearTestCaseIdList(TciTestCaseIdListType *pTcList);
void clearStringArray(String ** paStr);
void clearTciParameterTypeType(TciParameterTypeType *pParTypeType);
void clearTciParameterTypeList(TciParameterTypeListType *pParTypeList);
void clearTciModuleParameterList(TciModuleParameterListType * pModParList);
void disposeTciType(Type inst);
void disposeTciValue(Value inst);

#endif
