1 /*----------------------------------------------------------------------------
  2 Name:      XmlBlasterUnmanagedCE.h
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Comment:   Provides simplified access methods to xmlBlaster client C library
  6            to be usable from Windows CE .NET Compact Framework 1.0 (CF)
  7            as a unmanaged DLL (called by C#)
  8 Note:      A managed C++ wrapper is not supported in CF
  9 Author:    "Marcel Ruff" <xmlBlaster@marcelruff.info>
 10 Date:      2006-12-07
 11 See:       http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.html
 12 See:       P/Invoke for CE: http://msdn2.microsoft.com/en-us/library/Aa446536.aspx
 13 -----------------------------------------------------------------------------*/
 14 #ifndef _XmlBlasterUnmanagedCE_H

 15 #define _XmlBlasterUnmanagedCE_H

 16 
 17 /*
 18  To access this .dll as unmanaged code from C#, the C-API must be simplified,
 19  for example fixed size arrays like "char errorCode[256]" are tricky.
 20  We implement here a simple wrapper around XmlBlasterAccessUnparsed.h
 21  This code is called from xmlBlaster/src/csharp/PInvokeCE.cs
 22  See: http://www.xmlblaster.org/xmlBlaster/doc/requirements/client.csharp.html
 23  
 24  We should avoid C++ code as the name mangling makes difficulties,
 25  so we force C code here.
 26  See: http://www.opennetcf.org/Forums/topic.asp?TOPIC_ID=255
 27  */
 28 
 29 #include <XmlBlasterAccessUnparsed.h>

 30 
 31 #ifdef __cplusplus

 32 extern "C" {
 33 #endif

 34 
 35 /**
 36  * Usage without fixed array size, to avoid 'unsafe' code in C#
 37  */
 38 typedef struct XmlBlasterUnmanagedCEException {
 39    uint32_t remote;
 40    char *errorCode;
 41    char *message;
 42 } XmlBlasterUnmanagedCEException;
 43 
 44 /*
 45          public IntPtr key;
 46          public int contentLen;
 47          public IntPtr content;
 48          public IntPtr qos;
 49          public IntPtr responseQos;
 50 typedef struct MsgUnitUnmanagedCEget {
 51    char *key;
 52    uint32_t contentLen;
 53    char *content;
 54    char *qos;
 55    char *responseQos;
 56 } MsgUnitUnmanagedCEget;
 57 */
 58 /* this only works if the size_t has 4 bytes (from MsgUnit) */
 59 typedef MsgUnit MsgUnitUnmanagedCEpublish;
 60 typedef MsgUnit MsgUnitUnmanagedCEget;
 61 
 62 
 63 /**
 64  * Helper struct to pass an array of strings back to C#
 65  */
 66 typedef struct XmlBlasterUnmanagedCEStringArr {
 67    const char *str; 
 68 } XmlBlasterUnmanagedCEStringArr;
 69 
 70 
 71 Dll_Export extern char *xmlBlasterUnmanagedCEMalloc(int32_t size);
 72 Dll_Export extern void xmlBlasterUnmanagedCEFree(char *p);
 73 Dll_Export extern void xmlBlasterUnmanagedCEFreePP(char **pp);
 74 Dll_Export extern void xmlBlasterUnmanagedCEExceptionFree(XmlBlasterUnmanagedCEException *exception);
 75 
 76 /*
 77 #define CALLBACK    __stdcall
 78 #define WINAPI      __stdcall
 79 #define WINAPIV     __cdecl
 80 */
 81 #if defined(_WINDOWS)

 82 #  define XB_CALLBACK_DECL __cdecl

 83 # else/* XMLBLASTER_MONO */

 84 #  define XB_CALLBACK_DECL

 85 #endif

 86 typedef void (XB_CALLBACK_DECL *XmlBlasterUnmanagedCELoggerFp)(int32_t level, const char *location, const char *msg);
 87 typedef void (XB_CALLBACK_DECL *XmlBlasterUnmanagedCEUpdateFp)(const char *cbSessionId, MsgUnit *msgUnit, int32_t isOneway, XmlBlasterUnmanagedCEException *xmlBlasterException);
 88 typedef void (XB_CALLBACK_DECL *XmlBlasterUnmanagedCECallbackProgressListenerFp)(int32_t currBytesRead, int32_t nbytes);
 89 /*typedef int32_t (__cdecl *FPTR)( int32_t i );*/
 90 typedef int32_t (XB_CALLBACK_DECL *FPTR)( int32_t i );
 91 
 92 Dll_Export extern const char *getXmlBlasterEmei();
 93 
 94 Dll_Export extern void xmlBlasterUnmanagedCERegisterLogger(struct XmlBlasterAccessUnparsed *xa, XmlBlasterUnmanagedCELoggerFp logger);
 95 Dll_Export extern void callbackProgressListener_stdout(void *userP, const size_t currBytesRead, const size_t nbytes);
 96 Dll_Export extern void xmlBlasterUnmanagedCERegisterProgressListener(struct XmlBlasterAccessUnparsed *xa, XmlBlasterUnmanagedCECallbackProgressListenerFp progressListener);
 97 
 98 Dll_Export extern XmlBlasterAccessUnparsed *getXmlBlasterAccessUnparsedUnmanagedCE(int argc, char** argv);
 99 Dll_Export extern void freeXmlBlasterAccessUnparsedUnmanagedCE(XmlBlasterAccessUnparsed *xmlBlasterAccess);
100 
101 Dll_Export extern char *xmlBlasterUnmanagedCEConnect(struct XmlBlasterAccessUnparsed *xa, char *qos, XmlBlasterUnmanagedCEUpdateFp update, XmlBlasterUnmanagedCEException *exception);
102 Dll_Export extern  bool  xmlBlasterUnmanagedCEInitialize(struct XmlBlasterAccessUnparsed *xa, XmlBlasterUnmanagedCEUpdateFp update, XmlBlasterUnmanagedCEException *exception);
103 Dll_Export extern  bool  xmlBlasterUnmanagedCEDisconnect(struct XmlBlasterAccessUnparsed *xa, char *qos, XmlBlasterUnmanagedCEException *exception);
104 Dll_Export extern  char *xmlBlasterUnmanagedCEPublish(struct XmlBlasterAccessUnparsed *xa, MsgUnitUnmanagedCEpublish *msgUnit, XmlBlasterUnmanagedCEException *exception);
105 Dll_Export extern  QosArr *xmlBlasterUnmanagedCEPublishArr(struct XmlBlasterAccessUnparsed *xa, MsgUnitArr *msgUnitArr, XmlBlasterUnmanagedCEException *exception);
106 Dll_Export extern void xmlBlasterUnmanagedCEPublishOneway(struct XmlBlasterAccessUnparsed *xa, void *msgUnitArr, int length, XmlBlasterUnmanagedCEException *exception);
107 Dll_Export extern  char *xmlBlasterUnmanagedCESubscribe(struct XmlBlasterAccessUnparsed *xa, char *key, char *qos, XmlBlasterUnmanagedCEException *exception);
108 Dll_Export extern void xmlBlasterUnmanagedCEUnSubscribe(struct XmlBlasterAccessUnparsed *xa, char * key, char * qos, XmlBlasterUnmanagedCEException *exception, uint32_t* pSize, XmlBlasterUnmanagedCEStringArr** ppStruct);
109 Dll_Export extern void xmlBlasterUnmanagedCEErase(struct XmlBlasterAccessUnparsed *xa, char * key, char * qos, XmlBlasterUnmanagedCEException *exception, uint32_t* pSize, XmlBlasterUnmanagedCEStringArr** ppStruct);
110 Dll_Export extern  void xmlBlasterUnmanagedCEGet(struct XmlBlasterAccessUnparsed *xa, char * key, char *qos, XmlBlasterUnmanagedCEException *exception, uint32_t* pSize, MsgUnitUnmanagedCEget** ppStruct);
111 Dll_Export extern  char *xmlBlasterUnmanagedCEPing(struct XmlBlasterAccessUnparsed *xa, char * qos, XmlBlasterUnmanagedCEException *exception);
112 Dll_Export extern  bool xmlBlasterUnmanagedCEIsConnected(struct XmlBlasterAccessUnparsed *xa);
113 Dll_Export extern const char *xmlBlasterUnmanagedCEVersion();
114 Dll_Export extern const char *xmlBlasterUnmanagedCEUsage();
115 
116 #ifdef __cplusplus

117 }      /* extern "C" */
118 #endif

119 #endif /* _XmlBlasterUnmanagedCE_H */

120 


syntax highlighted by Code2HTML, v. 0.9.1