ns.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2003-2005 Neuroshare Project
  4. //
  5. // This is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Lesser General Public
  7. // License as published by the Free Software Foundation; either
  8. // version 2.1 of the License, or (at your option) any later version.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. // Lesser General Public License for more details.
  14. //
  15. // A copy of the GNU Lesser General Public License can be obtained by writing to:
  16. // Free Software Foundation, Inc.,
  17. // 59 Temple Place, Suite 330,
  18. // Boston, MA 02111-1307
  19. // USA
  20. //
  21. // Contact information:
  22. // Kirk Korver
  23. // CyberKinetics, Inc.,
  24. // 391 G Chipeta Way
  25. // Salt Lake City, UT 84108
  26. // USA
  27. // kkorver at cyberkineticsinc.com
  28. //
  29. // Website:
  30. // sourceforge.net/projects/neuroshare
  31. //
  32. // All other copyrights on this material are replaced by this license agreeement.
  33. //
  34. ///////////////////////////////////////////////////////////////////////////////////////////////////
  35. //
  36. // $Author: kirkkorver $
  37. // $Date: 2005/01/24 05:10:47 $
  38. // $Revision: 1.1 $
  39. // $Source: /cvsroot/neuroshare/NSLibraries/ns/ns.c,v $
  40. //
  41. ///////////////////////////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Specification : Glue to a neuroshare library
  44. //
  45. // Authors : Gopal Santhanam
  46. //
  47. //////////////////////////////////////////////////////////////////////////////
  48. /*=========================================================================
  49. | Project : Neuroshare API Glue
  50. | File : ns.c
  51. | Version : v1.01
  52. |--------------------------------------------------------------------------
  53. | Portions of this file are copyright (c) 2002-2003 Total Phase, Inc.
  54. | All rights reserved.
  55. | www.totalphase.com
  56. |
  57. | Redistribution and use in source and binary forms, with or without
  58. | modification, are permitted provided that the following conditions
  59. | are met:
  60. |
  61. | - Redistributions of source code must retain the above copyright
  62. | notice, this list of conditions and the following disclaimer.
  63. |
  64. | - Redistributions in binary form must reproduce the above copyright
  65. | notice, this list of conditions and the following disclaimer in the
  66. | documentation and/or other materials provided with the distribution.
  67. |
  68. | - Neither the name of Total Phase, Inc. nor the names of its
  69. | contributors may be used to endorse or promote products derived from
  70. | this software without specific prior written permission.
  71. |
  72. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  73. | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  74. | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  75. | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  76. | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  77. | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  78. | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  79. | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  80. | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81. | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  82. | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  83. | POSSIBILITY OF SUCH DAMAGE.
  84. |--------------------------------------------------------------------------
  85. |
  86. | API definitions for the Neuroshare file format standard.
  87. |
  88. | Use the following files to access Neuroshare files:
  89. | ns.h -- API header file
  90. | ns.c -- API interface module
  91. |
  92. | A Neuroshare library is required in conjuction with this module.
  93. | For example:
  94. | ns_NEV.so -- Linux shared object
  95. | or
  96. | ns_NEV.dll -- Windows dynamic link library
  97. |
  98. ========================================================================*/
  99. /*=========================================================================
  100. | INCLUDES
  101. ========================================================================*/
  102. /* This #include can be customized to conform to the user's build paths. */
  103. #include "ns.h"
  104. /*=========================================================================
  105. | VERSION CHECK
  106. ========================================================================*/
  107. #define NS_CFILE_VERSION 0x0103 /* v1.03 */
  108. #define NS_REQ_LIB_VERSION 0x0103 /* v1.03 */
  109. /*
  110. * Make sure that the ns.h was included and that
  111. * the version numbers match.
  112. */
  113. #ifndef NS_HEADER_VERSION
  114. # error Unable to include ns.h file. Please check include path.
  115. #elif NS_HEADER_VERSION != NS_CFILE_VERSION
  116. # error Version mismatch between ns.c and ns.h files.
  117. #endif
  118. /*=========================================================================
  119. | CONSTANTS
  120. ========================================================================*/
  121. #define MAX_SO_PATH 256
  122. /*=========================================================================
  123. | LINUX SUPPORT
  124. ========================================================================*/
  125. #ifdef linux
  126. #include <stdio.h>
  127. #include <stdlib.h>
  128. #include <unistd.h>
  129. #include <string.h>
  130. #include <dlfcn.h>
  131. #include <fcntl.h>
  132. #define DLL_HANDLE void *
  133. #define SO_EXT ".so"
  134. #define stricmp strcasecmp
  135. /*
  136. * These functions allow the Linux behavior to emulate
  137. * the Windows behavior as specified below in the Windows
  138. * support section.
  139. *
  140. * First, search for the shared object in the application
  141. * binary path, then in the current working directory.
  142. *
  143. * Searching the application binary path requires /proc
  144. * filesystem support, which is standard in 2.4.x kernels.
  145. *
  146. * If the /proc filesystem is not present, the shared object
  147. * will not be loaded from the execution path unless that path
  148. * is either the current working directory or explicitly
  149. * specified in LD_LIBRARY_PATH.
  150. */
  151. static int _checkPath (const char *path, char *so_name) {
  152. char *filename = (char *)malloc(strlen(path) +1 + strlen(so_name) +1);
  153. int fd;
  154. /* Check if the file is readable */
  155. sprintf(filename, "%s/%s", path, so_name);
  156. fd = open(filename, O_RDONLY);
  157. if (fd >= 0) {
  158. strncpy(so_name, filename, MAX_SO_PATH);
  159. close(fd);
  160. }
  161. /* Clean up and exit */
  162. free(filename);
  163. return (fd >= 0);
  164. }
  165. static void _setSearchPath (char *so_name) {
  166. char path[MAX_SO_PATH+1];
  167. int count;
  168. char *p;
  169. /* Make sure that SO_NAME is not an absolute path. */
  170. if (so_name[0] == '/') return;
  171. /* Check the execution directory name. */
  172. count = readlink("/proc/self/exe", path, MAX_SO_PATH);
  173. if (count > 0) {
  174. path[count] = 0;
  175. if ((p = strrchr(path, '/')) != 0) *p = '\0';
  176. if (path[0] == '\0') strcpy(path, "/");
  177. /* If there is a match, return immediately. */
  178. if (_checkPath(path, so_name)) return;
  179. }
  180. /* Check the current working directory. */
  181. p = getcwd(path, MAX_SO_PATH);
  182. if (p != 0) _checkPath(path, so_name);
  183. }
  184. #endif
  185. /*=========================================================================
  186. | WINDOWS SUPPORT
  187. ========================================================================*/
  188. #if defined(WIN32) || defined(_WIN32)
  189. #include <stdio.h>
  190. #include <windows.h>
  191. #include <string.h>
  192. #define DLL_HANDLE HINSTANCE
  193. #define dlopen(name, flags) LoadLibrary(name)
  194. #define dlsym(handle, name) GetProcAddress(handle, name)
  195. #define dlclose(handle) FreeLibrary(handle);
  196. #define dlerror() "Exiting program"
  197. #define SO_EXT ".dll"
  198. #define snprintf _snprintf
  199. #define stricmp _stricmp
  200. #ifdef __GNUC__
  201. #undef stricmp
  202. #define stricmp strcasecmp
  203. #endif
  204. /*
  205. * Use the default Windows DLL loading rules:
  206. * 1. The directory from which the application binary was loaded.
  207. * 2. The application's current directory.
  208. * 3a. [Windows NT/2000/XP only] 32-bit system directory
  209. * (default: c:\winnt\System32)
  210. * 3b. 16-bit system directory
  211. * (default: c:\winnt\System or c:\windows\system)
  212. * 4. The windows directory
  213. * (default: c:\winnt or c:\windows)
  214. * 5. The directories listed in the PATH environment variable
  215. */
  216. static void _setSearchPath (char *so_name)
  217. {
  218. /* Do nothing */
  219. }
  220. #endif
  221. /*=========================================================================
  222. | LIBRARY FUNCTION TABLE
  223. ========================================================================*/
  224. #if defined(WIN32) || defined(_WIN32)
  225. # define ns_api_stdcall __stdcall
  226. #else
  227. # define ns_api_stdcall
  228. #endif
  229. // Types for all of the function pointers
  230. typedef ns_RESULT (ns_api_stdcall *ns_GetLibraryInfoType)
  231. (ns_LIBRARYINFO *pLibraryInfo, UINT32 dwLibraryInfoSize);
  232. typedef ns_RESULT (ns_api_stdcall *ns_OpenFileType)
  233. (const char *pszFilename, UINT32 *hFile);
  234. typedef ns_RESULT (ns_api_stdcall *ns_GetFileInfoType)
  235. (UINT32 hFile, ns_FILEINFO *pFileInfo, UINT32 dwFileInfoSize);
  236. typedef ns_RESULT (ns_api_stdcall *ns_CloseFileType)
  237. (UINT32 hFile);
  238. typedef ns_RESULT (ns_api_stdcall *ns_GetEntityInfoType)
  239. (UINT32 hFile, UINT32 dwEntityID, ns_ENTITYINFO *pEntityInfo, UINT32 dwEntityInfoSize);
  240. /* Event API */
  241. typedef ns_RESULT (ns_api_stdcall *ns_GetEventInfoType)
  242. (UINT32 hFile, UINT32 dwEntityID, ns_EVENTINFO *pEventInfo, UINT32 dwEventInfoSize);
  243. typedef ns_RESULT (ns_api_stdcall *ns_GetEventDataType)
  244. (UINT32 hFile, UINT32 dwEntityID, UINT32 nIndex, double *pdTimeStamp, void *pData,
  245. UINT32 dwDataSize, UINT32 *pdwDataRetSize);
  246. /* Analog API */
  247. typedef ns_RESULT (ns_api_stdcall *ns_GetAnalogInfoType)
  248. (UINT32 hFile, UINT32 dwEntityID, ns_ANALOGINFO *pAnalogInfo,UINT32 dwAnalogInfoSize);
  249. typedef ns_RESULT (ns_api_stdcall *ns_GetAnalogDataType)
  250. (UINT32 hFile, UINT32 dwEntityID, UINT32 dwStartIndex, UINT32 dwIndexCount,
  251. UINT32 *pdwContCount, double *pData);
  252. /* Segment API */
  253. typedef ns_RESULT (ns_api_stdcall *ns_GetSegmentInfoType)
  254. (UINT32 hFile, UINT32 dwEntityID, ns_SEGMENTINFO *pSegmentInfo,UINT32 dwSegmentInfoSize);
  255. typedef ns_RESULT (ns_api_stdcall *ns_GetSegmentSourceInfoType)
  256. (UINT32 hFile, UINT32 dwEntityID, UINT32 dwSourceID, ns_SEGSOURCEINFO *pSourceInfo,
  257. UINT32 dwSourceInfoSize);
  258. typedef ns_RESULT (ns_api_stdcall *ns_GetSegmentDataType)
  259. (UINT32 hFile, UINT32 dwEntityID, INT32 nIndex, double *pdTimeStamp, double *pdData,
  260. UINT32 dwDataBufferSize, UINT32 *pdwSampleCount, UINT32 *pdwUnitID );
  261. /* Neural API */
  262. typedef ns_RESULT (ns_api_stdcall *ns_GetNeuralInfoType)
  263. (UINT32 hFile, UINT32 dwEntityID, ns_NEURALINFO *pNeuralInfo, UINT32 dwNeuralInfoSize);
  264. typedef ns_RESULT (ns_api_stdcall *ns_GetNeuralDataType)
  265. (UINT32 hFile, UINT32 dwEntityID, UINT32 dwStartIndex, UINT32 dwIndexCount, double *pdData);
  266. /* More General API */
  267. typedef ns_RESULT (ns_api_stdcall *ns_GetIndexByTimeType)
  268. (UINT32 hFile, UINT32 dwEntityID, double dTime, INT32 nFlag, UINT32 *pdwIndex);
  269. typedef ns_RESULT (ns_api_stdcall *ns_GetTimeByIndexType)
  270. (UINT32 hFile, UINT32 dwEntityID, UINT32 dwIndex, double *pdTime);
  271. typedef ns_RESULT (ns_api_stdcall *ns_GetLastErrorMsgType)
  272. (char *pszMsgBuffer, UINT32 dwMsgBufferSize);
  273. struct NS_LIBRARY_FUNCS
  274. {
  275. char so_name[MAX_SO_PATH+1];
  276. int valid;
  277. int refCount;
  278. DLL_HANDLE dllHandle;
  279. /* General API */
  280. ns_GetLibraryInfoType ns_GetLibraryInfo;
  281. ns_OpenFileType ns_OpenFile;
  282. ns_GetFileInfoType ns_GetFileInfo;
  283. ns_CloseFileType ns_CloseFile;
  284. ns_GetEntityInfoType ns_GetEntityInfo;
  285. /* Event API */
  286. ns_GetEventInfoType ns_GetEventInfo;
  287. ns_GetEventDataType ns_GetEventData;
  288. /* Analog API */
  289. ns_GetAnalogInfoType ns_GetAnalogInfo;
  290. ns_GetAnalogDataType ns_GetAnalogData;
  291. /* Segment API */
  292. ns_GetSegmentInfoType ns_GetSegmentInfo;
  293. ns_GetSegmentSourceInfoType ns_GetSegmentSourceInfo;
  294. ns_GetSegmentDataType ns_GetSegmentData;
  295. /* Neural API */
  296. ns_GetNeuralInfoType ns_GetNeuralInfo;
  297. ns_GetNeuralDataType ns_GetNeuralData;
  298. /* More General API */
  299. ns_GetIndexByTimeType ns_GetIndexByTime;
  300. ns_GetTimeByIndexType ns_GetTimeByIndex;
  301. ns_GetLastErrorMsgType ns_GetLastErrorMsg;
  302. };
  303. #define MAX_LIBS 32
  304. /* This is initialized to zero as per ANSI C specifications */
  305. static struct NS_LIBRARY_FUNCS _libraries[MAX_LIBS];
  306. #define CHECK_VALIDITY(nsDllHandle) \
  307. if (nsDllHandle < 1 || nsDllHandle > MAX_LIBS || \
  308. _libraries[nsDllHandle-1].valid == 0) \
  309. return ns_LIBERROR;
  310. /*=========================================================================
  311. | SHARED LIBRARY LOADER
  312. ========================================================================*/
  313. /* The error conditions can be customized depending on the application. */
  314. /* a return value of 0 indicates an error */
  315. ns_DLLHANDLE ns_stdcall ns_LoadLibrary (const char *libname)
  316. {
  317. int i;
  318. DLL_HANDLE handle;
  319. ns_LIBRARYINFO lib_info;
  320. UINT32 lib_api_version;
  321. char so_name[MAX_SO_PATH+1];
  322. for (i=0; i < MAX_LIBS; ++i)
  323. {
  324. if (_libraries[i].valid && !strcmp(libname, _libraries[i].so_name))
  325. {
  326. ++_libraries[i].refCount;
  327. return (i+1);
  328. }
  329. }
  330. /* Find an open slot */
  331. for (i=0; i < MAX_LIBS; ++i)
  332. {
  333. if (!_libraries[i].valid)
  334. break;
  335. }
  336. /* Return an error if we don't have enough slots left */
  337. if (i == MAX_LIBS)
  338. return ns_LIBERROR;
  339. /* Add the extension if necessary */
  340. {
  341. const char * pExt; /* point to the extension */
  342. pExt = libname + strlen(libname) - strlen(SO_EXT);
  343. if (pExt < libname) /* allow for really short library names) */
  344. pExt = libname;
  345. /* strcmp ignoring case */
  346. if (stricmp(pExt, SO_EXT) == 0)
  347. snprintf(so_name, MAX_SO_PATH, "%s", libname); /* copy the name */
  348. else
  349. snprintf(so_name, MAX_SO_PATH, "%s%s", libname, SO_EXT); /* copy the name, add extension */
  350. so_name[MAX_SO_PATH] = 0; /* force termination */
  351. }
  352. _setSearchPath(so_name);
  353. handle = dlopen(so_name, RTLD_LAZY);
  354. if (handle == 0)
  355. {
  356. #if 1
  357. fprintf(stderr, "ns.c: Unable to load %s\n", so_name);
  358. fprintf(stderr, "ns.c: %s\n", dlerror());
  359. #endif
  360. return 0;
  361. }
  362. _libraries[i].ns_GetLibraryInfo = (ns_GetLibraryInfoType)dlsym(handle,
  363. "ns_GetLibraryInfo");
  364. if (_libraries[i].ns_GetLibraryInfo == 0)
  365. {
  366. #if 1
  367. fprintf(stderr, "ns.c: Unable to bind %s ns_GetLibraryInfo function\n",
  368. so_name);
  369. fprintf(stderr, "ns.c: %s\n", dlerror());
  370. #endif
  371. dlclose(handle);
  372. return 0;
  373. }
  374. /* test for compatible versions */
  375. _libraries[i].ns_GetLibraryInfo(&lib_info, sizeof(lib_info));
  376. lib_api_version = ((lib_info.dwAPIVersionMaj << 8) & 0xff00) |
  377. ((lib_info.dwAPIVersionMin << 0) & 0x00ff);
  378. #if 0 /* ALL VERSIONS ARE COMPATIBLE */
  379. if (lib_api_version < NS_REQ_LIB_VERSION ||
  380. NS_CFILE_VERSION < lib_api_version)
  381. {
  382. #if 1
  383. fprintf(stderr, "\nns.c:Incompatible versions:\n");
  384. fprintf(stderr, "ns.c: NS Glue version = v%d.%02d ",
  385. (NS_CFILE_VERSION >> 8) & 0xff, NS_CFILE_VERSION & 0xff);
  386. if (lib_api_version < NS_REQ_LIB_VERSION)
  387. fprintf(stderr, "(requires Library API version >= %d.%02d)\n",
  388. (NS_REQ_LIB_VERSION >> 8) & 0xff,
  389. (NS_REQ_LIB_VERSION >> 0) & 0xff);
  390. else
  391. fprintf(stderr, "(Library API version OK)\n");
  392. fprintf(stderr, "ns.c: Library API version = v%d.%02d ",
  393. (lib_api_version >> 8) & 0xff, lib_api_version & 0xff);
  394. if (NS_CFILE_VERSION < NS_REQ_LIB_VERSION)
  395. fprintf(stderr, "(requires NS Glue version >= %d.%02d)\n",
  396. (lib_api_version >> 8) & 0xff,
  397. (lib_api_version >> 0) & 0xff);
  398. else
  399. fprintf(stderr, "(NS Glue version OK)\n");
  400. #endif
  401. dlclose(handle);
  402. return 0;
  403. }
  404. #endif
  405. // This macro only works because several conventions are followed
  406. // 1) A function named foo, has a type (typedef) called fooType
  407. // 2) The name of the function in our structure is the same name as 3)
  408. // 3) The exported DLL name is the same name as 2)
  409. #define LOAD_LIBRARY(func) \
  410. { \
  411. _libraries[i].func = (func##Type)dlsym(handle, #func); \
  412. if (_libraries[i].func == 0) { \
  413. fprintf(stderr, "ns.c: Unable to bind %s %s function\n", \
  414. so_name, #func); \
  415. fprintf(stderr, "ns.c: %s\n", dlerror()); \
  416. goto error; \
  417. } \
  418. }
  419. /* More General API */
  420. LOAD_LIBRARY(ns_OpenFile);
  421. LOAD_LIBRARY(ns_GetFileInfo);
  422. LOAD_LIBRARY(ns_CloseFile);
  423. LOAD_LIBRARY(ns_GetEntityInfo);
  424. /* Event API */
  425. LOAD_LIBRARY(ns_GetEventInfo);
  426. LOAD_LIBRARY(ns_GetEventData);
  427. /* Analog API */
  428. LOAD_LIBRARY(ns_GetAnalogInfo);
  429. LOAD_LIBRARY(ns_GetAnalogData);
  430. /* Segment API */
  431. LOAD_LIBRARY(ns_GetSegmentInfo);
  432. LOAD_LIBRARY(ns_GetSegmentSourceInfo);
  433. LOAD_LIBRARY(ns_GetSegmentData);
  434. /* Neural API */
  435. LOAD_LIBRARY(ns_GetNeuralInfo);
  436. LOAD_LIBRARY(ns_GetNeuralData);
  437. /* More General API */
  438. LOAD_LIBRARY(ns_GetIndexByTime);
  439. LOAD_LIBRARY(ns_GetTimeByIndex);
  440. LOAD_LIBRARY(ns_GetLastErrorMsg);
  441. #undef LOAD_LIBRARY
  442. /* Setup the other variables in the library structure */
  443. _libraries[i].valid = 1;
  444. _libraries[i].dllHandle = handle;
  445. _libraries[i].refCount = 1;
  446. strncpy(_libraries[i].so_name, so_name, MAX_SO_PATH);
  447. _libraries[i].so_name[MAX_SO_PATH] = 0;
  448. return (i+1);
  449. error:
  450. dlclose(handle);
  451. return 0;
  452. }
  453. ns_RESULT ns_stdcall ns_CloseLibrary (ns_DLLHANDLE nsDllHandle)
  454. {
  455. CHECK_VALIDITY(nsDllHandle)
  456. --_libraries[nsDllHandle -1].refCount;
  457. if (_libraries[nsDllHandle -1].refCount == 0) {
  458. dlclose(_libraries[nsDllHandle -1].dllHandle);
  459. _libraries[nsDllHandle -1].valid = 0;
  460. }
  461. return ns_OK;
  462. }
  463. /*=========================================================================
  464. | GENERAL API
  465. ========================================================================*/
  466. ns_RESULT ns_stdcall ns_GetLibraryInfo (ns_DLLHANDLE nsDllHandle, ns_LIBRARYINFO *pLibraryInfo, UINT32 dwLibraryInfoSize)
  467. {
  468. CHECK_VALIDITY(nsDllHandle)
  469. return _libraries[nsDllHandle-1].ns_GetLibraryInfo(pLibraryInfo, dwLibraryInfoSize);
  470. }
  471. ns_RESULT ns_stdcall ns_OpenFile (ns_DLLHANDLE nsDllHandle, const char *pszFilename, UINT32 *hFile)
  472. {
  473. CHECK_VALIDITY(nsDllHandle)
  474. return _libraries[nsDllHandle-1].ns_OpenFile(pszFilename, hFile);
  475. }
  476. ns_RESULT ns_stdcall ns_GetFileInfo (ns_DLLHANDLE nsDllHandle, UINT32 hFile, ns_FILEINFO *pFileInfo, UINT32 dwFileInfoSize)
  477. {
  478. CHECK_VALIDITY(nsDllHandle)
  479. return _libraries[nsDllHandle-1].ns_GetFileInfo(hFile, pFileInfo, dwFileInfoSize);
  480. }
  481. ns_RESULT ns_stdcall ns_CloseFile (ns_DLLHANDLE nsDllHandle, UINT32 hFile)
  482. {
  483. CHECK_VALIDITY(nsDllHandle)
  484. return _libraries[nsDllHandle-1].ns_CloseFile(hFile);
  485. }
  486. ns_RESULT ns_stdcall ns_GetEntityInfo (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, ns_ENTITYINFO *pEntityInfo, UINT32 dwEntityInfoSize)
  487. {
  488. CHECK_VALIDITY(nsDllHandle)
  489. return _libraries[nsDllHandle-1].ns_GetEntityInfo(hFile, dwEntityID, pEntityInfo, dwEntityInfoSize);
  490. }
  491. /*=========================================================================
  492. | EVENT API
  493. ========================================================================*/
  494. ns_RESULT ns_stdcall ns_GetEventInfo (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, ns_EVENTINFO *pEventInfo, UINT32 dwEventInfoSize)
  495. {
  496. CHECK_VALIDITY(nsDllHandle)
  497. return _libraries[nsDllHandle-1].ns_GetEventInfo(hFile, dwEntityID, pEventInfo, dwEventInfoSize);
  498. }
  499. ns_RESULT ns_stdcall ns_GetEventData (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, UINT32 nIndex, double *pdTimeStamp, void *pData,
  500. UINT32 dwDataSize, UINT32 *pdwDataRetSize)
  501. {
  502. CHECK_VALIDITY(nsDllHandle)
  503. return _libraries[nsDllHandle-1].ns_GetEventData(hFile, dwEntityID, nIndex, pdTimeStamp, pData, dwDataSize, pdwDataRetSize);
  504. }
  505. /*=========================================================================
  506. | ANALOG API
  507. ========================================================================*/
  508. ns_RESULT ns_stdcall ns_GetAnalogInfo (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, ns_ANALOGINFO *pAnalogInfo, UINT32 dwAnalogInfoSize)
  509. {
  510. CHECK_VALIDITY(nsDllHandle)
  511. return _libraries[nsDllHandle-1].ns_GetAnalogInfo(hFile, dwEntityID, pAnalogInfo, dwAnalogInfoSize);
  512. }
  513. ns_RESULT ns_stdcall ns_GetAnalogData (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, UINT32 dwStartIndex, UINT32 dwIndexCount,
  514. UINT32 *pdwContCount, double *pData)
  515. {
  516. CHECK_VALIDITY(nsDllHandle)
  517. return _libraries[nsDllHandle-1].ns_GetAnalogData(hFile, dwEntityID, dwStartIndex, dwIndexCount, pdwContCount, pData);
  518. }
  519. /*=========================================================================
  520. | SEGMENT API
  521. ========================================================================*/
  522. ns_RESULT ns_stdcall ns_GetSegmentInfo (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, ns_SEGMENTINFO *pSegmentInfo, UINT32 dwSegmentInfoSize)
  523. {
  524. CHECK_VALIDITY(nsDllHandle)
  525. return _libraries[nsDllHandle-1].ns_GetSegmentInfo(hFile, dwEntityID, pSegmentInfo, dwSegmentInfoSize);
  526. }
  527. ns_RESULT ns_stdcall ns_GetSegmentSourceInfo (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, UINT32 dwSourceID, ns_SEGSOURCEINFO *pSourceInfo,
  528. UINT32 dwSourceInfoSize)
  529. {
  530. CHECK_VALIDITY(nsDllHandle)
  531. return _libraries[nsDllHandle-1].ns_GetSegmentSourceInfo(hFile, dwEntityID, dwSourceID, pSourceInfo, dwSourceInfoSize);
  532. }
  533. ns_RESULT ns_stdcall ns_GetSegmentData (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, UINT32 nIndex, double *pdTimeStamp, double *pdData,
  534. UINT32 dwDataBufferSize, UINT32 *pdwSampleCount, UINT32 *pdwUnitID )
  535. {
  536. CHECK_VALIDITY(nsDllHandle)
  537. return _libraries[nsDllHandle-1].ns_GetSegmentData(hFile, dwEntityID, nIndex, pdTimeStamp, pdData,
  538. dwDataBufferSize, pdwSampleCount, pdwUnitID );
  539. }
  540. /*=========================================================================
  541. | NEURAL API
  542. ========================================================================*/
  543. ns_RESULT ns_stdcall ns_GetNeuralInfo (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, ns_NEURALINFO *pNeuralInfo, UINT32 dwNeuralInfoSize)
  544. {
  545. CHECK_VALIDITY(nsDllHandle)
  546. return _libraries[nsDllHandle-1].ns_GetNeuralInfo(hFile, dwEntityID, pNeuralInfo, dwNeuralInfoSize);
  547. }
  548. ns_RESULT ns_stdcall ns_GetNeuralData (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, UINT32 dwStartIndex, UINT32 dwIndexCount, double *pdData)
  549. {
  550. CHECK_VALIDITY(nsDllHandle)
  551. return _libraries[nsDllHandle-1].ns_GetNeuralData(hFile, dwEntityID, dwStartIndex, dwIndexCount, pdData);
  552. }
  553. /*=========================================================================
  554. | MORE GENERAL API
  555. ========================================================================*/
  556. ns_RESULT ns_stdcall ns_GetIndexByTime (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, double dTime, INT32 nFlag, UINT32 *pdwIndex)
  557. {
  558. CHECK_VALIDITY(nsDllHandle)
  559. return _libraries[nsDllHandle-1].ns_GetIndexByTime(hFile, dwEntityID, dTime, nFlag, pdwIndex);
  560. }
  561. ns_RESULT ns_stdcall ns_GetTimeByIndex (ns_DLLHANDLE nsDllHandle, UINT32 hFile, UINT32 dwEntityID, UINT32 dwIndex, double *pdTime)
  562. {
  563. CHECK_VALIDITY(nsDllHandle)
  564. return _libraries[nsDllHandle-1].ns_GetTimeByIndex(hFile, dwEntityID, dwIndex, pdTime);
  565. }
  566. ns_RESULT ns_stdcall ns_GetLastErrorMsg (ns_DLLHANDLE nsDllHandle, char *pszMsgBuffer, UINT32 dwMsgBufferSize)
  567. {
  568. CHECK_VALIDITY(nsDllHandle)
  569. return _libraries[nsDllHandle-1].ns_GetLastErrorMsg(pszMsgBuffer, dwMsgBufferSize);
  570. }