1 #include "dmt.hpp" 2 3 #include "dmMemory.h" 4 #include "dmDebug.h" // debug macroses 5 6 #include <stdlib.h> 7 #include <string> 8 #include <map> 9 #include <stdio.h> 10 11 #include "plugin/dmtPlugin.hpp" 12 13 #define Debug printf 14 15 //---------------------------Declaration---------------------- 16 17 PDmtErrorDescription 18 DMCheckMandatoryForSingleNode( 19 const char * szPath, //Single path (removed *) 20 DMStringMap & mapParameters, 21 PDmtTree tree //Global Tree with same access rights for current session 22 ) 23 { 24 bool nodeExist=false; 25 int numNodes=0; 26 27 Debug("Checking single node=%s\n", szPath); 28 nodeExist=tree->IsValidNode(szPath); 29 if (nodeExist) 30 numNodes ++; //Including myself 31 32 int numPaths=0; 33 for ( DMMap<DMString, DMString>::POS it = mapParameters.begin(); 34 it != mapParameters.end(); it++ ) 35 { 36 DMString name = mapParameters.get_key( it ); 37 //ignore value = it->second; 38 39 DMString childPath=name; 40 41 //For Relative path, start with /. Absolute path start with . 42 if (name[0] == '/') 43 { 44 childPath=szPath; 45 //childPath +="/"; 46 childPath += name; 47 numPaths ++; 48 } else 49 if (name[0] != '.') 50 { 51 //other parameters, ignore for now... 52 continue; 53 } 54 55 const char * szName; 56 szName=childPath.c_str(); 57 nodeExist=tree->IsValidNode(szName); 58 Debug(" Check for existence of %s=%d\n", szName, nodeExist); 59 if (nodeExist) 60 numNodes ++; 61 } 62 Debug("numNodes=%d\n", numNodes); 63 Debug("numPaths=%d\n", numPaths); 64 65 if (numNodes ==0 || numNodes== 1+ numPaths) 66 { 67 Debug("constraint Succeed\n"); 68 return PDmtErrorDescription(); 69 } 70 Debug("constraint Failed !!!!!!\n"); 71 return PDmtErrorDescription( new DmtErrorDescription(enumDmtResult_ConstraintFailed) ); 72 } 73 74 extern "C" 75 PDmtErrorDescription DMT_PluginLib_CheckConstraint( 76 const char * path, //Node that was invoked on for that was changed 77 DMStringMap & mapParameters, 78 PDmtTree tree //Global Tree with same access rights for current session 79 ) 80 { 81 Debug("CheckConstraint [%s]\n", path); 82 83 if (tree == NULL) 84 { 85 //When tree is NULL, means we cannot get session/lock? 86 return PDmtErrorDescription( new DmtErrorDescription(enumDmtResult_UnableStartSession) ); 87 } 88 89 #if 0 90 //Test if DmtTree is OK 91 PDmtNode node; 92 PDmtErrorDescription e=tree->GetNode( 93 ".", //const char* path, 94 node //PDmtNode& ptrNode 95 ); 96 if (e!=NULL) 97 { 98 printf( "Can't get node from DmtTree for %s, err=%s\n", ".", (const char*)e->GetErrorText().c_str() ); 99 } 100 nodeExist=tree->IsValidNode("."); 101 Debug( " nodeExist for %s=%d\n", ".", nodeExist ); 102 nodeExist=tree->IsValidNode("./SyncML"); 103 Debug( " nodeExist for %s=%d\n", "./SyncML", nodeExist ); 104 105 #endif 106 107 //No multi node 108 return DMCheckMandatoryForSingleNode( 109 path, 110 mapParameters, 111 tree 112 ); 113 } 114 115 116 extern "C" 117 int DMT_PluginLib_GetAPIVersion(void) 118 { 119 return DMT_PLUGIN_VERSION_1_1; 120 } 121 122