Exemplo n.º 1
0
 bool CProfileDatabase::saveChanges()
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    pugi::xml_document doc;
    pugi::xml_node profiles = doc.append_child("profiles");
    mpDbMutex->lock();
    for (std::map<UID,CProfileInfo>::const_iterator it = mProfiles.begin(); it != mProfiles.end(); ++it)
    {
       pugi::xml_node profile = profiles.append_child("profile");
       pugi::xml_node maniPath = profile.append_child("manifest-path");
       maniPath.append_child(pugi::node_pcdata).set_value(it->second.xmlPath().c_str());
       pugi::xml_node libsNode = profile.append_child("libs");
       for (std::map<std::string,std::string>::const_iterator sit = it->second.libs().begin(); sit != it->second.libs().end(); ++sit)
       {
          pugi::xml_node libNode = libsNode.append_child("lib");
          libNode.append_attribute("platform").set_value(sit->first.c_str());
          libNode.append_attribute("path").set_value(sit->second.c_str());
       }
    }
    bool result = doc.save_file(mDBPath.c_str());
    mpDbMutex->unlock();
    if (result)
    {
       mDBState = EDB_SAVE_ERROR;
    }
    printDB();
    return result;
 }
Exemplo n.º 2
0
void getRecord(struct DB *db, char *buf, char *print_buf, int sd_current)
{
    if(!strcmp(buf, "lname"))
    {
        printDB(db->lname_db, print_buf, sd_current);
    }
    else if(!strcmp(buf, "fname"))
    {
        printDB(db->fname_db, print_buf, sd_current);
    }
    else if(!strcmp(buf, "SID"))
    {
        printDB(db->sid_db, print_buf, sd_current);
    }
    else if(!strcmp(buf, "GPA"))
    {
        printDB(db->gpa_db, print_buf, sd_current);
    }
}
Exemplo n.º 3
0
 CProfileDatabase::CProfileDatabase(std::string dbPath)
    : mDBPath(dbPath)
    , mDBState(EDB_NORMAL_OK)
    , mpDbMutex(new CMutex)
    , mpRequestMutex(new CMutex)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    loadDatabase();
    printDB();
 }
Exemplo n.º 4
0
ProfileDatabase::ProfileDatabase(const std::string & rootFolderPath, const std::string & relativeFolderPath, const std::string & dbName)
    : mFolderPath(rootFolderPath + relativeFolderPath)
    , mDbName(dbName)
    , mRootFolderPath(rootFolderPath)
    , mDbState(EDB_NORMAL_OK)
{
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    loadDatabase();
    printDB();
}
Exemplo n.º 5
0
void CDBManager::start(){
    for(unsigned int i = 0; i<sizeof(m_httpMap)/sizeof(m_httpMap[0]);i++){
        string fileName = CConfig::getInstance("")->m_rootPath;
        if(i==I_IPV4_MAP){
            fileName.append("/db/2_ipv4.txt");
        }else if (i==I_DOMAIN_MAP){
            fileName.append("/db/2_domain.txt");
        }else if (i==I_HOSTNAME_MAP){
            fileName.append("/db/2_hostname.txt");
        }

        int num = 0;
        
        ifstream ifs;
        string line;
        ifs.open(fileName, ifstream::in);
        while (getline(ifs, line)) {
            if (line.size()==0||line[0]==' '||line[0]=='\t'){
                continue;
            }
            vector<string> result;
            split(line, "\t", result);
            if (result.size()<2){
                Debug(LOG_LEVEL_ERR, "db error:" << line);
            }
            m_httpMap[i][result[0]] = result[1];
            if((CConfig::getInstance("")->m_maxDb) &&
               (++num > CConfig::getInstance("")->m_maxDb)){
                break;
            }
        }
        ifs.close();
    } 
    printDB();

    DbMap::iterator it;
    struct in_addr addr;
    for(it=m_httpMap[I_IPV4_MAP].begin();
        it!=m_httpMap[I_IPV4_MAP].end();
        ++it){
        inet_aton(it->first.c_str(), &addr);
        m_ip4Map[addr.s_addr] = it->second;
    }
    
    
}
Exemplo n.º 6
0
/*
 * main()
 */
int main(int argc, char** argv) {
    pthread_t threads[NUM_THREADS]; // Create a new array of threads
    int i = 0; // Loop counter
    void *status; // Set a pointer to status
    int rc; // Used for error checking
    int j; // Loop counter
    pthread_mutex_t *lock = malloc(sizeof(pthread_mutex_t)); // Allocate the memory needed
    
    struct phone_record person = { // Create a person from phone record
        9286008799, // Phone number
        "Moody" // Name of person
    };
    
    struct Phone_Entries phone_entry = { // Create a phone entry
        &person, // Put our person in it
        lock // LOCK IT!
    };
    
    if (pthread_mutex_init(lock, NULL) != 0) { // Check if mutex initalized correctly
        printf("\nMutex failed to initialize\n"); // Oh no! We failed to initialize correctly
        return 1; // Return 1
    }
    
    while (i < NUM_THREADS) { // Iterate over the number of threads
        printf("\nCreating threads in main %d\n", i); // Let the user know what we are doing
        rc = pthread_create(&threads[i], NULL, data_access, (void *)&phone_entry); // Creat the threads!
        if (rc) { // Check if it really worked
            printf("Error, return code is %d\n", rc); // Oh no! We failed to create threads...
        }
        i++; // Increment the loop counter
    }
    
    for (j = 0; j < NUM_THREADS; j++) { // Loop to join the threads together
        pthread_join(threads[j], &status); // YES! Status has worked and we have created a thread
    }
    
    add_record(&person); // Add the person one last time
    printDB(); // Print the results
    return 0; // Return 0! Success!
}
Exemplo n.º 7
0
int main(int argc, char* argv[]) {
	bInitMimeHandling();
	printDB();
	printf("%s\n", pszGetMimeType(argv[1]));
	return 0;
}