#ifndef TRI_COMMON
#define TRI_COMMON

#include <stdio.h>
#include "TriCommunicationSA.h"
#include "TriPlatformPA.h"
#include "ChannelEventHandler.h"


//  Callbacks
// SA  pCallbacks
void setTriSAResetCallback (FTriSAReset pCallback);
void setTriExecuteTestCaseCallback (FTriExecuteTestCase pCallback);
void setTriMapCallback (FTriMap pCallback);
void setTriUnmapCallback (FTriUnmap pCallback);
void setTriEndTestCaseCallback (FTriEndTestCase pCallback);
void setTriSendCallback (FTriSend pCallback);
void setTriSendBCCallback (FTriSendBC pCallback);
void setTriSendMCCallback (FTriSendMC pCallback);
void setTriCallCallback (FTriCall pCallback);
void setTriCallBCCallback (FTriCallBC pCallback);
void setTriCallMCCallback (FTriCallMC pCallback);
void setTriReplyCallback (FTriReply pCallback);
void setTriReplyBCCallback (FTriReplyBC pCallback);
void setTriReplyMCCallback (FTriReplyMC pCallback);
void setTriRaiseCallback (FTriRaise pCallback);
void setTriRaiseBCCallback (FTriRaiseBC pCallback);
void setTriRaiseMCCallback (FTriRaiseMC pCallback);
void setTriSUTActionInformalCallback (FTriSUTActionInformal pCallback);

// PA  pCallbacks
void setTriPAResetCallback (FTriPAReset pCallback);
void setTriStartTimerCallback (FTriStartTimer pCallback);
void setTriStopTimerCallback (FTriStopTimer pCallback);
void setTriReadTimerCallback (FTriReadTimer pCallback);
void setTriTimerRunningCallback (FTriTimerRunning pCallback);
void setTriExternalFunctionCallback (FTriExternalFunction pCallback);

// Service  pCallbacks
void setOnErrorCallback (FOnError pCallback);
void setOnConnectionEstablishedCallback (FOnConnectionEstablished pCallback);
void setOnConnectionClosedCallback (FOnConnectionClosed 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.

void copyBinaryString(BinaryString * pTargetString, const BinaryString * pSrcString);
void copyQualifiedName(QualifiedName * pTargetName, const QualifiedName * pSrcName);
void copyTriAddress(TriAddress * pTargetAddress, const TriAddress * pSrcAddress);
void copyTriAddressList(TriAddressList * pTargetAddressList, const TriAddressList * pSrcAddressList);
void copyTriComponentId(TriComponentId * pTargetComponentId, const TriComponentId * pSrcComponentId);
void copyTriComponentIdList(TriComponentIdList * pTargetList, const TriComponentIdList * pSrcList);
void copyTriException(TriException * pTargetException, const TriException * pSrcException);
void copyTriFunctionId(TriFunctionId * pTargetFunctionId, const TriFunctionId * pSrcFunctionId);
void copyTriMessage(TriMessage * pTargetMessage, const TriMessage * pSrcMessage);
void copyTriParameter(TriParameter * pTargetParameter, const TriParameter * pSrcParameter);
void copyTriParameterList(TriParameterList * pTargetList, const TriParameterList * pSrcList);
void copyTriPortId(TriPortId * pTargetPortId, const TriPortId * pSrcPortId);
void copyTriPortIdList(TriPortIdList * pTargetList, const TriPortIdList * pSrcList);
void copyTriSignatureId(TriSignatureId * pTargetSignatureId, const TriSignatureId * pSrcSignatureId);
void copyTriTestCaseId(TriTestCaseId * pTargetTestCaseId, const TriTestCaseId * pSrcTestCaseId);
void copyTriTimerId(TriTimerId * pTargetTimerId, const TriTimerId * pSrcTimerId);

// 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 clearBinaryString(BinaryString * pString);
void clearQualifiedName(QualifiedName * pName);
void clearTriAddress(TriAddress * pAddress);
void clearTriAddressList(TriAddressList * pAddressList);
void clearTriComponentId(TriComponentId * pComponentId);
void clearTriComponentIdList(TriComponentIdList * pList);
void clearTriException(TriException * pException);
void clearTriFunctionId(TriFunctionId * pFunctionId);
void clearTriMessage(TriMessage * pMessage);
void clearTriParameter(TriParameter * pParameter);
void clearTriParameterList(TriParameterList * pList);
void clearTriPortId(TriPortId * pPortId);
void clearTriPortIdList(TriPortIdList * pList);
void clearTriSignatureId(TriSignatureId * pSignatureId);
void clearTriTestCaseId(TriTestCaseId * pTestCaseId);
void clearTriTimerId(TriTimerId * pTimerId);

#endif
