1 #ifndef _WDL_SHM_MSGREPLY_
2 #define _WDL_SHM_MSGREPLY_
5 #include "shm_connection.h"
12 4 byte unique message ID (0 for no reply needed/wanted)
14 4 byte message length (following)
18 call specific return data
19 type: all others user defined
22 // type is user defined, however type=0 is reserved for reply
23 class SHM_MsgReplyConnection
34 WaitingMessage
*_next
;
39 WDL_HeapBuf m_msgdata
;
43 SHM_MsgReplyConnection(int bufsize
, int maxqueuesize
, bool dir
, const char *uniquestr
=NULL
, int timeout_sec
=0, int extra_flags
=0);
44 ~SHM_MsgReplyConnection();
46 // be sure to set these, and have OnRecv() Reply() to any nonzero msgID !
48 WaitingMessage
*(*OnRecv
)(SHM_MsgReplyConnection
*con
, WaitingMessage
*msg
);
49 bool (*IdleProc
)(SHM_MsgReplyConnection
*con
); // return TRUE to abort (this will set the m_has_had_error to true / kill the connection)
50 // can return NULL To temporarily buffer msg, can return a chain of msgs too to return them to the spare list
52 // run as you wish, Send() will also run internally when waiting for reply
53 // note: the checkForReplyID etc are for INTERNAL USE ONLY :)
55 bool Run(bool runFull
=true);
57 // returns <0 if no reply, otherwise lenght of replybuf used
58 // no retbuf = no wait for reply
59 int Send(int type
, const void *msg
, int msglen
,
60 void *replybuf
, int maxretbuflen
, const int *forceMsgID
=NULL
,
61 const void *secondchunk
=NULL
, int secondchunklen
=0, // allow sending two blocks as one message (for speed in certain instances)
62 WDL_HeapBuf
*hbreplyout
=NULL
); // if hbreplyout is set it will get the full message (replybuf can be NULL then)
63 void Reply(int msgID
, const void *msg
, int msglen
);
64 void Wait(HANDLE extraEvt
=NULL
);
66 const char *GetUniqueString() { return m_uniq
; }
68 void ReturnSpares(WaitingMessage
*msglist
);
71 bool RunInternal(int checkForReplyID
=0, WaitingMessage
**replyPtr
=0); // nonzero on error
75 WDL_SHM_Connection
*m_shm
;
78 WaitingMessage
*m_waiting_replies
;
79 WaitingMessage
*m_spares
;