Exemplo n.º 1
0
/*=== BEGIN tests for class 'TmpFileBLOB' ===*/
void BLOBTest::testTmpFileBLOBCreate()
{
	ibrcommon::File tmppath("/tmp");
	ibrcommon::BLOB::changeProvider(new ibrcommon::FileBLOBProvider(tmppath), true);

	/* test signature () */
	ibrcommon::BLOB::Reference ref = ibrcommon::BLOB::create();
}
Exemplo n.º 2
0
int main(int argc, char** argv) {
  auto path = tmppath();
  std::cout << "Using temporary file: " << path << std::endl;

  // Basic set/get
  {
    c10d::FileStore store(path);
    c10d::test::set(store, "key0", "value0");
    c10d::test::set(store, "key1", "value1");
    c10d::test::set(store, "key2", "value2");
    c10d::test::check(store, "key0", "value0");
    c10d::test::check(store, "key1", "value1");
    c10d::test::check(store, "key2", "value2");
  }

  // Perform get on new instance
  {
    c10d::FileStore store(path);
    c10d::test::check(store, "key0", "value0");
  }

  // Hammer on FileStore#add
  std::vector<std::thread> threads;
  const auto numThreads = 4;
  const auto numIterations = 100;
  c10d::test::Semaphore sem1, sem2;
  for (auto i = 0; i < numThreads; i++) {
    threads.push_back(std::move(std::thread([&] {
      c10d::FileStore store(path);
      sem1.post();
      sem2.wait();
      for (auto j = 0; j < numIterations; j++) {
        store.add("counter", 1);
      }
    })));
  }
  sem1.wait(numThreads);
  sem2.post(numThreads);
  for (auto& thread : threads) {
    thread.join();
  }

  // Check that the counter has the expected value
  {
    c10d::FileStore store(path);
    std::string expected = std::to_string(numThreads * numIterations);
    c10d::test::check(store, "counter", expected);
  }

  unlink(path.c_str());
  std::cout << "Test succeeded" << std::endl;
  return 0;
}
Exemplo n.º 3
0
string
joinPaths(string const &path, string const &file) {
  string tmppath(path);
  if ((tmppath.length() > 0) && (tmppath[tmppath.length() - 1] == '/')) {
    tmppath = tmppath.substr(0, tmppath.length() - 1);
  }
  string tmpfile(file);
  while ((tmpfile.length() >= 3) && (tmpfile.substr(0, 3) == "../")) {
    tmppath = getDirectory(tmppath);
    tmpfile = tmpfile.substr(3);
  }
  
  return tmppath + "/" + tmpfile;
}
Exemplo n.º 4
0
bool
SourceFileRez::CheckNeedsBuild(BuildInfo &info, bool check_deps)
{
	if (!info.objectFolder.GetFullPath())
		return false;
	
	if (BString(GetPath().GetExtension()).ICompare("r") != 0)
		return false;
	
	if (BuildFlag() == BUILD_YES)
		return true;
	
	BString objname(GetPath().GetBaseName());
	objname << ".rsrc";
	
	DPath objpath(info.objectFolder);
	objpath.Append(objname);
	if (!BEntry(objpath.GetFullPath()).Exists())
		return true;
	
	BString tmpname(GetPath().GetBaseName());
	tmpname << ".r.txt";
	
	DPath tmppath(info.objectFolder);
	tmppath.Append(tmpname);
	if (!BEntry(tmppath.GetFullPath()).Exists())
		return true;
	
	
	struct stat objstat;
	if (stat(objpath.GetFullPath(),&objstat) != 0)
		return false;
	
	// Fix mod times set into the future
	time_t now = real_time_clock();
	if (GetModTime() > now)
	{
		BNode node(GetPath().GetFullPath());
		node.SetModificationTime(now);
	}
	
	if (GetModTime() > objstat.st_mtime)
		return true;
	
	return false;
}
Exemplo n.º 5
0
int main( int argc, char* argv[] )
{
    std::cout << "\nImporting PUT Data from Annotation Tool into SQLite3 DB " << std::endl;

    //----------------- program options

    po::positional_options_description pod;
    pod.add("sqldb-file",1);
    pod.add("imgdbname",1);
    pod.add("image-dir",1);
    pod.add("landmarks-dir",1);
    pod.add("regions-dir",1);
    pod.add("clear-sqldb",1);

    po::options_description description("Options");
    description.add_options()
    ("help", "produce help message")
    ("sqldb-file", po::value< string >(), "sql database file")
    ("imgdbname", po::value< string >(), "image database name")
    ("image-dir", po::value< string >(), "image file path (../Images/XXXX/xxxxxxxx.jpg)")
    ("landmarks-dir", po::value< string >(), "landmarks file path (../LXXX/xxxxxxxx.yml)")
    ("regions-dir", po::value< string >(), "regions file path (../RXXX/xxxxxxxx.yml)")
    ("clear-sqldb", po::value< string >(), "optinal: clear sql database (default: false)")
    ;

    po::variables_map variablesMap;

    try
    {
        po::store(po::command_line_parser(argc, argv).options(description).positional(pod).run(), variablesMap);
        po::notify(variablesMap);
    } catch ( const boost::program_options::error& e )
    {
        std::cerr << e.what() << std::endl;
    }

    bool showHelp = false;

    string sqlDBFile;
    if (variablesMap.count("sqldb-file"))
        sqlDBFile = variablesMap["sqldb-file"].as<string>();
    else
        showHelp = true;

    string imgDBName;
    if (variablesMap.count("imgdbname"))
        imgDBName = variablesMap["imgdbname"].as<string>();
    else
        showHelp = true;

    string imgDir;
    if (variablesMap.count("image-dir"))
        imgDir = variablesMap["image-dir"].as<string>();
    else
        showHelp = true;


    string landmarksDir;
    if (variablesMap.count("landmarks-dir"))
        landmarksDir = variablesMap["landmarks-dir"].as<string>();
    else
        showHelp = true;

    string regionsDir;
    if (variablesMap.count("regions-dir"))
        regionsDir = variablesMap["regions-dir"].as<string>();
    else
        showHelp = true;

    string clearSqlDB;
    if (variablesMap.count("clear-sqldb"))
        clearSqlDB = variablesMap["clear-sqldb"].as<string>();
    else
        clearSqlDB = "false";

    if (variablesMap.count("help") || showHelp)
    {
        cout << description << "\n";
        return 1;
    }

    std::string basePath = "";

    std::cout << "-------------------------------------------------------" << std::endl;
    std::cout << "  Config:" << std::endl;
    std::cout << "    SQL DB Name:     " << sqlDBFile << std::endl;
    std::cout << "    Image DB Name:   " << imgDBName << std::endl;
    std::cout << "    Image Folder:    " << imgDir << std::endl;
    std::cout << "    Landmarks Folder:" << landmarksDir << std::endl;
    std::cout << "    Regions Folder:  " << regionsDir << std::endl;
    std::cout << "    Optional:        clear SqlDB -> " << clearSqlDB << std::endl;
    std::cout << "    Base Path:       " << basePath << std::endl;
    std::cout << "-------------------------------------------------------" << std::endl;


    //------------------ DELETE db entries from sql database
    if (clearSqlDB.compare("true") == 0) {
        cout << " \nCLEAR Sql Database " << endl;
        DeleteSqlEntries dsde;
        dsde.deleteAllSqlEntries(sqlDBFile);
        return 0;
    } else {
        std::cout << " \nADD data to Sql Database" << std::endl;
        std::string::size_type pos = sqlDBFile.find_last_of("\\/");
        if (pos != std::string::npos) {
            basePath = sqlDBFile.substr(0,pos+1);
        }
    }


    //------------------ INSERT dbname INTO sql database
    DeleteSqlEntries dnsf;

    bool deleted = false;
    deleted = dnsf.deleteDBName(sqlDBFile, imgDBName);
    if (deleted == true) {
        dnsf.insertDBName(sqlDBFile, imgDBName);
    }

    // get all *jpg files from img file folder
    ImagesFromFolder iff;

    // PathVector paths = iff.getImagesFromFolder(imgDir + "\\0" + folderName, ".JPG");
    // paths.clear();

    PathVector pathImages = iff.getFilesFromFolderStruct(imgDir, ".JPG");
    iff.clearPathVector();
    PathVector pathLandmarks = iff.getFilesFromFolderStruct(landmarksDir, ".YML");
    iff.clearPathVector();

    if (pathImages.empty()) {
        std::cout << " PUTIMPORTER -> Warning: NO Files in Folderpath '" << imgDir << "' found! " << std::endl;
    } else if (pathLandmarks.empty()) {
        std::cout << " PUTIMPORTER -> Warning: NO Files in Folderpath '" << landmarksDir << "' found! " << std::endl;
    } else {
        // iff.printFoundFiles(paths);
        // iff.printFoundFiles(pathLandmarks);

        PutFileReader putFileReader;

        // first read all images
        for (unsigned int n = 0; n < pathImages.size(); ++n)
        {
            std::string imgFileName = pathImages.at(n).string();
            putFileReader.loadImage(imgFileName);
            std::cout << " Insert '" << imgFileName << "' into putFileReader structure. " << std::endl;
        }

        // second add landmarks to images (if no images available ignore landmark)
        for (unsigned int n = 0; n < pathLandmarks.size(); ++n)
        {
std:
            string landmarksFileName = pathLandmarks.at(n).string();
            putFileReader.loadLandmarks(landmarksFileName);
            std::cout << " Insert '" << landmarksFileName << "' into putFileReader structure. " << std::endl;
        }

        // insert all images into sql database
        std::map<int, PutFileData>::iterator putIt = putFileReader.m_putDataMap.begin();
        for (; putIt != putFileReader.m_putDataMap.end(); ++putIt)
        {
            //putFileReader.printPutData();

            // Draw landmarks to image.
            //putFileReader.drawLandmarks();

            //------------------ INSERT INTO sql db
            SQLiteDBConnection sqlConn;

            if (sqlConn.open(sqlDBFile))
            {
                //int annotTypeID_PUT= getAnnotTypeID(&sqlConn);

                // get the feature IDs from the database - matching the feature codes from the input file
                FeatureCoordTypes fct;
                fct.load(&sqlConn);
                //fct.debugPrint();

                vector<int> featIDs;
                for (int i = 0; i < PutFileData::numFeaturesFileFeatureCodes; ++i)
                {
                    string featCode = PutFileData::featuresFileFeatureCodes[i];
                    int featID = fct.getIDByCode(featCode);
                    if (featID < 0)
                        std::cout << "Error: No ID for feature '" << featCode << "'" << std::endl;
                    else {
                        featIDs.push_back(featID);
                    }
                }

                string insertFaceSqlStmtStr = "INSERT INTO Faces(file_id,db_id) VALUES (?1,?2)";
                SQLiteStmt *insertFaceSqlStmt = sqlConn.prepare(insertFaceSqlStmtStr);

                string insertFeatureCoordsSqlStmtStr = "INSERT INTO FeatureCoords(face_id,feature_id,x,y) VALUES (?1, ?2, ?3, ?4)";
                SQLiteStmt *insertFeatureCoordsSqlStmt = sqlConn.prepare(insertFeatureCoordsSqlStmtStr);

                string insertImageSqlStmtStr = "INSERT INTO FaceImages(db_id,file_id,filepath,bw,width,height) VALUES (?1, ?2, ?3, ?4, ?5, ?6)";
                SQLiteStmt *insertImageSqlStmt = sqlConn.prepare(insertImageSqlStmtStr);

                bool allOK = true;

                if (insertFaceSqlStmt && insertFeatureCoordsSqlStmt)
                {
                    sqlConn.exec("PRAGMA synchronous = OFF;");
                    sqlConn.exec("BEGIN TRANSACTION;");


                    vector<std::pair<double, double> >::iterator landmarksIt = putIt->second.landmarks.begin();
                    if (landmarksIt == putIt->second.landmarks.end()) {
                        std::cout << " NO Landmarks for Image:  " << putIt->second.imgFilename << " found." << std::endl;
                        allOK = false;
                    }

                    // extract fileName and filePath
                    std::string fileName = "";
                    std::string filePath = putIt->second.imgFilename;
                    std::string::size_type pos = filePath.find_last_of("\\");
                    if (pos != std::string::npos)
                    {
                        fileName = filePath.substr(pos+1);
                        pos = filePath.find("\\"); // find first space
                        while ( pos != string::npos )
                        {
                            filePath.replace( pos, 1, "/" );
                            pos = filePath.find( "\\", pos + 1 );
                        }
                    }

                    insertFaceSqlStmt->reset();
                    insertFaceSqlStmt->bind(1,fileName);
                    insertFaceSqlStmt->bind(2,imgDBName);
                    allOK = allOK && (sqlConn.step(insertFaceSqlStmt) == SQLITE_DONE);

                    // get database id of inserted face
                    int face_id = sqlConn.getLastInsertRowid();

                    // insert features
                    insertFeatureCoordsSqlStmt->bind(1,face_id);
                    for (unsigned int i = 0 ; landmarksIt != putIt->second.landmarks.end(); ++landmarksIt, ++i)
                    {
                        if ( (landmarksIt->first > 0) && (landmarksIt->second > 0) ) {
                            if (i >= featIDs.size()) {
                                break;
                            }
                            insertFeatureCoordsSqlStmt->bind(2,featIDs[i]);
                            insertFeatureCoordsSqlStmt->bind(3,static_cast<float>(landmarksIt->first));
                            insertFeatureCoordsSqlStmt->bind(4,static_cast<float>(landmarksIt->second));
                            allOK = allOK && (sqlConn.step(insertFeatureCoordsSqlStmt) == SQLITE_DONE);
                            if (!allOK) {
                                break;
                            }
                            insertFeatureCoordsSqlStmt->reset();
                        }
                    }

                    // insert image
                    std::string totalFileName = filePath;

                    fs::path tmppath(totalFileName);
                    totalFileName = tmppath.relative_path().string();

                    cv::Mat img = cv::imread(tmppath.string(),-1);
                    if (img.empty()) {
                        std::cout << "Error: Could not load Image: '" << totalFileName << "'" << std::endl;
                        allOK = false;
                    } else {

                        std::string relativeFilePath = "";
                        if (filePath.size() > imgDir.size()) {
                            relativeFilePath = filePath.substr(imgDir.size()+1);
                        }

                        //db_id,file_id,filepath,bw,width,height
                        insertImageSqlStmt->bind(1,imgDBName);
                        insertImageSqlStmt->bind(2,fileName);
                        insertImageSqlStmt->bind(3,relativeFilePath);
                        insertImageSqlStmt->bind(4,img.channels() == 1);
                        insertImageSqlStmt->bind(5,img.cols);
                        insertImageSqlStmt->bind(6,img.rows);

                        allOK = allOK && (sqlConn.step(insertImageSqlStmt) == SQLITE_DONE);
                        insertImageSqlStmt->reset();
                    }

                    if (allOK) {
                        sqlConn.exec("COMMIT;");
                        std::cout << "Reading ...   Inserting...    File: '" << putIt->second.filenumber <<
                                  "' into Database" << std::endl;
                    }
                    else {
                        sqlConn.exec("ROLLBACK TRANSACTION;");
                    }

                    sqlConn.exec("PRAGMA synchronous = NORMAL;");

                    sqlConn.finalize(insertFaceSqlStmt);
                    delete insertFaceSqlStmt;
                    sqlConn.finalize(insertFeatureCoordsSqlStmt);
                    delete insertFeatureCoordsSqlStmt;
                }
                sqlConn.close();

            } else {
                std::cout << "failed to open sql db file '" << sqlDBFile << "'" << std::endl;
            }
        }
    }
    std::cout << "done." << std::endl;
}
Exemplo n.º 6
0
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) 
{
    pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
    logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];

	gDebug = boost::shared_ptr<amxDebug>(new amxDebug());

	gDebug->Log("\tDebugging started\n");
	gDebug->Log("-----------------------------------------------------------------");
	gDebug->Log("Called plugin load | amx data: 0x%x | logprintf address: 0x%x", ppData[PLUGIN_DATA_AMX_EXPORTS], logprintf);
	gDebug->Log("-----------------------------------------------------------------\n");

	gCore = boost::shared_ptr<amxCore>(new amxCore());

	#if defined LINUX
	boost::filesystem::path tmppath("plugins/_addon_tmp.so");
	boost::filesystem::path libpath("plugins/addon.so");
	boost::filesystem::path curcfg("server.cfg");
	boost::filesystem::path tmpcfg("server.cfg.bak");
	#else
	boost::filesystem::path tmppath(".\\plugins\\_addon_tmp.dll");
	boost::filesystem::path libpath(".\\plugins\\addon.dll");
	boost::filesystem::path curcfg(".\\server.cfg");
	boost::filesystem::path tmpcfg(".\\server.cfg.bak");
	#endif

	if(boost::filesystem::exists(tmppath) && boost::filesystem::exists(tmpcfg))
	{
		try
		{
			boost::filesystem::remove(libpath);
			boost::filesystem::copy_file(tmppath, libpath);

			boost::filesystem::remove(curcfg);
			boost::filesystem::rename(tmpcfg, curcfg);
		}
		catch(boost::filesystem::filesystem_error& error)
		{
			logprintf("SAMP-Addon warning: When updating addon binary: %s", error.what());
		}

		logprintf("SAMP-Addon warning: Addon binary was updated. Start server again.");
		exit(EXIT_SUCCESS);
	}
	else if(boost::filesystem::exists(tmppath) && !boost::filesystem::exists(tmpcfg))
	{
		try
		{
			boost::filesystem::remove(tmppath);
		}
		catch(boost::filesystem::filesystem_error& error)
		{
			logprintf("SAMP-Addon warning: Cannot remove old addon binary, remove it manually (What: %s)", error.what());
		}

		logprintf("SAMP-Addon warning: old addon binary was removed");
	}

	logprintf(" SAMP-Addon was loaded");

    return true;
}
Exemplo n.º 7
0
 TemporaryFile() {
   path = tmppath();
 }