Beispiel #1
0
void UserNSConfig::assertMapCorrect(const IDMap &map, const std::string &ID,
                                    unsigned contID, unsigned hostID, unsigned num) const
{
    if (map.size() >= 5) {
        const std::string msg = "Max number of 5 " + ID + " mappings has been already reached";
        LOGE(msg);
        throw ConfigureException(msg);
    }

    uid_t max = (uid_t)-1;
    if ((contID > (max - num)) || (hostID > (max - num))) {
        const std::string msg = "Given " + ID + " range exceeds maximum allowed values";
        LOGE(msg);
        throw ConfigureException(msg);
    }

    if (map.size()) {
        for (auto &it : map) {
            unsigned size = std::get<2>(it);
            uid_t contMin = std::get<0>(it);
            uid_t contMax = contMin + size - 1;
            uid_t hostMin = std::get<1>(it);
            uid_t hostMax = hostMin + size - 1;

            if ((contMin <= contID && contID <= contMax) ||
                (hostMin <= hostID && hostID <= hostMax)) {
                const std::string msg = "Given " + ID + " range overlaps with already configured mappings";
                LOGE(msg);
                throw ConfigureException(msg);
            }
        }
    }
}
Beispiel #2
0
unsigned UserNSConfig::convContToHostID(const IDMap &map, const std::string &ID,
                                        unsigned contID) const
{
    if (map.empty()) {
        return contID;
    }

    auto it = std::find_if(map.begin(), map.end(),
        [contID](const std::tuple<unsigned, unsigned, unsigned>& entry) {
            unsigned size = std::get<2>(entry);
            uid_t contMin = std::get<0>(entry);
            uid_t contMax = contMin + size - 1;

            if (contMin <= contID && contID <= contMax) {
                return true;
            }

            return false;
        }
    );

    if (it == map.end()) {
        const std::string msg = "The " + ID + ": " + std::to_string(contID) + " is not mapped in the container";
        LOGE(msg);
        throw ConfigureException(msg);
    }

    unsigned diff = contID - std::get<0>(*it);
    unsigned hostID = std::get<1>(*it) + diff;

    return hostID;
}
Beispiel #3
0
/// Returns an annotation document by given path.
AnnotationDocumentPtr AnnotationAgent::getDocument( const QString & doc_path )
{
    DocumentIter idx = docs_.find( doc_path );
    if (idx != docs_.end())
    {
        return idx.value();
    }

    // create a new document
    AnnotationDocumentPtr doc( new AnnotationDocument() );
    if ( !doc->open( doc_path ) )
    {
        return AnnotationDocumentPtr();
    }

    // put new document instance into list
    docs_[doc_path] = doc;

    // get the list of pages id and initialize all of the page instances
    shared_ptr<AnnotationIO> io = AnnotationIO::getIO( doc_path, false );
    if (io.get())
    {
        IDMap ids;
        io->loadPagesID( ids );
        IDMapIter iter = ids.begin();
        for (; iter != ids.end(); iter++)
        {
            AnnotationPagePtr page = doc->getPage( iter.value() );
            page->setGlobalID( iter.key() );
            // qDebug("Load Annotation Page:%d, Global ID:%d", iter.value(), iter.key());
        }
    }
    return doc;
}