/nci/jni/RouteDataSet.h

https://gitlab.com/Codeaurora/platform_vendor_nxp_opensource_packages_apps_Nfc · C Header · 326 lines · 71 code · 48 blank · 207 comment · 0 complexity · 3c2fc0d5387ba8fbff0b4b334513be90 MD5 · raw file

  1. /*
  2. * Copyright (C) 2012 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. *
  18. * The original Work has been changed by NXP Semiconductors.
  19. *
  20. * Copyright (C) 2015 NXP Semiconductors
  21. *
  22. * Licensed under the Apache License, Version 2.0 (the "License");
  23. * you may not use this file except in compliance with the License.
  24. * You may obtain a copy of the License at
  25. *
  26. * http://www.apache.org/licenses/LICENSE-2.0
  27. *
  28. * Unless required by applicable law or agreed to in writing, software
  29. * distributed under the License is distributed on an "AS IS" BASIS,
  30. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  31. * See the License for the specific language governing permissions and
  32. * limitations under the License.
  33. *
  34. ******************************************************************************/
  35. /*
  36. * Import and export general routing data using a XML file.
  37. */
  38. #pragma once
  39. #include "NfcJniUtil.h"
  40. #include "nfa_api.h"
  41. //#include <libxml/parser.h>
  42. #include <vector>
  43. #include <string>
  44. /*****************************************************************************
  45. **
  46. ** Name: RouteData
  47. **
  48. ** Description: Base class for every kind of route data.
  49. **
  50. *****************************************************************************/
  51. class RouteData
  52. {
  53. public:
  54. enum RouteType {ProtocolRoute, TechnologyRoute};
  55. RouteType mRouteType;
  56. protected:
  57. RouteData (RouteType routeType) : mRouteType (routeType)
  58. {}
  59. };
  60. /*****************************************************************************
  61. **
  62. ** Name: RouteDataForProtocol
  63. **
  64. ** Description: Data for protocol routes.
  65. **
  66. *****************************************************************************/
  67. class RouteDataForProtocol : public RouteData
  68. {
  69. public:
  70. int mNfaEeHandle; //for example 0x4f3, 0x4f4
  71. bool mSwitchOn;
  72. bool mSwitchOff;
  73. bool mBatteryOff;
  74. tNFA_PROTOCOL_MASK mProtocol;
  75. RouteDataForProtocol () : RouteData (ProtocolRoute), mNfaEeHandle (NFA_HANDLE_INVALID),
  76. mSwitchOn (false), mSwitchOff (false), mBatteryOff (false),
  77. mProtocol (0)
  78. {}
  79. };
  80. /*****************************************************************************
  81. **
  82. ** Name: RouteDataForTechnology
  83. **
  84. ** Description: Data for technology routes.
  85. **
  86. *****************************************************************************/
  87. class RouteDataForTechnology : public RouteData
  88. {
  89. public:
  90. int mNfaEeHandle; //for example 0x4f3, 0x4f4
  91. bool mSwitchOn;
  92. bool mSwitchOff;
  93. bool mBatteryOff;
  94. tNFA_TECHNOLOGY_MASK mTechnology;
  95. RouteDataForTechnology () : RouteData (TechnologyRoute), mNfaEeHandle (NFA_HANDLE_INVALID),
  96. mSwitchOn (false), mSwitchOff (false), mBatteryOff (false),
  97. mTechnology (0)
  98. {}
  99. };
  100. /*****************************************************************************/
  101. /*****************************************************************************/
  102. /*****************************************************************************
  103. **
  104. ** Name: AidBuffer
  105. **
  106. ** Description: Buffer to store AID after converting a string of hex
  107. ** values to bytes.
  108. **
  109. *****************************************************************************/
  110. class AidBuffer
  111. {
  112. public:
  113. /*******************************************************************************
  114. **
  115. ** Function: AidBuffer
  116. **
  117. ** Description: Parse a string of hex numbers. Store result in an array of
  118. ** bytes.
  119. ** aid: string of hex numbers.
  120. **
  121. ** Returns: None.
  122. **
  123. *******************************************************************************/
  124. AidBuffer (std::string& aid);
  125. /*******************************************************************************
  126. **
  127. ** Function: ~AidBuffer
  128. **
  129. ** Description: Release all resources.
  130. **
  131. ** Returns: None.
  132. **
  133. *******************************************************************************/
  134. ~AidBuffer ();
  135. UINT8* buffer () {return mBuffer;};
  136. int length () {return mBufferLen;};
  137. private:
  138. UINT8* mBuffer;
  139. UINT32 mBufferLen;
  140. };
  141. /*****************************************************************************/
  142. /*****************************************************************************/
  143. /*****************************************************************************
  144. **
  145. ** Name: RouteDataSet
  146. **
  147. ** Description: Import and export general routing data using a XML file.
  148. ** See /data/bcm/param/route.xml
  149. **
  150. *****************************************************************************/
  151. class RouteDataSet
  152. {
  153. public:
  154. typedef std::vector<RouteData*> Database;
  155. enum DatabaseSelection {DefaultRouteDatabase, SecElemRouteDatabase};
  156. /*******************************************************************************
  157. **
  158. ** Function: ~RouteDataSet
  159. **
  160. ** Description: Release all resources.
  161. **
  162. ** Returns: None.
  163. **
  164. *******************************************************************************/
  165. ~RouteDataSet ();
  166. /*******************************************************************************
  167. **
  168. ** Function: initialize
  169. **
  170. ** Description: Initialize resources.
  171. **
  172. ** Returns: True if ok.
  173. **
  174. *******************************************************************************/
  175. bool initialize ();
  176. /*******************************************************************************
  177. **
  178. ** Function: import
  179. **
  180. ** Description: Import data from an XML file. Fill the database.
  181. **
  182. ** Returns: True if ok.
  183. **
  184. *******************************************************************************/
  185. bool import ();
  186. /*******************************************************************************
  187. **
  188. ** Function: getDatabase
  189. **
  190. ** Description: Obtain a database of routing data.
  191. ** selection: which database.
  192. **
  193. ** Returns: Pointer to database.
  194. **
  195. *******************************************************************************/
  196. Database* getDatabase (DatabaseSelection selection);
  197. /*******************************************************************************
  198. **
  199. ** Function: saveToFile
  200. **
  201. ** Description: Save XML data from a string into a file.
  202. ** routesXml: XML that represents routes.
  203. **
  204. ** Returns: True if ok.
  205. **
  206. *******************************************************************************/
  207. static bool saveToFile (const char* routesXml);
  208. /*******************************************************************************
  209. **
  210. ** Function: loadFromFile
  211. **
  212. ** Description: Load XML data from file into a string.
  213. ** routesXml: string to receive XML data.
  214. **
  215. ** Returns: True if ok.
  216. **
  217. *******************************************************************************/
  218. static bool loadFromFile (std::string& routesXml);
  219. /*******************************************************************************
  220. **
  221. ** Function: deleteFile
  222. **
  223. ** Description: Delete route data XML file.
  224. **
  225. ** Returns: True if ok.
  226. **
  227. *******************************************************************************/
  228. static bool deleteFile ();
  229. /*******************************************************************************
  230. **
  231. ** Function: printDiagnostic
  232. **
  233. ** Description: Print some diagnostic output.
  234. **
  235. ** Returns: None.
  236. **
  237. *******************************************************************************/
  238. void printDiagnostic ();
  239. private:
  240. Database mSecElemRouteDatabase; //routes when NFC service selects sec elem
  241. Database mDefaultRouteDatabase; //routes when NFC service deselects sec elem
  242. static const char* sConfigFile;
  243. static const bool sDebug = false;
  244. /*******************************************************************************
  245. **
  246. ** Function: deleteDatabase
  247. **
  248. ** Description: Delete all routes stored in all databases.
  249. **
  250. ** Returns: None.
  251. **
  252. *******************************************************************************/
  253. void deleteDatabase ();
  254. /*******************************************************************************
  255. **
  256. ** Function: importProtocolRoute
  257. **
  258. ** Description: Parse data for protocol routes.
  259. ** element: XML node for one protocol route.
  260. ** database: store data in this database.
  261. **
  262. ** Returns: None.
  263. **
  264. *******************************************************************************/
  265. //void importProtocolRoute (xmlNodePtr& element, Database& database);
  266. /*******************************************************************************
  267. **
  268. ** Function: importTechnologyRoute
  269. **
  270. ** Description: Parse data for technology routes.
  271. ** element: XML node for one technology route.
  272. ** database: store data in this database.
  273. **
  274. ** Returns: None.
  275. **
  276. *******************************************************************************/
  277. // void importTechnologyRoute (xmlNodePtr& element, Database& database);
  278. };