Ejemplo n.º 1
0
      bool CDatabase::load()
      {
         LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );

         mpMutex->lock();
         pugi::xml_document doc;
         // Get DOM structure from XML file
         LOG4CPLUS_INFO(msLogger, "DB path: " + mDBPath);
         LOG4CPLUS_INFO(msLogger, "DB directory path: " + mDirPath);
         std::string fullPath = mDirPath + mDBPath;
         pugi::xml_parse_result res = doc.load_file(fullPath.c_str());
         switch (res.status)
         {
         case pugi::status_ok:              // No error
            LOG4CPLUS_INFO(msLogger, "AppMan database parsed by xml-parser");
            break;
         case pugi::status_file_not_found:      // File was not found during load_file()
         case pugi::status_io_error:            // Error reading from file/stream
         case pugi::status_out_of_memory:       // Could not allocate memory
         case pugi::status_internal_error:      // Internal error occurred
            LOG4CPLUS_ERROR(msLogger, "AppMan database open error");
            mpMutex->unlock();
            return false;
            break;
         case pugi::status_unrecognized_tag:    // Parser could not determine tag type
         case pugi::status_bad_pi:              // Parsing error occurred while parsing document declaration/processing instruction
         case pugi::status_bad_comment:         // Parsing error occurred while parsing comment
         case pugi::status_bad_cdata:           // Parsing error occurred while parsing CDATA section
         case pugi::status_bad_doctype:         // Parsing error occurred while parsing document type declaration
         case pugi::status_bad_pcdata:          // Parsing error occurred while parsing PCDATA section
         case pugi::status_bad_start_element:   // Parsing error occurred while parsing start element tag
         case pugi::status_bad_attribute:       // Parsing error occurred while parsing element attribute
         case pugi::status_bad_end_element:     // Parsing error occurred while parsing end element tag
         case pugi::status_end_element_mismatch: // There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
            LOG4CPLUS_ERROR(msLogger, "AppMan database parsing error");
            mpMutex->unlock();
            return false;
            break;
         default:
            assert(0);
            break;
         }
         loadParsedDatabase(doc);
         saveWithNoLocks();
         mpMutex->unlock();
         return true;
      }
Ejemplo n.º 2
0
void ProfileDatabase::loadDatabase()
{
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    LOG4CPLUS_INFO(msLogger, "Folder path: " + mFolderPath +
            " DB name: " + mDbName);
    mProfiles.clear();
    pugi::xml_document doc;
    std::string path = mFolderPath + mDbName;
    pugi::xml_parse_result res = doc.load_file(path.c_str());
    switch (res.status)
    {
    case pugi::status_ok:              // No error
        mDbState = EDB_NORMAL_OK;
        break;
    case pugi::status_file_not_found:      // File was not found during load_file()
    case pugi::status_io_error:            // Error reading from file/stream
    case pugi::status_out_of_memory:       // Could not allocate memory
    case pugi::status_internal_error:      // Internal error occurred
        LOG4CPLUS_ERROR(msLogger, "Profile API Database open error");
        mDbState = EDB_OPEN_ERROR;
        break;
    case pugi::status_unrecognized_tag:    // Parser could not determine tag type
    case pugi::status_bad_pi:              // Parsing error occurred while parsing document declaration/processing instruction
    case pugi::status_bad_comment:         // Parsing error occurred while parsing comment
    case pugi::status_bad_cdata:           // Parsing error occurred while parsing CDATA section
    case pugi::status_bad_doctype:         // Parsing error occurred while parsing document type declaration
    case pugi::status_bad_pcdata:          // Parsing error occurred while parsing PCDATA section
    case pugi::status_bad_start_element:   // Parsing error occurred while parsing start element tag
    case pugi::status_bad_attribute:       // Parsing error occurred while parsing element attribute
    case pugi::status_bad_end_element:     // Parsing error occurred while parsing end element tag
    case pugi::status_end_element_mismatch: // There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
        LOG4CPLUS_ERROR(msLogger, "Profile Database parsing error");
        mDbState = EDB_PARSING_ERROR;
        break;
    default:
        assert(0);
        break;
    }
    loadParsedDatabase(doc);
}