thorplugin.hpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef THORPLUGIN_HPP
  14. #define THORPLUGIN_HPP
  15. #include "hqlplugins.hpp"
  16. #include "dllserver.hpp"
  17. // call release to unload it.
  18. interface ILoadedDllEntry : extends IInterface
  19. {
  20. virtual void * getEntry(const char * name) const = 0;
  21. virtual HINSTANCE getInstance() const = 0;
  22. virtual bool IsShared() = 0;
  23. virtual const char * queryVersion() const = 0;
  24. virtual const char * queryName() const = 0;
  25. virtual const byte * getResource(unsigned id) const = 0;
  26. virtual bool getResource(size32_t & len, const void * & data, const char * type, unsigned id) const = 0;
  27. };
  28. extern DLLSERVER_API ILoadedDllEntry * createDllEntry(const char *name, bool isGlobal, const IFileIO *dllFile);
  29. extern DLLSERVER_API ILoadedDllEntry * createExeDllEntry(const char *name);
  30. extern DLLSERVER_API bool getEmbeddedWorkUnitXML(ILoadedDllEntry *dll, StringBuffer &xml);
  31. extern DLLSERVER_API bool getEmbeddedManifestXML(ILoadedDllEntry *dll, StringBuffer &xml);
  32. extern DLLSERVER_API bool checkEmbeddedWorkUnitXML(ILoadedDllEntry *dll);
  33. extern DLLSERVER_API bool getResourceXMLFromFile(const char *filename, const char *type, unsigned id, StringBuffer &xml);
  34. extern DLLSERVER_API bool getWorkunitXMLFromFile(const char *filename, StringBuffer &xml);
  35. extern DLLSERVER_API bool getManifestXMLFromFile(const char *filename, StringBuffer &xml);
  36. extern DLLSERVER_API bool decompressResource(size32_t len, const void *data, StringBuffer &result);
  37. extern DLLSERVER_API void compressResource(MemoryBuffer & compressed, size32_t len, const void *data);
  38. extern DLLSERVER_API void appendResource(MemoryBuffer & mb, size32_t len, const void *data, bool compress);
  39. class DLLSERVER_API SimplePluginCtx : implements IPluginContextEx
  40. {
  41. public:
  42. virtual void * ctxMalloc(size_t size);
  43. virtual void * ctxRealloc(void * _ptr, size_t size);
  44. virtual void ctxFree(void * _ptr);
  45. virtual char * ctxStrdup(char * _ptr);
  46. virtual int ctxGetPropInt(const char *propName, int defaultValue) const;
  47. virtual const char *ctxQueryProp(const char *propName) const;
  48. };
  49. class DLLSERVER_API SafePluginMap : public CInterface
  50. {
  51. IPluginContextEx * pluginCtx;
  52. MapStringToMyClass<ILoadedDllEntry> map;
  53. CriticalSection crit;
  54. bool trace;
  55. public:
  56. SafePluginMap(IPluginContextEx * _pluginCtx, bool _trace)
  57. : pluginCtx(_pluginCtx), map(true), trace(_trace)
  58. {
  59. assertex(pluginCtx);
  60. }
  61. ILoadedDllEntry *getPluginDll(const char *id, const char *version, bool checkVersion);
  62. bool addPlugin(const char *path, const char *dllname);
  63. void loadFromList(const char * pluginsList);
  64. void loadFromDirectory(const char * pluginDirectory);
  65. };
  66. #endif // THORPLUGIN_HPP