void AGBusLine::setBusNames() { busNbr = 0; std::list<AGBus>::iterator it1 = buses.begin(); //iterator on buses in the first direction std::list<AGBus>::iterator it2 = revBuses.begin(); //iterator on buses in the second direction std::list<std::pair<int, std::string> > drivingBuses1, drivingBuses2; //buses on the road or in the parking of the corresponding end: int: the time of availability while (it1 != buses.end() && it2 != revBuses.end()) { if (it1->getDeparture() > it2->getDeparture()) { if (drivingBuses2.size() == 0) { drivingBuses2.push_front(make_pair(it2->getDeparture(), createName())); } else if (drivingBuses2.front().first > it2->getDeparture()) { drivingBuses2.push_front(make_pair(it2->getDeparture(), createName())); } //here the first in drivingBuses2 is available for the trip it2->setName(drivingBuses2.front().second); drivingBuses2.pop_front(); //the same bus will be available for the main direction after some time (see function getReady): drivingBuses1.push_back(make_pair(getReady(it2->getDeparture()), it2->getName())); it2++; } else { if (drivingBuses1.size() == 0) { drivingBuses1.push_front(make_pair(it1->getDeparture(), createName())); } else if (drivingBuses1.front().first > it1->getDeparture()) { drivingBuses1.push_front(make_pair(it1->getDeparture(), createName())); } //here the first in drivingBuses1 is available for the trip it1->setName(drivingBuses1.front().second); drivingBuses1.pop_front(); //the same bus will be available for the return way after some time (see function getReady): drivingBuses2.push_back(make_pair(getReady(it1->getDeparture()), it1->getName())); it1++; } } if (it1 != buses.end()) { if (drivingBuses1.size() == 0) { it1->setName(createName()); } else if (drivingBuses1.front().first > it1->getDeparture()) { it1->setName(createName()); } else { it1->setName(drivingBuses1.front().second); drivingBuses1.pop_front(); } it1++; } if (it2 != revBuses.end()) { if (drivingBuses2.size() == 0) { it2->setName(createName()); } else if (drivingBuses2.front().first > it2->getDeparture()) { it2->setName(createName()); } else { it2->setName(drivingBuses2.front().second); drivingBuses2.pop_front(); } it2++; } }
bool LLPluginSharedMemory::create(size_t size) { mName = SHM_OPEN_SHARED_MEMORY_PREFIX_STRING; mName += createName(); mSize = size; // Preemptive unlink, just in case something didn't get cleaned up. unlink(); mImpl->mSharedMemoryFD = ::shm_open(mName.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if(mImpl->mSharedMemoryFD == -1) { return false; } mNeedsDestroy = true; if(::ftruncate(mImpl->mSharedMemoryFD, mSize) == -1) { return false; } return map(); }
/** * Create a shared pointer to an algorithm object with the given name and version. If the algorithm is one registered with a clean pointer rather than * an instantiator then a clone is returned. * @param name :: Algorithm name * @param version :: Algorithm version * @returns A shared pointer to the algorithm object */ boost::shared_ptr<Algorithm> AlgorithmFactoryImpl::createAlgorithm(const std::string & name, const int version) const { try { return Kernel::DynamicFactory<Algorithm>::create(createName(name,version)); } catch(Mantid::Kernel::Exception::NotFoundError &) { } //See if we can make one from the clean cache const std::string fqlname(createName(name, version)); std::map<std::string, CloneableAlgorithm*>::const_iterator itr = m_cloneable_algs.find(fqlname); if( itr != m_cloneable_algs.end() ) { API::CloneableAlgorithm *cloned = itr->second->clone(); if( !cloned ) { throw std::runtime_error("Cloning algorithm failed, cannot create algorithm \"" + name + "\""); } return boost::shared_ptr<API::CloneableAlgorithm>(cloned, std::mem_fun(&CloneableAlgorithm::kill)); } else { throw Mantid::Kernel::Exception::NotFoundError("Unknown algorithm requested.", name); } }
void ProgramDataMenu::run() { int8_t index; do { index = runSimple(); if(index < 0) return; switch(index) { case 5: createName(); break; case 6: editName(); break; default: ProgramData undo(p_); if(!runEdit(index)) { p_ = undo; } else { Buzzer::soundSelect(); p_.check(); } break; } } while(true); }
void VRRegisterSceneGraph::createRegisterMessage(osg::Node *node, string parent) { if (node) { string nodeName = createName(node->getName()); // check for vr-prepare's EndOfTree indicator bool doNotFollow = (nodeName.find("_EOT") != string::npos) || (nodeName.find("-EOT") != string::npos); // append counting register id stringstream idString; idString << nodeName; idString << "_" << sceneGraphAppendixIdString << "_"; idString << registerId; node->setName(idString.str().c_str()); registerId++; //separate names with tabulators //separate node, class and parent with ;; string message = node->getName(); message.append(";;"); message.append(node->className()); message.append(";;"); message.append(parent); message.append("\t"); whole_message.append(message); osg::Group *group = dynamic_cast<osg::Group *>(node); if (group && !doNotFollow) // pfGroup, pfDCS { for (unsigned int i = 0; i < group->getNumChildren(); i++) { createRegisterMessage(group->getChild(i), node->getName()); } } } }
bool MMTT_SharedMem::open(const char *name, unsigned int size, bool supportInfo) { mySize = size; myMemory = 0; myMapping = 0; myName = 0; mySharedMemInfo = NULL; memset(myNamePostFix, 0, MMTT_SHM_MAX_POST_FIX_SIZE); myShortName = _strdup(name); mySupportInfo = supportInfo; size_t len = strlen(myShortName); createName(); char *m = new char[strlen(myName) + 5 + 1]; strcpy(m, myName); strcat(m, "Mutex"); myMutex = new MMTT_Mutex(m); delete m; if (size > 0) myAmOwner = true; else myAmOwner = false; if (supportInfo) { if (!createInfo()) { return false; } } else { mySharedMemInfo = NULL; } if (size > 0) { if (!createSharedMem()) { myErrorState = MMTT_SHM_ERR_ALREADY_EXIST; return false; } } else { if (!openSharedMem()) { myErrorState = MMTT_SHM_ERR_DOESNT_EXIST; return false; } } myErrorState = MMTT_SHM_ERR_NONE; return true; }
bool LLPluginSharedMemory::create(size_t size) { mName = APR_SHARED_MEMORY_PREFIX_STRING; mName += createName(); mSize = size; apr_status_t status = apr_shm_create( &(mImpl->mAprSharedMemory), mSize, mName.c_str(), gAPRPoolp ); if(ll_apr_warn_status(status)) { return false; } mNeedsDestroy = true; return map(); }
/** * Store a pointer to an Algorithm object that is cloneable, e.g. a Python algorithm * @param algorithm :: A pointer to a clonable algorithm object */ bool AlgorithmFactoryImpl::storeCloneableAlgorithm(CloneableAlgorithm* algorithm) { const std::string alg_name = algorithm->name(); if( alg_name.empty() ) { throw std::runtime_error("Cannot register algorithm with empty name."); } const int alg_version(algorithm->version()); //Check if we already have an algorithm of this name and version within the factory std::map<std::string, int>::const_iterator itr = m_vmap.find(alg_name); if( itr != m_vmap.end() ) { int registered_version = itr->second; if( alg_version > registered_version ) { m_vmap[alg_name] = alg_version; } } else { m_vmap[alg_name] = alg_version; } // Finally check that the algorithm can be initialized without throwing try { algorithm->clone()->initialize(); } catch( std::runtime_error & e ) { g_log.error(e.what()); return false; } catch( ... ) { return false; } //Insert into map, overwriting if necessary m_cloneable_algs[createName(alg_name, alg_version)] = algorithm; //Notify whomever is interested that the factory has been updated notificationCenter.postNotification(new AlgorithmFactoryUpdateNotification); return true; }
QT_BEGIN_NAMESPACE_PROCESSMANAGER /*! \class QProcessBackend \brief The QProcessBackend class is a generalized representation of a process. \inmodule QtProcessManager The QProcessBackend class encapsulates a process whose lifecycle is controlled by the process manager. It is a generalized representation - in actuality, subclasses of the QProcessBackend class are used to control processes. These subclasses are used to accelerate process launching, wrap processes with additional arguments and settings, or fake the existence of a process. The QProcessBackend class itself cannot be instantiated. A QProcessBackend object always contains a QProcessInfo object, which is the static information used to start and execute the process. Because QProcessBackends represent actual or fake processes, they can only modify a few of the process properties. Currently the QProcessBackend can only modify the process priority (or niceness) and the oomAdjustment score (for Linux systems). All other process properties (such as UID, GID, program name) can be considered fixed. Furthermore, please note that setting these dynamic values can take time - for example, they may require some intra-application communication. For example, if the process manager has delegated starting applications to some kind of pipe process, then the process manager itself may not be running with sufficient permissions to change the priority or oomAdjustment value to the desired setting. In this case, the process manager must request that the pipe process make the changes, which will result in some time delay before the changes are real. In this case, the actualPriority() and desiredPriority() functions will return different values until the IPC has completed. */ /*! \internal Constructs a QProcessBackend instance with QProcessInfo \a info and optional \a parent */ QProcessBackend::QProcessBackend(const QProcessInfo &info, QObject *parent) : QObject(parent) , m_info(info) , m_echo(QProcessBackend::EchoStdoutStderr) { static int backend_count = 0; m_id = ++backend_count; createName(); }
bool MMTT_SharedMem::openSharedMem() { if (myMapping) return true; createName(); #ifdef WIN32 myMapping = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, s2ws(myName).c_str()); #else assert(false); #endif if (!myMapping) return false; return true; }
bool FlushEngine::prune() { std::set<IFlushHandler::SP> toPrune; { std::lock_guard<std::mutex> guard(_lock); if (_pendingPrune.empty()) { return false; } _pendingPrune.swap(toPrune); } for (const auto &handler : toPrune) { IFlushTarget::List lst = handler->getFlushTargets(); auto oldestFlushed = findOldestFlushedTarget(lst, *handler); if (LOG_WOULD_LOG(event)) { EventLogger::flushPrune(createName(*handler, oldestFlushed.second), oldestFlushed.first); } handler->flushDone(oldestFlushed.first); } return true; }
bool LLPluginSharedMemory::create(size_t size) { mName = WIN32_SHARED_MEMORY_PREFIX_STRING; mName += createName(); mSize = size; mImpl->mMapFile = CreateFileMappingA( INVALID_HANDLE_VALUE, // use paging file NULL, // default security PAGE_READWRITE, // read/write access 0, // max. object size mSize, // buffer size mName.c_str()); // name of mapping object if(mImpl->mMapFile == NULL) { LL_WARNS("Plugin") << "CreateFileMapping failed: " << GetLastError() << LL_ENDL; return false; } mNeedsDestroy = true; return map(); }
void MMTT_SharedMem::resize(unsigned int s) { // This can't be called by someone that didn't create it in the first place // Also you can't resize it if you arn't using the info feature // Finally, don't set the size to 0, just delete this object if you want to clean it if (mySize > 0 && mySharedMemInfo && myAmOwner) { mySharedMemInfo->lock(); MMTT_SharedMemInfo *info = (MMTT_SharedMemInfo*)mySharedMemInfo->getMemory(); if (info && info->supported) { detachInternal(); mySize = s; // Keep trying until we find a name that works do { randomizePostFix(); createName(); } while(!createSharedMem()); memcpy(info->namePostFix, myNamePostFix, MMTT_SHM_MAX_POST_FIX_SIZE); } else // Otherwise, just try and detach and resize, if it fails give up { detachInternal(); mySize = s; if (!createSharedMem()) { myErrorState = MMTT_SHM_ERR_ALREADY_EXIST; } } mySharedMemInfo->unlock(); } }
/** Creates an instance of an algorithm * @param name :: the name of the Algrorithm to create * @param version :: the version of the algroithm to create * @returns a shared pointer to the created algorithm */ boost::shared_ptr<Algorithm> AlgorithmFactoryImpl::create(const std::string& name,const int& version) const { int local_version=version; if( version < 0) { if(version == -1)//get latest version since not supplied { VersionMap::const_iterator it = m_vmap.find(name); if (!name.empty()) { if(it == m_vmap.end() ) throw std::runtime_error("Algorithm not registered "+ name ); else local_version = it->second; } else throw std::runtime_error("Algorithm not registered (empty algorithm name)"); } } try { return this->createAlgorithm(name, local_version); } catch(Kernel::Exception::NotFoundError&) { VersionMap::const_iterator it = m_vmap.find(name); if(it == m_vmap.end() ) throw std::runtime_error("algorithm not registered "+ name ); else { g_log.error()<< "algorithm "<< name<< " version " << version << " is not registered "<<std::endl; g_log.error()<< "the latest registered version is " << it->second<<std::endl; throw std::runtime_error("algorithm not registered "+ createName(name,local_version) ); } } }
/** * Create a shared pointer to an algorithm object with the given name and * version. If the algorithm is one registered with a clean pointer rather than * an instantiator then a clone is returned. * @param name :: Algorithm name * @param version :: Algorithm version * @returns A shared pointer to the algorithm object */ boost::shared_ptr<Algorithm> AlgorithmFactoryImpl::createAlgorithm(const std::string &name, const int version) const { return Kernel::DynamicFactory<Algorithm>::create(createName(name, version)); }
bool create(const QString &dir, CFontEngine &fe) { bool root(Misc::root()), added = false; QString fmapDir(Misc::dirSyntax(root ? KFI_ROOT_CFG_DIR : dir)); CFile old(fmapDir); QStringList entries; int i; FcPattern *pat = FcPatternCreate(); FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_SCALABLE, (void *)0); FcFontSet *fs = FcFontList(0, pat, os); FcPatternDestroy(pat); FcObjectSetDestroy(os); for(i = 0; i < fs->nfont; i++) { QString fName(Misc::fileSyntax(CFcEngine::getFcString(fs->fonts[i], FC_FILE))); FcBool scalable = FcFalse; if(!fName.isEmpty() && (root || dir.isEmpty() || 0 == fName.find(dir)) && FcResultMatch == FcPatternGetBool(fs->fonts[i], FC_SCALABLE, 0, &scalable) && scalable) { const QStringList *existing = old.getEntries(fName); if(existing && existing->count()) entries += (*existing); else { int face = 0, numFaces = 0; do { if(fe.openFont(fName, face)) { if(fe.hasPsInfo()) { if(0 == numFaces) numFaces = fe.getNumFaces(); // Only really for TTC files... // // Add real addEntry(entries, fe.getPsName(), fName, fmapDir); added = true; // // Add fake entries for X11 generated names switch(fe.getWeight()) { case CFontEngine::WEIGHT_MEDIUM: case CFontEngine::WEIGHT_REGULAR: { QString x11Ps(createX11PsName(fe.getFamilyName())); if(CFontEngine::ITALIC_ITALIC != fe.getItalic() && CFontEngine::ITALIC_OBLIQUE != fe.getItalic()) addAliasEntry(entries, createName(x11Ps, "Roman", getItalicStr(fe.getItalic())), fe.getPsName()); addAliasEntry(entries, createName(x11Ps, NULL, getItalicStr(fe.getItalic())), fe.getPsName()); break; } case CFontEngine::WEIGHT_UNKNOWN: break; default: addAliasEntry(entries, createName(createX11PsName(fe.getFamilyName()), CFontEngine::weightStr(fe.getWeight()), getItalicStr(fe.getItalic())), fe.getPsName()); } } fe.closeFont(); } } while(++face < numFaces); } } } bool status = true; if(added || entries.count() != old.getLineCount()) { KSaveFile out(fmapDir + FONTMAP); QTextStream *stream = out.textStream(); if(stream) { QStringList::Iterator it; for(it = entries.begin(); it != entries.end(); ++it) *stream << *it << endl; } else status = false; } // // Ensure GS's main Fontmap references our file... if(root && status) { static const char *constGhostscriptDirs[] = {"/usr/share/ghostscript/", "/usr/local/share/ghostscript/", "/usr/share/gs-esp/", NULL}; QString gsFile = locateFile(FONTMAP, constGhostscriptDirs); if(!gsFile.isEmpty()) { const int constMaxLineLen = 1024; const char *constRLF = ".runlibfile"; char line[constMaxLineLen]; ifstream in(QFile::encodeName(gsFile)); if(in) { QCString fmap(QFile::encodeName(fmapDir + FONTMAP)); int lineNum = 0, kfiLine = -1, gsLine = -1, ncLine = -1; do { in.getline(line, constMaxLineLen); if(in.good()) { line[constMaxLineLen - 1] = '\0'; if(strstr(line, fmap.data()) != NULL && strstr(line, constRLF) != NULL) kfiLine = lineNum; else if(strstr(line, FONTMAP ".GS") != NULL && strstr(line, constRLF) != NULL) gsLine = lineNum; if(-1 == ncLine && '%' != line[0]) ncLine = lineNum; lineNum++; } } while(!in.eof() && (-1 == kfiLine || -1 == gsLine)); // // If the file doesn't already say to use our Fontmap file, then tell it to! // Also, ensure ours is .runlibfile'd before the main GS one - else problems can occur if(-1 == kfiLine || kfiLine > gsLine) { in.clear(); in.seekg(0, ios::end); int size = (streamoff)in.tellg(); in.seekg(0, ios::beg); char *buffer = new char[size + strlen(fmap) + strlen(constRLF) + 5]; if(buffer) { bool added = false; buffer[0] = '\0'; lineNum = 0; do { in.getline(line, constMaxLineLen); if(in.good()) { line[constMaxLineLen - 1] = '\0'; if(lineNum >= ncLine && !added) { strcat(buffer, "("); strcat(buffer, fmap); strcat(buffer, ") "); strcat(buffer, constRLF); strcat(buffer, "\n"); added = true; } if(lineNum != kfiLine) { strcat(buffer, line); strcat(buffer, "\n"); } lineNum++; } } while(!in.eof()); in.close(); if(added) // Don't re-write GS's Fontmap unless we've actually added something... { KSaveFile out(gsFile); QTextStream *stream = out.textStream(); if(stream) *stream << buffer; } delete[] buffer; } } } } } return status; }