void C1WireByOWFS::GetDevices(const std::string inDir, /*out*/std::vector<_t1WireDevice>& devices) const { DIR *d=opendir(inDir.c_str()); if (d != NULL) { struct dirent *de=NULL; // Loop while not NULL while((de=readdir(d))) { // Check dir if (!IsValidDir(de)) continue; // Get the device from it's dirname _t1WireDevice device; GetDevice(inDir, de->d_name, device); // Add device to list devices.push_back(device); // If device is a hub, scan for all hub connected devices (recursively) if (device.family==microlan_coupler) { // Scan in "main" and "aux" dir GetDevices(inDir + "/" + de->d_name + HUB_MAIN_SUB_PATH, devices); GetDevices(inDir + "/" + de->d_name + HUB_AUX_SUB_PATH, devices); } } } closedir(d); }
bool C1WireByOWFS::FindDevice(const std::string inDir, const std::string sID, /*out*/_t1WireDevice& device) const { bool found = false; DIR *d=opendir(inDir.c_str()); if (d != NULL) { struct dirent *de=NULL; // Loop while not NULL or not found while((de=readdir(d)) && !found) { // Check dir if (!IsValidDir(de)) continue; // Get the device from it's dirname GetDevice(inDir, de->d_name, device); // Check if it's the device we are looking for if (device.devid.compare(0,sID.length(),sID)==0) { found=true; continue; } // Else, try to scan hubs (recursively) if (device.family==microlan_coupler) { // Search in "main" and "aux" dir found=FindDevice(inDir + "/" + de->d_name + HUB_MAIN_SUB_PATH, sID, device); if(!found) found=FindDevice(inDir + "/" + de->d_name + HUB_AUX_SUB_PATH, sID, device); } } } closedir(d); return found; }
HANDLE WINAPI EXP_NAME(OpenFilePlugin)(LPCTSTR name, LPCBYTE data, int dataSize #ifdef UNICODE , int OpMode #endif ) { /*if(!SETTINGS_GET(sBrowseXMLFiles, 1)) return INVALID_HANDLE_VALUE;*/ /* int sz = dataSize; while(sz) { if(strchr(" \t\r\n", *data)) { data++; sz--; if(*data != '{' && } break; }*/ { MemoryStream ms((LPCSTR)data, dataSize); AutoUTFInputStream<unsigned, MemoryStream> is(ms); GenericDocument<DocType> d; d.ParseStream(is); auto err = d.GetParseError(); auto ofs= d.GetErrorOffset(); if(err != kParseErrorNone && ofs < (unsigned)dataSize-4) return INVALID_HANDLE_VALUE; } auto plugin = new JsonPlugin(name, data); if(!plugin->IsValidDir()) { delete plugin; return INVALID_HANDLE_VALUE; } return plugin; }