plugin.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef _PLUGIN_H
  2. #define _PLUGIN_H
  3. #include <map>
  4. #include <string>
  5. #include <vector>
  6. #include <unistd.h>
  7. //#include "tokenizer.h"
  8. using namespace std;
  9. //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. //%% Functions exported by this DLL
  11. //%% Should always be only SetEventFunc and InvokeFunction
  12. //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  13. // g++ requires extern "C" otherwise the names of SetEventFunc and InvokeFunction
  14. // are mangled C++ style. MS Visual Studio doesn't seem to care though.
  15. extern "C"
  16. {
  17. typedef void (*SendPluginEv)( const char* szEvent, void* pContext );
  18. char* SetEventFunc(SendPluginEv funcPtr);
  19. char* InvokeFunction( const char* szCommand, void* pContext );
  20. }
  21. // JNEXT Framework function of the form:
  22. // typedef void (*SendPluginEv)( const char* szEvent );
  23. // used to notify JavaScript of an asynchronous event
  24. extern SendPluginEv SendPluginEvent;
  25. /////////////////////////////////////////////////////////////////////////
  26. // Constants and methods common to all JNEXT extensions types
  27. /////////////////////////////////////////////////////////////////////////
  28. #define szERROR "Error "
  29. #define szOK "Ok "
  30. #define szDISPOSE "Dispose"
  31. #define szINVOKE "InvokeMethod"
  32. #define szCREATE "CreateObj"
  33. /////////////////////////////////////////////////////////////////////////
  34. // Utility functions
  35. /////////////////////////////////////////////////////////////////////////
  36. string& g_trim( string& str );
  37. void g_tokenize(const string& str,const string& delimiters, vector<string>& tokens);
  38. char* g_str2static( const string& strRetVal );
  39. void g_sleep( unsigned int mseconds );
  40. bool g_unregisterObject( const string& strObjId, void* pContext );
  41. /////////////////////////////////////////////////////////////////////////
  42. // Abstract extension object
  43. /////////////////////////////////////////////////////////////////////////
  44. class JSExt
  45. {
  46. public:
  47. virtual ~JSExt() {};
  48. virtual string InvokeMethod( const string& strCommand ) = 0;
  49. virtual bool CanDelete( void ) = 0;
  50. virtual void TryDelete( void ) {}
  51. public:
  52. void* m_pContext;
  53. };
  54. /////////////////////////////////////////////////////////////////////////
  55. // Callback functions to be implemented by the plugin implementation
  56. /////////////////////////////////////////////////////////////////////////
  57. extern char* onGetObjList( void );
  58. extern JSExt* onCreateObject( const string& strClassName, const string& strObjId );
  59. #endif