bool InterfaceBase::RemoveUserData(const std::string& key) const { // have to destroy the userdata pointer outside the lock, otherwise can get into a deadlock UserDataPtr olduserdata; { boost::unique_lock< boost::shared_mutex > lock(_mutexInterface); std::map<std::string, UserDataPtr>::iterator it = __mapUserData.find(key); if( it == __mapUserData.end() ) { return false; } olduserdata = it->second; __mapUserData.erase(it); } olduserdata.reset(); return true; }
void InterfaceBase::SetUserData(const std::string& key, UserDataPtr data) const { UserDataPtr olduserdata; { boost::unique_lock< boost::shared_mutex > lock(_mutexInterface); std::map<std::string, UserDataPtr>::iterator it = __mapUserData.find(key); if( it == __mapUserData.end() ) { __mapUserData[key] = data; } else { olduserdata = it->second; it->second = data; } } olduserdata.reset(); }
int main(int argc, char ** argv) { //int num = 1; string scenefilename = "data/lab1.env.xml"; string viewername = RaveGetDefaultViewerType(); //qtcoin // parse the command line options int i = 1; while(i < argc) { if((strcmp(argv[i], "-h") == 0)||(strcmp(argv[i], "-?") == 0)||(strcmp(argv[i], "/?") == 0)||(strcmp(argv[i], "--help") == 0)||(strcmp(argv[i], "-help") == 0)) { RAVELOG_INFO("orloadviewer [--num n] [--scene filename] viewername\n"); return 0; } else if( strcmp(argv[i], "--scene") == 0 ) { scenefilename = argv[i+1]; i += 2; } else break; } if( i < argc ) { viewername = argv[i++]; } RaveInitialize(true); // start openrave core EnvironmentBasePtr penv = RaveCreateEnvironment(); // create the main environment RaveSetDebugLevel(Level_Debug); boost::thread thviewer(boost::bind(SetViewer,penv,viewername)); penv->Load(scenefilename); // load the scene UserDataPtr pregistration; while(!pregistration) { if( !pregistration && !!penv->GetViewer() ) { pregistration = penv->GetViewer()->RegisterViewerThreadCallback(boost::bind(ViewerCallback,penv->GetViewer())); } boost::this_thread::sleep(boost::posix_time::milliseconds(1)); } thviewer.join(); // wait for the viewer thread to exit pregistration.reset(); penv->Destroy(); // destroy return 0; }