1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
|
/****************************************************************************
* *
* OpenNI 1.x Alpha *
* Copyright (C) 2011 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* OpenNI is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* OpenNI is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
* *
****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnModuleLoader.h"
#include "XnInternalDefs.h"
#include <XnOpenNI.h>
#include <XnLog.h>
#include "XnXml.h"
#include "XnTypeManager.h"
#include <XnArray.h>
#include <XnAlgorithms.h>
#include "xnInternalFuncs.h"
#if !XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
#include <XnModuleCFunctions.h>
#endif
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define XN_MODULE_LOADER_MAX_MODULES_COUNT 1000
#define XN_MODULE_LOADER_MAX_INTERFACE_PER_MODULE 20
#define XN_MASK_MODULE_LOADER "ModuleLoader"
#define XN_MODULE_ELEMENT_NAME "Module"
#define XN_VALIDATE_FUNC_NOT_NULL(pInterface, func) \
if ((pInterface)->func == NULL) \
{ \
xnLogWarning(XN_MASK_MODULE_LOADER, "Production Node does not have the %s function!", \
XN_STRINGIFY(func)); \
return XN_STATUS_INVALID_GENERATOR; \
}
#define XN_VALIDATE_CAPABILITY_STRUCT(name, pStruct) \
{ \
XnStatus nTempRetVal = ValidateFunctionGroup( \
XN_STRINGIFY(name), \
(void**)pStruct, \
sizeof(*pStruct)/sizeof(void*)); \
XN_IS_STATUS_OK(nTempRetVal); \
}
#define XN_VALIDATE_CAPABILITY(pInterface, name) \
XN_VALIDATE_CAPABILITY_STRUCT(name, pInterface->p##name##Interface)
//---------------------------------------------------------------------------
// Backwards Compatibility Issues
//---------------------------------------------------------------------------
static XnVersion EXTENSIONS_VERSION = { 1, 1, 0, 0 };
typedef const void* (XN_CALLBACK_TYPE* GetDataPrototype)(XnModuleNodeHandle hGenerator);
static const void* XN_CALLBACK_TYPE GetDataNull(XnModuleNodeHandle /*hGenerator*/)
{
return NULL;
}
typedef XnUInt32 (XN_CALLBACK_TYPE* GetBytesPerPixelPrototype)(XnModuleNodeHandle hGenerator);
static XnUInt32 XN_CALLBACK_TYPE GetDepthBytesPerPixel(XnModuleNodeHandle /*hNode*/)
{
return sizeof(XnDepthPixel);
}
static XnUInt32 XN_CALLBACK_TYPE GetIRBytesPerPixel(XnModuleNodeHandle /*hNode*/)
{
return sizeof(XnIRPixel);
}
static XnUInt32 XN_CALLBACK_TYPE GetSceneBytesPerPixel(XnModuleNodeHandle /*hNode*/)
{
return sizeof(XnLabel);
}
//---------------------------------------------------------------------------
// XnDescriptionKeyManager class
//---------------------------------------------------------------------------
XnHashCode XnModuleLoader::XnDescriptionKeyManager::Hash(XnProductionNodeDescription const& key)
{
XnUInt32 nTotalCRC = 0;
nTotalCRC += (key.Type * 19);
XnUInt32 nTempCRC;
xnOSStrCRC32(key.strVendor, &nTempCRC);
nTotalCRC += nTempCRC;
xnOSStrCRC32(key.strName, &nTempCRC);
nTotalCRC += nTempCRC;
xnOSStrNCRC32((XnUChar*)&key.Version, sizeof(key.Version), &nTempCRC);
nTotalCRC += nTempCRC;
// convert from UINT32 to XnHashValue
return nTotalCRC % (1 << (sizeof(XnHashCode)*8));
}
XnInt32 XnModuleLoader::XnDescriptionKeyManager::Compare(XnProductionNodeDescription const& key1, XnProductionNodeDescription const& key2)
{
XnInt32 nResult = key1.Type - key2.Type;
if (nResult == 0)
{
nResult = strcmp(key1.strVendor, key2.strVendor);
}
if (nResult == 0)
{
nResult = strcmp(key1.strName, key2.strName);
}
if (nResult == 0)
{
nResult = xnVersionCompare(&key1.Version, &key2.Version);
}
return nResult;
}
XnStatus resolveModulesFile(XnChar* strFileName, XnUInt32 nBufSize)
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = xnGetOpenNIConfFilesPath(strFileName, nBufSize);
XN_IS_STATUS_OK(nRetVal);
nRetVal = xnOSStrAppend(strFileName, "modules.xml", nBufSize);
XN_IS_STATUS_OK(nRetVal);
return (XN_STATUS_OK);
}
XnStatus loadModulesFile(TiXmlDocument& doc)
{
XnStatus nRetVal = XN_STATUS_OK;
XnChar strFileName[XN_FILE_MAX_PATH];
nRetVal = resolveModulesFile(strFileName, XN_FILE_MAX_PATH);
XN_IS_STATUS_OK(nRetVal);
XnBool bDoesExist = FALSE;
nRetVal = xnOSDoesFileExist(strFileName, &bDoesExist);
XN_IS_STATUS_OK(nRetVal);
if (bDoesExist)
{
nRetVal = xnXmlLoadDocument(doc, strFileName);
XN_IS_STATUS_OK(nRetVal);
}
else
{
TiXmlElement root("Modules");
doc.InsertEndChild(root);
doc.SaveFile(strFileName);
}
return (XN_STATUS_OK);
}
XnStatus saveModulesFile(TiXmlDocument& doc)
{
XnStatus nRetVal = XN_STATUS_OK;
XnChar strFileName[XN_FILE_MAX_PATH];
nRetVal = resolveModulesFile(strFileName, XN_FILE_MAX_PATH);
XN_IS_STATUS_OK(nRetVal);
if (!doc.SaveFile(strFileName))
{
return XN_STATUS_OS_FILE_WRITE_FAILED;
}
return (XN_STATUS_OK);
}
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
XnModuleLoader::XnModuleLoader() : m_loadingMode(LOADING_MODE_LOAD)
{
}
XnModuleLoader::~XnModuleLoader()
{
// free memory
for (XnLoadedGeneratorsHash::Iterator it = m_AllGenerators.Begin(); it != m_AllGenerators.End(); ++it)
{
xnOSFree(it->Value().strConfigDir);
XN_DELETE(it->Value().pInterface);
}
}
void XnModuleLoader::SetLoadingMode(LoadingMode mode)
{
m_loadingMode = mode;
}
XnStatus XnModuleLoader::Init()
{
XnStatus nRetVal = XN_STATUS_OK;
#if XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
nRetVal = LoadAllModules();
XN_IS_STATUS_OK(nRetVal);
#else
for (RegisteredModulesList::Iterator it = sm_modulesList.Begin(); it != sm_modulesList.End(); ++it)
{
RegisteredModule& module = *it;
nRetVal = AddModule(module.pInterface, module.strConfigDir, module.strName);
XN_IS_STATUS_OK(nRetVal);
}
#endif
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadAllModules()
{
XnStatus nRetVal = XN_STATUS_OK;
// first load OpenNI itself
nRetVal = AddOpenNIGenerators();
XN_IS_STATUS_OK(nRetVal);
// now load modules
TiXmlDocument doc;
nRetVal = loadModulesFile(doc);
XN_IS_STATUS_OK(nRetVal);
// try to load each
TiXmlElement* pModule = doc.RootElement()->FirstChildElement(XN_MODULE_ELEMENT_NAME);
while (pModule != NULL)
{
const XnChar* strModulePath = NULL;
nRetVal = xnXmlReadStringAttribute(pModule, "path", &strModulePath);
XN_IS_STATUS_OK(nRetVal);
const XnChar* strConfigDir = pModule->Attribute("configDir");
nRetVal = LoadModule(strModulePath, strConfigDir);
XN_IS_STATUS_OK(nRetVal);
pModule = pModule->NextSiblingElement(XN_MODULE_ELEMENT_NAME);
}
if (m_loadingMode == LOADING_MODE_LOAD && m_AllGenerators.Size() == 0)
{
return (XN_STATUS_NO_MODULES_FOUND);
}
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadModule(const XnChar* strFileName, const XnChar* strConfigDir)
{
XnStatus nRetVal = XN_STATUS_OK;
xnLogVerbose(XN_MASK_MODULE_LOADER, "Checking %s...", strFileName);
if (m_loadingMode == LOADING_MODE_PRINT)
{
printf("%s ", strFileName);
}
XN_LIB_HANDLE hLib;
nRetVal = xnOSLoadLibrary(strFileName, &hLib);
if (nRetVal != XN_STATUS_OK)
{
xnLogWarning(XN_MASK_MODULE_LOADER, "Failed to load '%s' - missing dependencies?", strFileName);
return (XN_STATUS_OK);
}
nRetVal = AddModuleGenerators(strFileName, hLib, strConfigDir);
if (nRetVal != XN_STATUS_OK)
{
xnOSFreeLibrary(hLib);
return (nRetVal);
}
if (m_loadingMode == LOADING_MODE_PRINT)
{
printf("\n");
}
return (XN_STATUS_OK);
}
inline static XnStatus FindFuncAddress(const XnChar* strModuleFile, XN_LIB_HANDLE hLib, const XnChar* funcName, XnFarProc* pFunc)
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = xnOSGetProcAddress(hLib, funcName, pFunc);
if (nRetVal != XN_STATUS_OK)
{
xnLogWarning(XN_MASK_MODULE_LOADER, "'%s' is not a valid module: can't find '%s' function!", strModuleFile, funcName);
return (nRetVal);
}
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::AddModuleGenerators(const XnChar* strModuleFile, XN_LIB_HANDLE hLib, const XnChar* strConfigDir)
{
XnStatus nRetVal = XN_STATUS_OK;
XnOpenNIModuleInterface openNIModule;
// get the function pointers
nRetVal = FindFuncAddress(strModuleFile, hLib, XN_STRINGIFY(XN_MODULE_LOAD), (XnFarProc*)&openNIModule.pLoadFunc);
XN_IS_STATUS_OK(nRetVal);
nRetVal = FindFuncAddress(strModuleFile, hLib, XN_STRINGIFY(XN_MODULE_UNLOAD), (XnFarProc*)&openNIModule.pUnloadFunc);
XN_IS_STATUS_OK(nRetVal);
nRetVal = FindFuncAddress(strModuleFile, hLib, XN_STRINGIFY(XN_MODULE_GET_EXPORTED_NODES_COUNT), (XnFarProc*)&openNIModule.pGetCountFunc);
XN_IS_STATUS_OK(nRetVal);
nRetVal = FindFuncAddress(strModuleFile, hLib, XN_STRINGIFY(XN_MODULE_GET_EXPORTED_NODES_ENTRY_POINTS), (XnFarProc*)&openNIModule.pGetEntryPointsFunc);
XN_IS_STATUS_OK(nRetVal);
nRetVal = FindFuncAddress(strModuleFile, hLib, XN_STRINGIFY(XN_MODULE_GET_OPEN_NI_VERSION), (XnFarProc*)&openNIModule.pGetVersionFunc);
XN_IS_STATUS_OK(nRetVal);
// add it
nRetVal = AddModule(&openNIModule, strConfigDir, strModuleFile);
XN_IS_STATUS_OK(nRetVal);
return XN_STATUS_OK;
}
XnStatus XnModuleLoader::AddOpenNIGenerators()
{
XnStatus nRetVal = XN_STATUS_OK;
XnOpenNIModuleInterface* pOpenNIModule = GetOpenNIModuleInterface();
// add it
nRetVal = AddModule(pOpenNIModule, NULL, "OpenNI");
XN_IS_STATUS_OK(nRetVal);
return XN_STATUS_OK;
}
XnStatus XnModuleLoader::AddModule(XnOpenNIModuleInterface* pInterface, const XnChar* strConfigDir, const XnChar* strName)
{
XnStatus nRetVal = XN_STATUS_OK;
// get OpenNI Version
XnVersion openNIVersion;
pInterface->pGetVersionFunc(&openNIVersion);
if (m_loadingMode == LOADING_MODE_PRINT)
{
XnChar strOpenNIVersion[100];
xnVersionToString(&openNIVersion, strOpenNIVersion, 100);
printf("(compiled with OpenNI %s):\n", strOpenNIVersion);
}
// load Module
nRetVal = pInterface->pLoadFunc();
if (nRetVal != XN_STATUS_OK)
{
xnLogWarning(XN_MASK_MODULE_LOADER, "'%s' load function failed. Error code: 0x%x", strName, nRetVal);
return (nRetVal);
}
// take the number of generators
XnUInt32 nCount = pInterface->pGetCountFunc();
// allocate entry points array
XnModuleGetExportedInterfacePtr* aEntryPoints;
XN_VALIDATE_CALLOC(aEntryPoints, XnModuleGetExportedInterfacePtr, nCount);
// fill it
nRetVal = pInterface->pGetEntryPointsFunc(aEntryPoints, nCount);
if (nRetVal != XN_STATUS_OK)
{
xnLogWarning(XN_MASK_MODULE_LOADER, "'%s' - failed to get exported nodes. Error code: 0x%x", strName, nRetVal);
xnOSFree(aEntryPoints);
return (nRetVal);
}
// now add every exported node
for (XnUInt32 i = 0; i < nCount; ++i)
{
// get exported interface
XnModuleExportedProductionNodeInterface ExportedInterface;
aEntryPoints[i](&ExportedInterface);
nRetVal = AddExportedNode(openNIVersion, &ExportedInterface, strConfigDir);
if (nRetVal == XN_STATUS_INVALID_GENERATOR)
{
// if it failed, then this specific generator is not loaded, but the rest should be loaded anyway.
xnLogWarning(XN_MASK_MODULE_LOADER, "Failed to add generator %d from module '%s'", i, strName);
}
else if (nRetVal != XN_STATUS_OK)
{
xnOSFree(aEntryPoints);
return (nRetVal);
}
}
xnOSFree(aEntryPoints);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::AddExportedNode(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, const XnChar* strConfigDir)
{
XnStatus nRetVal = XN_STATUS_OK;
// Validate we have all mandatory functions
XN_VALIDATE_FUNC_NOT_NULL(pExportedInterface, GetDescription);
XN_VALIDATE_FUNC_NOT_NULL(pExportedInterface, EnumerateProductionTrees);
XN_VALIDATE_FUNC_NOT_NULL(pExportedInterface, Create);
XN_VALIDATE_FUNC_NOT_NULL(pExportedInterface, Destroy);
XN_VALIDATE_FUNC_NOT_NULL(pExportedInterface, GetInterface.General);
XnLoadedGenerator loaded;
xnOSMemSet(&loaded, 0, sizeof(loaded));
loaded.ExportedInterface = *pExportedInterface;
// Get Description
pExportedInterface->GetDescription(&loaded.Description);
XnChar strDescription[512];
xnProductionNodeDescriptionToString(&loaded.Description, strDescription, 512);
xnLogVerbose(XN_MASK_MODULE_LOADER, "Found exported production node. %s", strDescription);
if (m_loadingMode == LOADING_MODE_PRINT)
{
printf("\t%s\n", strDescription);
}
// make sure it's not in the list
XnLoadedGeneratorsHash::ConstIterator it = m_AllGenerators.Find(loaded.Description);
if (it != m_AllGenerators.End())
{
XN_LOG_WARNING_RETURN(XN_STATUS_INVALID_GENERATOR, XN_MASK_MODULE_LOADER, "A Generator with the same description already exists!");
}
// Now load specific interface
XnProductionNodeInterfaceContainer* pInterfaceContainer = NULL;
nRetVal = LoadSpecificInterface(moduleOpenNIVersion, loaded.Description.Type, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
loaded.pInterface = pInterfaceContainer;
if (strConfigDir != NULL)
{
loaded.strConfigDir = xnOSStrDup(strConfigDir);
}
// Add it to list
if (m_loadingMode == LOADING_MODE_LOAD)
{
nRetVal = m_AllGenerators.Set(loaded.Description, loaded);
if (nRetVal != XN_STATUS_OK)
{
xnOSFree(loaded.strConfigDir);
XN_DELETE(pInterfaceContainer);
return (nRetVal);
}
}
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadSpecificInterface(XnVersion& moduleOpenNIVersion, XnProductionNodeType Type, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
const XnBitSet* pHierarchy;
nRetVal = TypeManager::GetInstance().GetTypeHierarchy(Type, pHierarchy);
XN_IS_STATUS_OK(nRetVal);
// start with concrete types
if (pHierarchy->IsSet(XN_NODE_TYPE_DEVICE))
{
nRetVal = LoadDeviceNode(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_DEPTH))
{
nRetVal = LoadDepthGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_IMAGE))
{
nRetVal = LoadImageGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_IR))
{
nRetVal = LoadIRGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_GESTURE))
{
nRetVal = LoadGestureGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_USER))
{
nRetVal = LoadUserGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_HANDS))
{
nRetVal = LoadHandsGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_SCENE))
{
nRetVal = LoadSceneAnalyzer(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_AUDIO))
{
nRetVal = LoadAudioGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_RECORDER))
{
nRetVal = LoadRecorder(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_PLAYER))
{
nRetVal = LoadPlayer(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_CODEC))
{
nRetVal = LoadCodec(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_SCRIPT))
{
nRetVal = LoadScriptNode(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
// and now, some abstract types
else if (pHierarchy->IsSet(XN_NODE_TYPE_MAP_GENERATOR))
{
nRetVal = LoadMapGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_GENERATOR))
{
nRetVal = LoadGenerator(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else if (pHierarchy->IsSet(XN_NODE_TYPE_PRODUCTION_NODE))
{
nRetVal = LoadProductionNode(moduleOpenNIVersion, pExportedInterface, pInterfaceContainer);
XN_IS_STATUS_OK(nRetVal);
}
else
{
XN_LOG_ERROR_RETURN(XN_STATUS_UNKNOWN_GENERATOR_TYPE, XN_MASK_MODULE_LOADER, "Unknown type: %u", Type);
}
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadDeviceNode(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnDeviceInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Device(&Interface.Device);
// validate it
nRetVal = ValidateDeviceInterface(moduleOpenNIVersion, &Interface.Device);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnDeviceInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnDeviceInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadDepthGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnDepthGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Depth(&Interface.Depth);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = (GetDataPrototype)Interface.Depth.GetDepthMap;
Interface.Map.GetBytesPerPixel = GetDepthBytesPerPixel;
}
// validate it
nRetVal = ValidateDepthGeneratorInterface(moduleOpenNIVersion, &Interface.Depth);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnDepthGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnDepthGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadImageGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnImageGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Image(&Interface.Image);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = (GetDataPrototype)Interface.Image.GetImageMap;
Interface.Map.GetBytesPerPixel = (GetBytesPerPixelPrototype)XN_SPECIAL_BC_BEHAVIOR;
}
// validate interface
nRetVal = ValidateImageGeneratorInterface(moduleOpenNIVersion, &Interface.Image);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnImageGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnImageGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadIRGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnIRGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.IR(&Interface.IR);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = (GetDataPrototype)Interface.IR.GetIRMap;
Interface.Map.GetBytesPerPixel = GetIRBytesPerPixel;
}
// validate interface
nRetVal = ValidateIRGeneratorInterface(moduleOpenNIVersion, &Interface.IR);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnIRGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnIRGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadGestureGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnGestureGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Gesture(&Interface.Gesture);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = GetDataNull;
}
// validate interface
nRetVal = ValidateGestureGeneratorInterface(moduleOpenNIVersion, &Interface.Gesture);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnGestureGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnGestureGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return XN_STATUS_OK;
}
XnStatus XnModuleLoader::LoadUserGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnUserGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.User(&Interface.User);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = GetDataNull;
}
// validate interface
nRetVal = ValidateUserGeneratorInterface(moduleOpenNIVersion, &Interface.User);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnUserGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnUserGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return XN_STATUS_OK;
}
XnStatus XnModuleLoader::LoadHandsGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnHandsGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Hands(&Interface.Hands);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = GetDataNull;
}
// validate interface
nRetVal = ValidateHandsGeneratorInterface(moduleOpenNIVersion, &Interface.Hands);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnHandsGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnHandsGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return XN_STATUS_OK;
}
XnStatus XnModuleLoader::LoadSceneAnalyzer(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnSceneAnalyzerInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Scene(&Interface.Scene);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = (GetDataPrototype)Interface.Scene.GetLabelMap;
Interface.Map.GetBytesPerPixel = GetSceneBytesPerPixel;
}
// validate interface
nRetVal = ValidateSceneAnalyzerInterface(moduleOpenNIVersion, &Interface.Scene);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnSceneAnalyzerInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnSceneAnalyzerInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return XN_STATUS_OK;
}
XnStatus XnModuleLoader::LoadAudioGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnAudioGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Audio(&Interface.Audio);
// fix BC issues
if (xnVersionCompare(&moduleOpenNIVersion, &EXTENSIONS_VERSION) < 0)
{
Interface.Generator.GetData = (GetDataPrototype)Interface.Audio.GetAudioBuffer;
}
// validate interface
nRetVal = ValidateAudioGeneratorInterface(moduleOpenNIVersion, &Interface.Audio);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnAudioGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnAudioGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadRecorder(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnRecorderInterfaceContainer interface;
// fill it up
pExportedInterface->GetInterface.Recorder(&interface.recorder);
// validate interface
nRetVal = ValidateRecorderInterface(moduleOpenNIVersion, &interface.recorder);
XN_IS_STATUS_OK(nRetVal);
/*interface.recorder.pNodeNotifications points to interface.nodeNotifications,
so interface.nodeNotifications is already set. */
nRetVal = ValidateNodeNotifications(moduleOpenNIVersion, &interface.nodeNotifications);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnRecorderInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnRecorderInterfaceContainer);
*pContainer = interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadPlayer(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnPlayerInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Player(&Interface.Player);
// validate interface
nRetVal = ValidatePlayerInterface(moduleOpenNIVersion, &Interface.Player);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnPlayerInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnPlayerInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadCodec(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnCodecInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Codec(&Interface.Codec);
// validate interface
nRetVal = ValidateCodecInterface(moduleOpenNIVersion, &Interface.Codec);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnCodecInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnCodecInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadScriptNode(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnScriptNodeInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Script(&Interface.Script);
// validate interface
nRetVal = ValidateScriptNodeInterface(moduleOpenNIVersion, &Interface.Script);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnScriptNodeInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnScriptNodeInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadProductionNode(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnProductionNodeInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.ProductionNode(&Interface.ProductionNode);
// validate interface
nRetVal = ValidateProductionNodeInterface(moduleOpenNIVersion, &Interface.ProductionNode);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnProductionNodeInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnProductionNodeInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.Generator(&Interface.Generator);
// validate interface
nRetVal = ValidateGeneratorInterface(moduleOpenNIVersion, &Interface.Generator);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::LoadMapGenerator(XnVersion& moduleOpenNIVersion, XnModuleExportedProductionNodeInterface* pExportedInterface, XnProductionNodeInterfaceContainer*& pInterfaceContainer)
{
XnStatus nRetVal = XN_STATUS_OK;
XnMapGeneratorInterfaceContainer Interface;
// fill it up
pExportedInterface->GetInterface.MapGenerator(&Interface.Map);
// validate interface
nRetVal = ValidateMapGeneratorInterface(moduleOpenNIVersion, &Interface.Map);
XN_IS_STATUS_OK(nRetVal);
// everything is OK. Allocate and store it
XnMapGeneratorInterfaceContainer* pContainer;
XN_VALIDATE_NEW(pContainer, XnMapGeneratorInterfaceContainer);
*pContainer = Interface;
pInterfaceContainer = pContainer;
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateProductionNodeInterface(XnVersion& /*moduleOpenNIVersion*/, XnModuleProductionNodeInterface* pInterface)
{
XN_VALIDATE_FUNC_NOT_NULL(pInterface, IsCapabilitySupported);
// NOTE: we allow general set / get functions to be NULL, so no need to check them
// validate extended serialization capability
XN_VALIDATE_CAPABILITY(pInterface, ExtendedSerialization);
// validate lock aware capability
XN_VALIDATE_CAPABILITY(pInterface, LockAware);
// validate error state capability
XN_VALIDATE_CAPABILITY(pInterface, ErrorState);
// validate general int capability
XN_VALIDATE_CAPABILITY(pInterface, GeneralInt);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateDeviceInterface(XnVersion& moduleOpenNIVersion, XnModuleDeviceInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = ValidateProductionNodeInterface(moduleOpenNIVersion, pInterface->pProductionNode);
XN_IS_STATUS_OK(nRetVal);
// validate identification capability
XN_VALIDATE_CAPABILITY(pInterface, DeviceIdentification);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = ValidateProductionNodeInterface(moduleOpenNIVersion, pInterface->pProductionNodeInterface);
XN_IS_STATUS_OK(nRetVal);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, StartGenerating);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, StopGenerating);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToGenerationRunningChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromGenerationRunningChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToNewDataAvailable);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromNewDataAvailable);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, IsNewDataAvailable);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UpdateData);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetData);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetDataSize);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetTimestamp);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetFrameID);
// validate mirror capability
XN_VALIDATE_CAPABILITY(pInterface, Mirror);
// validate alternative view point capability
XN_VALIDATE_CAPABILITY(pInterface, AlternativeViewPoint);
// validate frame sync capability
XN_VALIDATE_CAPABILITY(pInterface, FrameSync);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateMapGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleMapGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateGeneratorInterface(moduleOpenNIVersion, pInterface->pGeneratorInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetSupportedMapOutputModes);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetMapOutputMode);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetMapOutputMode);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToMapOutputModeChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromMapOutputModeChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetBytesPerPixel); // This function was only added in 1.0.0.30, but we already BC it in each LoadX() function.
// validate Cropping interface
XN_VALIDATE_CAPABILITY(pInterface, Cropping);
// validate AntiFlicker interface
XN_VALIDATE_CAPABILITY(pInterface, AntiFlicker);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateDepthGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleDepthGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateMapGeneratorInterface(moduleOpenNIVersion, pInterface->pMapInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetDeviceMaxDepth);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetFieldOfView);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToFieldOfViewChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromFieldOfViewChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetDepthMap);
// now check capabilities
XN_VALIDATE_CAPABILITY(pInterface, UserPosition);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateImageGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleImageGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateMapGeneratorInterface(moduleOpenNIVersion, pInterface->pMapInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetImageMap);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, IsPixelFormatSupported);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetPixelFormat);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetPixelFormat);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToPixelFormatChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromPixelFormatChange);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateIRGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleIRGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateMapGeneratorInterface(moduleOpenNIVersion, pInterface->pMapInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetIRMap);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateGestureGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleGestureGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateGeneratorInterface(moduleOpenNIVersion, pInterface->pGeneratorInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, AddGesture);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RemoveGesture);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetActiveGestures);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, EnumerateGestures);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, IsGestureAvailable);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, IsGestureProgressSupported);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterGestureCallbacks);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterGestureCallbacks);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToGestureChange);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromGestureChange);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateSceneAnalyzerInterface(XnVersion& moduleOpenNIVersion, XnModuleSceneAnalyzerInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateMapGeneratorInterface(moduleOpenNIVersion, pInterface->pMapInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetLabelMap);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetFloor);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateUserGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleUserGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateGeneratorInterface(moduleOpenNIVersion, pInterface->pGeneratorInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetNumberOfUsers);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetUsers);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetCoM);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetUserPixels);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterUserCallbacks);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterUserCallbacks);
// now check Skeleton capability. NOTE: we don't check the entire struct. Only the first 28
// functions are mandatory. The rest were added in future versions
nRetVal = ValidateFunctionGroup("Skeleton", (void**)pInterface->pSkeletonInterface, 28);
XN_IS_STATUS_OK(nRetVal);
// now check Skeleton capability. NOTE: we don't check the entire struct. Only the first 6
// functions are mandatory. The rest were added in future versions
nRetVal = ValidateFunctionGroup("PoseDetection", (void**)pInterface->pPoseDetectionInterface, 6);
XN_IS_STATUS_OK(nRetVal);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateHandsGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleHandsGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateGeneratorInterface(moduleOpenNIVersion, pInterface->pGeneratorInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterHandCallbacks);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterHandCallbacks);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, StopTracking);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, StopTrackingAll);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, StartTracking);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetSmoothing);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateAudioGeneratorInterface(XnVersion& moduleOpenNIVersion, XnModuleAudioGeneratorInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
// validate base
nRetVal = ValidateGeneratorInterface(moduleOpenNIVersion, pInterface->pGeneratorInterface);
XN_IS_STATUS_OK(nRetVal);
// validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetAudioBuffer);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetSupportedWaveOutputModes);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetWaveOutputMode);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetWaveOutputMode);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToWaveOutputModeChanges);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromWaveOutputModeChanges);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateRecorderInterface(XnVersion& moduleOpenNIVersion, XnModuleRecorderInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetOutputStream);
// validate bases
nRetVal = ValidateProductionNodeInterface(moduleOpenNIVersion, pInterface->pProductionNode);
XN_IS_STATUS_OK(nRetVal);
nRetVal = ValidateNodeNotifications(moduleOpenNIVersion, pInterface->pNodeNotifications);
XN_IS_STATUS_OK(nRetVal);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidatePlayerInterface(XnVersion& moduleOpenNIVersion, XnModulePlayerInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
//validate functions
nRetVal = ValidateProductionNodeInterface(moduleOpenNIVersion, pInterface->pProductionNode);
XN_IS_STATUS_OK(nRetVal);
//validate functions
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetInputStream);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, ReadNext);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetNodeNotifications);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SetRepeat);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SeekToTimeStamp);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, SeekToFrame);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, TellTimestamp);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, TellFrame);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetNumFrames);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetSupportedFormat);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, IsEOF);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, RegisterToEndOfFileReached);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, UnregisterFromEndOfFileReached);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateCodecInterface(XnVersion& moduleOpenNIVersion, XnModuleCodecInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = ValidateProductionNodeInterface(moduleOpenNIVersion, pInterface->pProductionNode);
XN_IS_STATUS_OK(nRetVal);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetCodecID);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, Init);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, CompressData);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, DecompressData);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateScriptNodeInterface(XnVersion& moduleOpenNIVersion, XnModuleScriptNodeInterface* pInterface)
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = ValidateProductionNodeInterface(moduleOpenNIVersion, pInterface->pProductionNode);
XN_IS_STATUS_OK(nRetVal);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, GetSupportedFormat);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, LoadScriptFromFile);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, LoadScriptFromString);
XN_VALIDATE_FUNC_NOT_NULL(pInterface, Run);
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::ValidateNodeNotifications(XnVersion& /*moduleOpenNIVersion*/, XnNodeNotifications* pNodeNotifications)
{
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeAdded);
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeRemoved);
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeIntPropChanged);
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeRealPropChanged);
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeStringPropChanged);
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeStateReady);
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeGeneralPropChanged);
XN_VALIDATE_FUNC_NOT_NULL(pNodeNotifications, OnNodeNewData);
return (XN_STATUS_OK);
}
static XnBool CompareGeneratorsByVersion(const XnLoadedGenerator*& arg1, const XnLoadedGenerator*& arg2)
{
XnInt32 nCompareRes = strcmp(arg1->Description.strVendor, arg2->Description.strVendor);
if (nCompareRes == 0)
{
nCompareRes = strcmp(arg1->Description.strName, arg2->Description.strName);
}
if (nCompareRes == 0)
{
nCompareRes = -xnVersionCompare(&arg1->Description.Version, &arg2->Description.Version);
}
return (nCompareRes < 0);
}
XnStatus XnModuleLoader::Enumerate(XnContext* pContext, XnProductionNodeType Type, XnNodeInfoList* pList, XnEnumerationErrors* pErrors)
{
XnStatus nRetVal = XN_STATUS_OK;
XnArray<const XnLoadedGenerator*> foundGenerators;
foundGenerators.Reserve(50);
for (XnLoadedGeneratorsHash::ConstIterator it = m_AllGenerators.Begin(); it != m_AllGenerators.End(); ++it)
{
const XnLoadedGenerator& LoadedGenerator = it->Value();
// check if it's of the same type and it's not a mock node
if (LoadedGenerator.Description.Type == Type)
{
nRetVal = foundGenerators.AddLast(&LoadedGenerator);
XN_IS_STATUS_OK(nRetVal);
}
}
// now sort the list, so that new versions of a specific generator (vendor + name) will appear first
XnAlgorithms::BubbleSort(foundGenerators.GetData(), foundGenerators.GetSize(), CompareGeneratorsByVersion);
// and now enumerate each one
for (XnUInt32 i = 0; i < foundGenerators.GetSize(); ++i)
{
XnNodeInfoList* pGeneratorList = NULL;
nRetVal = xnNodeInfoListAllocate(&pGeneratorList);
XN_IS_STATUS_OK(nRetVal);
const XnLoadedGenerator* pLoadedGenerator = foundGenerators[i];
nRetVal = pLoadedGenerator->ExportedInterface.EnumerateProductionTrees(pContext, pGeneratorList, pErrors);
if (nRetVal != XN_STATUS_OK && pErrors != NULL)
{
nRetVal = xnEnumerationErrorsAdd(pErrors, &pLoadedGenerator->Description, nRetVal);
if (nRetVal != XN_STATUS_OK)
{
xnNodeInfoListFree(pGeneratorList);
return (nRetVal);
}
}
xnNodeInfoListAppend(pList, pGeneratorList);
xnNodeInfoListFree(pGeneratorList);
}
return (XN_STATUS_OK);
}
XnStatus XnModuleLoader::CreateRootNode(XnContext* pContext, XnNodeInfo* pTree, XnModuleInstance** ppInstance)
{
XnStatus nRetVal = XN_STATUS_OK;
// look for this generator
XnLoadedGenerator* pLoaded = NULL;
nRetVal = m_AllGenerators.Get(*xnNodeInfoGetDescription(pTree), pLoaded);
if (nRetVal == XN_STATUS_NO_MATCH)
{
return XN_STATUS_NODE_NOT_LOADED;
}
XN_IS_STATUS_OK(nRetVal);
// create instance holder
XnModuleInstance* pInstance;
XN_VALIDATE_CALLOC(pInstance, XnModuleInstance, 1);
pInstance->pLoaded = pLoaded;
// create an instance
const XnChar* strInstanceName = xnNodeInfoGetInstanceName(pTree);
const XnChar* strCreationInfo = xnNodeInfoGetCreationInfo(pTree);
XnNodeInfoList* pNeededNodes = xnNodeInfoGetNeededNodes(pTree);
nRetVal = pLoaded->ExportedInterface.Create(pContext, strInstanceName, strCreationInfo, pNeededNodes, pLoaded->strConfigDir, &pInstance->hNode);
XN_IS_STATUS_OK(nRetVal);
*ppInstance = pInstance;
return (XN_STATUS_OK);
}
void XnModuleLoader::DestroyModuleInstance(XnModuleInstance* pInstance)
{
pInstance->pLoaded->ExportedInterface.Destroy(pInstance->hNode);
xnOSFree(pInstance);
}
XnStatus XnModuleLoader::ValidateFunctionGroup(const XnChar* strName, void** aFunctions, XnUInt32 nSize)
{
XnUInt32 nNotNullCount = 0;
for (XnUInt32 i = 0; i < nSize; ++i)
{
if (aFunctions[i] != NULL)
nNotNullCount++;
}
if (nNotNullCount != 0 && nNotNullCount != nSize)
{
xnLogWarning(XN_MASK_MODULE_LOADER, "Production Node has only some of the %s methods!", strName);
return XN_STATUS_INVALID_GENERATOR;
}
return XN_STATUS_OK;
}
XN_C_API XnStatus xnRegisterModule(const XnChar* strModule, const XnChar* strConfigDir)
{
XnStatus nRetVal = XN_STATUS_OK;
XnChar strFullPath[XN_FILE_MAX_PATH];
nRetVal = xnOSGetFullPathName(strModule, strFullPath, XN_FILE_MAX_PATH);
XN_IS_STATUS_OK(nRetVal);
XnBool bExists = FALSE;
nRetVal = xnOSDoesFileExist(strFullPath, &bExists);
XN_IS_STATUS_OK(nRetVal);
if (!bExists)
{
XN_LOG_WARNING_RETURN(XN_STATUS_OS_FILE_NOT_FOUND, XN_MASK_OPEN_NI, "File '%s' does not exist!", strFullPath);
}
XnChar strConfigFullPathBuffer[XN_FILE_MAX_PATH] = {0};
const XnChar* strConfigFullPath = NULL;
if (strConfigDir != NULL)
{
nRetVal = xnOSGetFullPathName(strConfigDir, strConfigFullPathBuffer, XN_FILE_MAX_PATH);
XN_IS_STATUS_OK(nRetVal);
strConfigFullPath = strConfigFullPathBuffer;
bExists = FALSE;
nRetVal = xnOSDoesDirecotyExist(strConfigFullPath, &bExists);
XN_IS_STATUS_OK(nRetVal);
if (!bExists)
{
XN_LOG_WARNING_RETURN(XN_STATUS_OS_FILE_NOT_FOUND, XN_MASK_OPEN_NI, "Config directory '%s' does not exist!", strConfigFullPath);
}
}
// TODO: try to load it to make sure its valid
TiXmlDocument doc;
nRetVal = loadModulesFile(doc);
XN_IS_STATUS_OK(nRetVal);
// check if it's already there
XnBool bFound = FALSE;
TiXmlElement* pModule = doc.RootElement()->FirstChildElement(XN_MODULE_ELEMENT_NAME);
while (pModule != NULL)
{
const XnChar* strPath;
nRetVal = xnXmlReadStringAttribute(pModule, "path", &strPath);
XN_IS_STATUS_OK(nRetVal);
if (strcmp(strPath, strFullPath) == 0)
{
bFound = TRUE;
break;
}
pModule = pModule->NextSiblingElement(XN_MODULE_ELEMENT_NAME);
}
if (!bFound)
{
// Add it
TiXmlElement newElem(XN_MODULE_ELEMENT_NAME);
newElem.SetAttribute("path", strFullPath);
if (strConfigDir != NULL)
{
newElem.SetAttribute("configDir", strConfigFullPath);
}
doc.RootElement()->InsertEndChild(newElem);
nRetVal = saveModulesFile(doc);
XN_IS_STATUS_OK(nRetVal);
}
return (XN_STATUS_OK);
}
XN_C_API XnStatus xnUnregisterModule(const XnChar* strModule)
{
XnStatus nRetVal = XN_STATUS_OK;
XnChar strFullPath[XN_FILE_MAX_PATH];
nRetVal = xnOSGetFullPathName(strModule, strFullPath, XN_FILE_MAX_PATH);
XN_IS_STATUS_OK(nRetVal);
TiXmlDocument doc;
nRetVal = loadModulesFile(doc);
XN_IS_STATUS_OK(nRetVal);
// find this module
TiXmlElement* pModule = doc.RootElement()->FirstChildElement(XN_MODULE_ELEMENT_NAME);
while (pModule != NULL)
{
const XnChar* strPath;
nRetVal = xnXmlReadStringAttribute(pModule, "path", &strPath);
XN_IS_STATUS_OK(nRetVal);
if (xnOSStrCaseCmp(strPath, strFullPath) == 0)
{
doc.RootElement()->RemoveChild(pModule);
break;
}
pModule = pModule->NextSiblingElement(XN_MODULE_ELEMENT_NAME);
}
nRetVal = saveModulesFile(doc);
XN_IS_STATUS_OK(nRetVal);
return (XN_STATUS_OK);
}
XN_C_API XnStatus xnPrintRegisteredModules()
{
XnStatus nRetVal = XN_STATUS_OK;
XnModuleLoader loader;
loader.SetLoadingMode(XnModuleLoader::LOADING_MODE_PRINT);
XnVersion version;
nRetVal = xnGetVersion(&version);
XN_IS_STATUS_OK(nRetVal);
XnChar strVersion[100];
nRetVal = xnVersionToString(&version, strVersion, 100);
XN_IS_STATUS_OK(nRetVal);
printf("OpenNI version is %s.\n", strVersion);
printf("\nRegistered modules:\n\n");
return loader.Init();
}
#if !XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
XnModuleLoader::RegisteredModulesList XnModuleLoader::sm_modulesList;
XnStatus XnModuleLoader::RegisterModule(XnOpenNIModuleInterface* pInterface, const XnChar* strConfigDir, const XnChar* strName)
{
RegisteredModule module = { pInterface, strConfigDir, strName };
return sm_modulesList.AddLast(module);
}
XN_C_API XnStatus xnRegisterModuleWithOpenNI(XnOpenNIModuleInterface* pInterface, const XnChar* strConfigDir, const XnChar* strName)
{
return XnModuleLoader::RegisterModule(pInterface, strConfigDir, strName);
}
#endif
|