jhi_proxy.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #include <stdint.h>
  32. #include <dlfcn.h>
  33. #include "oal/oal.h"
  34. #include "jhi.h"
  35. #include "jhi_proxy.h"
  36. const static char JHI_PATH[] = "libjhi.so";
  37. SharedLibProxy::SharedLibProxy():handle(NULL), library_path(JHI_PATH)
  38. {
  39. }
  40. SharedLibProxy::~SharedLibProxy(void)
  41. {
  42. unload();
  43. }
  44. void SharedLibProxy::load(void)
  45. {
  46. handle = dlopen(library_path, RTLD_LAZY);
  47. if (!isLoaded())
  48. {
  49. const char* err = dlerror();
  50. AESM_DBG_ERROR("Load JHI library failed: %s", err); (void)(err);
  51. }
  52. }
  53. void SharedLibProxy::unload()
  54. {
  55. if (isLoaded())
  56. {
  57. dlclose(handle);
  58. handle = 0;
  59. }
  60. }
  61. bool SharedLibProxy::findSymbol(const char* name, void** function)
  62. {
  63. if (!isLoaded())
  64. {
  65. load();
  66. }
  67. if (isLoaded())
  68. {
  69. *function = dlsym(handle, name);
  70. return *function != NULL;
  71. }
  72. return false;
  73. }
  74. JHI_EXPORT
  75. JHI_Initialize(
  76. OUT JHI_HANDLE* ppHandle,
  77. IN PVOID context,
  78. IN UINT32 flags
  79. )
  80. {
  81. JHI_RET (*p_JHI_Initialize)(
  82. OUT JHI_HANDLE* ppHandle,
  83. IN PVOID context,
  84. IN UINT32 flags) = NULL;
  85. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_Initialize))
  86. {
  87. return p_JHI_Initialize(ppHandle, context, flags);
  88. }
  89. return JHI_SERVICE_UNAVAILABLE;
  90. }
  91. JHI_EXPORT JHI_Deinit(IN JHI_HANDLE handle)
  92. {
  93. JHI_RET(*p_JHI_Deinit)(IN JHI_HANDLE handle) = NULL;
  94. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_Deinit))
  95. {
  96. return p_JHI_Deinit(handle);
  97. }
  98. return JHI_SERVICE_UNAVAILABLE;
  99. }
  100. JHI_EXPORT
  101. JHI_SendAndRecv2(
  102. IN JHI_HANDLE handle,
  103. IN JHI_SESSION_HANDLE SessionHandle,
  104. IN INT32 nCommandId,
  105. INOUT JVM_COMM_BUFFER* pComm,
  106. OUT INT32* responseCode)
  107. {
  108. JHI_RET(*p_JHI_SendAndRecv2)(
  109. IN JHI_HANDLE handle,
  110. IN JHI_SESSION_HANDLE SessionHandle,
  111. IN INT32 nCommandId,
  112. INOUT JVM_COMM_BUFFER* pComm,
  113. OUT INT32* responseCode) = NULL;
  114. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_SendAndRecv2))
  115. {
  116. return p_JHI_SendAndRecv2(handle, SessionHandle, nCommandId, pComm, responseCode);
  117. }
  118. return JHI_SERVICE_UNAVAILABLE;
  119. }
  120. JHI_EXPORT
  121. JHI_Install2(
  122. IN const JHI_HANDLE handle,
  123. IN const char* AppId,
  124. IN const FILECHAR* srcFile
  125. )
  126. {
  127. JHI_RET(*p_JHI_Install2)(
  128. IN const JHI_HANDLE handle,
  129. IN const char* AppId,
  130. IN const FILECHAR* srcFile) = NULL;
  131. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_Install2))
  132. {
  133. return p_JHI_Install2(handle, AppId, srcFile);
  134. }
  135. return JHI_SERVICE_UNAVAILABLE;
  136. }
  137. JHI_EXPORT
  138. JHI_Uninstall(
  139. IN JHI_HANDLE handle,
  140. IN const char* AppId
  141. )
  142. {
  143. JHI_RET(*p_JHI_Uninstall)(
  144. IN JHI_HANDLE handle,
  145. IN const char* AppId) = NULL;
  146. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_Uninstall))
  147. {
  148. return p_JHI_Uninstall(handle, AppId);
  149. }
  150. return JHI_SERVICE_UNAVAILABLE;
  151. }
  152. JHI_EXPORT
  153. JHI_GetAppletProperty(
  154. IN JHI_HANDLE handle,
  155. IN const char* AppId,
  156. INOUT JVM_COMM_BUFFER* pComm
  157. )
  158. {
  159. JHI_RET(*p_JHI_GetAppletProperty)(
  160. IN JHI_HANDLE handle,
  161. IN const char* AppId,
  162. INOUT JVM_COMM_BUFFER* pComm) = NULL;
  163. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_GetAppletProperty))
  164. {
  165. return p_JHI_GetAppletProperty(handle, AppId, pComm);
  166. }
  167. return JHI_SERVICE_UNAVAILABLE;
  168. }
  169. JHI_EXPORT
  170. JHI_CreateSession(
  171. IN const JHI_HANDLE handle,
  172. IN const char* AppId,
  173. IN UINT32 flags,
  174. IN DATA_BUFFER* initBuffer,
  175. OUT JHI_SESSION_HANDLE* pSessionHandle
  176. )
  177. {
  178. JHI_RET(*p_JHI_CreateSession)(
  179. IN const JHI_HANDLE handle,
  180. IN const char* AppId,
  181. IN UINT32 flags,
  182. IN DATA_BUFFER* initBuffer,
  183. OUT JHI_SESSION_HANDLE* pSessionHandle) = NULL;
  184. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_CreateSession))
  185. {
  186. return p_JHI_CreateSession(handle, AppId, flags, initBuffer, pSessionHandle);
  187. }
  188. return JHI_SERVICE_UNAVAILABLE;
  189. }
  190. JHI_EXPORT
  191. JHI_GetSessionsCount(
  192. IN const JHI_HANDLE handle,
  193. IN const char* AppId,
  194. OUT UINT32* SessionsCount
  195. )
  196. {
  197. JHI_RET(*p_JHI_GetSessionsCount)(
  198. IN const JHI_HANDLE handle,
  199. IN const char* AppId,
  200. OUT UINT32* SessionsCount) = NULL;
  201. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_GetSessionsCount))
  202. {
  203. return p_JHI_GetSessionsCount(handle, AppId, SessionsCount);
  204. }
  205. return JHI_SERVICE_UNAVAILABLE;
  206. }
  207. JHI_EXPORT
  208. JHI_CloseSession(
  209. IN const JHI_HANDLE handle,
  210. IN JHI_SESSION_HANDLE* pSessionHandle
  211. )
  212. {
  213. JHI_RET(*p_JHI_CloseSession)(
  214. IN const JHI_HANDLE handle,
  215. IN JHI_SESSION_HANDLE* pSessionHandle) = NULL;
  216. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_CloseSession))
  217. {
  218. return p_JHI_CloseSession(handle, pSessionHandle);
  219. }
  220. return JHI_SERVICE_UNAVAILABLE;
  221. }
  222. JHI_EXPORT
  223. JHI_ForceCloseSession(
  224. IN const JHI_HANDLE handle,
  225. IN JHI_SESSION_HANDLE* pSessionHandle
  226. )
  227. {
  228. JHI_RET(*p_JHI_ForceCloseSession)(
  229. IN const JHI_HANDLE handle,
  230. IN JHI_SESSION_HANDLE* pSessionHandle) = NULL;
  231. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_ForceCloseSession))
  232. {
  233. return p_JHI_ForceCloseSession(handle, pSessionHandle);
  234. }
  235. return JHI_SERVICE_UNAVAILABLE;
  236. }
  237. JHI_EXPORT
  238. JHI_GetSessionInfo(
  239. IN const JHI_HANDLE handle,
  240. IN JHI_SESSION_HANDLE SessionHandle,
  241. OUT JHI_SESSION_INFO* SessionInfo
  242. )
  243. {
  244. JHI_RET(*p_JHI_GetSessionInfo)(
  245. IN const JHI_HANDLE handle,
  246. IN JHI_SESSION_HANDLE SessionHandle,
  247. OUT JHI_SESSION_INFO* SessionInfo) = NULL;
  248. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_GetSessionInfo))
  249. {
  250. return p_JHI_GetSessionInfo(handle, SessionHandle, SessionInfo);
  251. }
  252. return JHI_SERVICE_UNAVAILABLE;
  253. }
  254. JHI_EXPORT
  255. JHI_RegisterEvents(
  256. IN const JHI_HANDLE handle,
  257. IN JHI_SESSION_HANDLE SessionHandle,
  258. IN JHI_EventFunc pEventFunction)
  259. {
  260. JHI_RET(*p_JHI_RegisterEvents)(
  261. IN const JHI_HANDLE handle,
  262. IN JHI_SESSION_HANDLE SessionHandle,
  263. IN JHI_EventFunc pEventFunction) = NULL;
  264. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_RegisterEvents))
  265. {
  266. return p_JHI_RegisterEvents(handle, SessionHandle, pEventFunction);
  267. }
  268. return JHI_SERVICE_UNAVAILABLE;
  269. }
  270. JHI_EXPORT
  271. JHI_UnRegisterEvents(
  272. IN const JHI_HANDLE handle,
  273. IN JHI_SESSION_HANDLE SessionHandle)
  274. {
  275. JHI_RET(*p_JHI_UnRegisterEvents)(
  276. IN const JHI_HANDLE handle,
  277. IN JHI_SESSION_HANDLE SessionHandle) = NULL;
  278. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_UnRegisterEvents))
  279. {
  280. return p_JHI_UnRegisterEvents(handle, SessionHandle);
  281. }
  282. return JHI_SERVICE_UNAVAILABLE;
  283. }
  284. JHI_EXPORT
  285. JHI_GetVersionInfo(
  286. IN const JHI_HANDLE handle,
  287. OUT JHI_VERSION_INFO* pVersionInfo)
  288. {
  289. JHI_RET(*p_JHI_GetVersionInfo)(
  290. IN const JHI_HANDLE handle,
  291. OUT JHI_VERSION_INFO* pVersionInfo) = NULL;
  292. if (SharedLibProxy::instance().findSymbol(__FUNCTION__, (void**)&p_JHI_GetVersionInfo))
  293. {
  294. return p_JHI_GetVersionInfo(handle, pVersionInfo);
  295. }
  296. return JHI_SERVICE_UNAVAILABLE;
  297. }