Tango::DevLong DServer::un_lock_device(const Tango::DevVarLongStringArray *in_data) { NoSyncModelTangoMonitor mon(this); cout4 << "In un_lock_device command for device " << in_data->svalue[0] << endl; // // Get client identification // Tango::client_addr *cl = get_client_ident(); if (cl == NULL) { Except::throw_exception((const char*)"API_CantGetClientIdent", (const char*)"Cannot retrieve client identification", (const char*)"DServer::un_lock_device"); } cout4 << "Client identification = " << *cl << endl; if ((cl->client_ident == false) && (in_data->lvalue[0] == 0)) { Except::throw_exception((const char*)"API_ClientTooOld", (const char*)"Your client cannot un-lock devices. You are using a too old Tango release. Please, update to tango V7 or more", (const char*)"DServer::un_lock_device"); } // // Get the device and unlock it // DevLong ctr = 0; Tango::Util *tg = Tango::Util::instance(); for (unsigned int loop = 0;loop < in_data->svalue.length();++loop) { string d_name(in_data->svalue[loop]); if (d_name == get_name()) ctr = ext->lock_ctr; else { DeviceImpl *the_dev = tg->get_device_by_name(d_name); ctr = the_dev->unlock((bool)in_data->lvalue[0]); } if (loop > 0) ctr = 0; } return ctr; }
Tango::DevVarLongStringArray *DServer::dev_lock_status(Tango::ConstDevString dev_name) { NoSyncModelTangoMonitor mon(this); cout4 << "In dev_lock_status command for device " << dev_name << endl; // // Get the device and get its lock status // string d_name(dev_name); Tango::Util *tg = Tango::Util::instance(); DeviceImpl *the_dev = tg->get_device_by_name(d_name); return the_dev->lock_status(); }
int ResourceManager::loadPluginsIn(const std::string &dirname) { int res = 0; DIR *dir; struct dirent *ent; if ( (dir = opendir (dirname.c_str())) != NULL ) { /* print all the files and directories within directory */ while ( (ent = readdir (dir)) != NULL ) { std::string d_name(ent->d_name); if (d_name == "." || d_name == "..") continue; Plugin plugin = iPluginManager.load(std::string(ent->d_name) + "-plugin", dirname + "/" + ent->d_name); #ifdef GreIsDebugMode if( plugin.isInvalid() ) { GreDebugPretty() << "Couldn't load plugin '" << ent->d_name << "'." << std::endl; continue; } #endif plugin.start(); } closedir (dir); } else { /* could not open directory */ perror(""); return 0; } return res; }
int main(int argc, char **argv) { DIR *dp; struct dirent * dirp ; char *foldPath = argv[2]; std::vector<std::string> filenames; if((dp = opendir(foldPath)) == NULL){ std::cout<<"opendir error"<<std::endl; exit(1); } while((dirp = readdir(dp)) != NULL){ char filename[128]; // char mp4File[128]; // strcat(foldPath,new char('/')); char videoFile[256]; sprintf(videoFile,"%s%s", foldPath, dirp->d_name); // strcat(videoFile, foldPath); // strcat(videoFile, dirp->d_name); CvCapture *capture = cvCreateFileCapture(videoFile); //open video std::cout<<videoFile<<std::endl; int count = 0; int period = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS); period = period * atoi(argv[1]);// set the period to the frame capture int num = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT); std::cout<<"period: "<<period<<std::endl<<"num: "<<num<<std::endl; if (capture == NULL) { continue; } IplImage *frame; std::string d_name(dirp->d_name); int pos = d_name.find_last_of('.'); char foldName[256]; sprintf(foldName, "%s%s", foldPath, (d_name.substr(0,pos)).c_str()); // strcat(foldName, foldPath); // strcat(foldName, ); // std::cout<<mkdir(foldName,0755)<<std::endl; if(mkdir(foldName,0755) == 0){ bool stop = false; std::cout<<"dddddddddddddddd"; while (1&&!stop) { for (int i = 0; i < period; i++) { frame = cvQueryFrame(capture); if (!frame) { printf("finish!\n"); system("pause"); stop = true; break; } } if(stop) continue; sprintf(filename, "%s/img_%d.jpg", foldName,count++); std::cout<<filename<<std::endl; cvSaveImage(filename, frame); } }else{ std::cout<<foldName<<std::endl; } cvReleaseCapture(&capture); } return 0; }
/* * delete a file or directory. If force_delet is set then delete * recursively */ int delete_file(char *fname) { DIR *d; struct dirent *di; char buf[MAXPATHLEN]; extern int force_delete; STRUCT_STAT st; int ret; extern int recurse; if (robust_unlink(fname) == 0 || errno == ENOENT) return 0; #if SUPPORT_LINKS ret = do_lstat(fname, &st); #else ret = do_stat(fname, &st); #endif if (ret) { rprintf(FERROR,"stat(%s) : %s\n", fname, strerror(errno)); return -1; } if (!S_ISDIR(st.st_mode)) { rprintf(FERROR,"unlink(%s) : %s\n", fname, strerror(errno)); return -1; } if (do_rmdir(fname) == 0 || errno == ENOENT) return 0; if (!force_delete || !recurse || (errno != ENOTEMPTY && errno != EEXIST)) { rprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno)); return -1; } /* now we do a recsursive delete on the directory ... */ d = opendir(fname); if (!d) { rprintf(FERROR,"opendir(%s): %s\n", fname,strerror(errno)); return -1; } for (di=readdir(d); di; di=readdir(d)) { char *dname = d_name(di); if (strcmp(dname,".")==0 || strcmp(dname,"..")==0) continue; slprintf(buf, sizeof(buf), "%s/%s", fname, dname); if (verbose > 0) rprintf(FINFO,"deleting %s\n", buf); if (delete_file(buf) != 0) { closedir(d); return -1; } } closedir(d); if (do_rmdir(fname) != 0) { rprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno)); return -1; } return 0; }
void DServer::re_lock_devices(const Tango::DevVarStringArray *dev_name_list) { NoSyncModelTangoMonitor mon(this); cout4 << "In re_lock_devices command" << endl; CORBA::ULong loop; CORBA::ULong nb_dev = dev_name_list->length(); for (loop = 0;loop < nb_dev;loop++) cout4 << "Device to re-lock: " << (*dev_name_list)[loop] << endl; // // Get client identification // Tango::client_addr *cl = get_client_ident(); if (cl == NULL) { Except::throw_exception((const char*)"API_CantGetClientIdent", (const char*)"Cannot retrieve client identification", (const char*)"DServer::re_lock_devices"); } cout4 << "Client identification = " << *cl << endl; if (cl->client_ident == false) { Except::throw_exception((const char*)"API_ClientTooOld", (const char*)"Your client cannot re_lock devices. You are using a too old Tango release. Please, update to tango V7 or more", (const char*)"DServer::re_lock_devices"); } // // ReLock the devices // If we have an error in this loop, memorize it and throw the exception at the // end of the loop // Tango::Util *tg = Tango::Util::instance(); DevErrorList errors; long nb_error = 0; for (loop = 0;loop < nb_dev;loop++) { string d_name((*dev_name_list)[loop]); // // Get device ptr // DeviceImpl *the_dev = NULL; try { the_dev = tg->get_device_by_name(d_name); } catch (Tango::DevFailed &e) { errors.length(nb_error + 1); errors[nb_error].desc = CORBA::string_dup(e.errors[0].desc.in()); errors[nb_error].reason = CORBA::string_dup(e.errors[0].reason.in()); errors[nb_error].origin = CORBA::string_dup(e.errors[0].origin.in()); errors[nb_error].severity = e.errors[0].severity; nb_error++; } // // ReLock the device // try { the_dev->relock(cl); } catch (Tango::DevFailed &e) { errors.length(nb_error + 1); errors[nb_error].desc = CORBA::string_dup(e.errors[0].desc.in()); errors[nb_error].reason = CORBA::string_dup(e.errors[0].reason.in()); errors[nb_error].origin = CORBA::string_dup(e.errors[0].origin.in()); errors[nb_error].severity = e.errors[0].severity; nb_error++; } } // // Throw the exception if we had one during the loop // if (nb_error != 0) { throw Tango::DevFailed(errors); } }