예제 #1
0
bool File::unlink ( ) {
	// safety catch!
	if ( g_conf.m_readOnlyMode )
		return logf(LOG_DEBUG,"disk: Trying to unlink "
			    "while in read only mode.");
	// give the fd back to the pull, free the m_vfd
	close ();
	// avoid unneccessary unlinking
	long status = doesExist();
	// return true if we don't exist anyway
	if ( status == 0 ) return true;
	// return false and set g_errno on error
	if ( status  < 0 ) return false;
	// log it so we can see what happened to timedb!
	log("disk: unlinking %s", m_filename );
	// remove ourselves from the disk
	if ( ::unlink ( m_filename ) == 0 ) return true;
	// sync it to disk in case power goes out
	sync();
	// copy errno to g_errno
	g_errno = errno;
	// return false and set g_errno on error
	return log("disk: unlink(%s) : %s" , m_filename,strerror(g_errno));
}
예제 #2
0
    ResourceManager::ResourceManager(const std::string &path)
    {
        mDefaultBody = 0;
        mDefaultFemale = 0;
        mDefaultHair = 0;
        mDefaultChest = 0;
        mDefaultLegs = 0;
        mDefaultFeet = 0;
        mBodyWidth = 0;
        mBodyHeight = 0;
        mNumParts = 5; // TODO: Calculate based on body.cfg
        std::string datapath = "";
        std::string error;
        std::string dirName;

        // physfs code
        PHYSFS_init(path.c_str());

        // add paths
        // writable first, since thats where updates will go to
#if defined __unix__
        mWriteDataPath = PHYSFS_getUserDir();
#elif defined __APPLE__
		mWriteDataPath = PHYSFS_getUserDir();
		mWriteDataPath.append("Library/Application Support/");
#elif defined _WIN32
        TCHAR writePath[MAX_PATH+1];
        SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, writePath);
		int length = _tcslen(writePath);
        mWriteDataPath.assign(&writePath[0], &writePath[length]);
#endif

#ifndef __unix__
        dirName = "townslife";
#else
        dirName = ".townslife";
#endif
        PHYSFS_setWriteDir(mWriteDataPath.c_str());

        if (!doesExist(dirName))
        {
			if (PHYSFS_mkdir(dirName.c_str()) == 0)
			{
			    error = PHYSFS_getLastError();
			}
        }
        mWriteDataPath.append("/" + dirName);
        PHYSFS_setWriteDir(mWriteDataPath.c_str());
        mWriteDataPath.append("/");
        addPath(mWriteDataPath);

        // now add cfg and /data directory
#if defined __unix__
        datapath = PHYSFS_getBaseDir();
        addPath(datapath);
        addPath(datapath + "data/");
#elif defined __APPLE__
        CFBundleRef mainBundle = CFBundleGetMainBundle();
		CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
		char resPath[PATH_MAX];
		CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)resPath, PATH_MAX);
		CFRelease(resourcesURL);
		addPath(resPath);
#elif defined _WIN32
        TCHAR exePath[MAX_PATH+1];
        GetModuleFileName(0, exePath, MAX_PATH);
		length = _tcslen(exePath);
        datapath.append(&exePath[0], &exePath[length]);
        datapath = datapath.substr(0, datapath.find_last_of("\\") + 1);
        addPath(datapath);
        addPath(datapath + "data\\");
#endif
    }
예제 #3
0
/*
 * Check if there's any conflict among src and dest, checks duplicate in names, servers, ports and directories.
 *
 * The rules are:
 *
 * 1) Each node (gtm, gtm_proxy, coordinator, datanode) must have unique name.
 *
 * 2) A port, in a given host, must be owned (listed to) only by single node.
 *
 * 3) A directory, in a given host, must be owned (used) only by single node.
 */
static void checkResourceConflict(char *srcNames, char *srcServers, char *srcPorts, char *srcPoolers, char *srcDirs,
								  char *destNames, char *destServers, char *destPorts, char *destPoolers, char *destDirs, 
								  int destOnly, int checkName)
{
	int ii, jj;

	if (!srcNames || !find_var(srcNames))
	{
		/* No source specified */
		return;
	}
	if (!destOnly)
	{
		/* Check conflict among the source first */
		for (ii = 0; aval(srcNames)[ii]; ii++)
		{
			if (is_none(aval(srcNames)[ii]))
				continue;
			/* Pooler and the port in the same name */
			if (srcPoolers && (atoi(aval(srcPorts)[ii]) == atoi(aval(srcPoolers)[ii])))
			{
				if (atoi(aval(srcPorts)[ii]) > 0)
				{
					anyConfigErrors = TRUE;
					elog(ERROR, "ERROR: Conflict in between port and pooler within %s variable.\n", srcNames);
				}
			}
			if (checkName && srcNames && !doesExist(srcNames, ii))
				assign_arrayEl(srcNames, ii, "none", NULL);
			if (srcServers && !doesExist(srcServers, ii))
				assign_arrayEl(srcServers, ii, "none", NULL);
			if (srcPoolers && !doesExist(srcPoolers, ii))
				assign_arrayEl(srcPoolers, ii, "-1", "-1");
			if (srcPorts && !doesExist(srcPorts, ii))
				assign_arrayEl(srcPorts, ii, "-1", "-1");
			if (srcDirs && !doesExist(srcDirs, ii))
				assign_arrayEl(srcDirs, ii, "none", NULL);
			for (jj = ii+1; aval(srcNames)[jj]; jj++)
			{
				/* Name conflict */
				if (checkName && srcNames && !doesExist(srcNames, jj))
					assign_arrayEl(srcNames, jj, "none", NULL);
				if (checkName && srcNames && (strcmp(aval(srcNames)[ii], aval(srcNames)[jj]) == 0))
				{
					anyConfigErrors = TRUE;
					elog(ERROR, "ERROR: Conflict in resource name within %s variable.\n", srcNames);
				}
				if (srcServers && is_none(aval(srcServers)[ii]))
					continue;
				if (srcServers && !doesExist(srcServers, jj))
					assign_arrayEl(srcServers, jj, "none", NULL);
				if (srcServers && strcmp(aval(srcServers)[ii], aval(srcServers)[jj]) == 0)
				{
					/* Ports and Poolers */
					if (srcPorts && !doesExist(srcPorts, jj))
						assign_arrayEl(srcPorts, jj, "-1", "-1");
					if (srcPoolers && !doesExist(srcPoolers, jj))
						assign_arrayEl(srcPoolers, jj, "-1", "-1");
					if((srcPorts && (atoi(aval(srcPorts)[ii]) > 0) && (atoi(aval(srcPorts)[ii]) == atoi(aval(srcPorts)[jj]))) ||
					   (srcPorts && srcPoolers && (atoi(aval(srcPorts)[ii]) > 0) && (atoi(aval(srcPorts)[ii]) == atoi(aval(srcPoolers)[jj]))) ||
					   (srcPoolers && (atoi(aval(srcPoolers)[ii]) > 0) && (atoi(aval(srcPoolers)[ii]) == atoi(aval(srcPoolers)[jj]))))
					{
						anyConfigErrors = TRUE;
						elog(ERROR, "ERROR: Conflict in port and pooler numbers within  %s variable.\n", srcNames);
					}
					/* Directories */
					if (srcDirs && !doesExist(srcDirs, jj))
						assign_arrayEl(srcDirs, jj, "none", NULL);
					if (srcDirs && strcmp(aval(srcDirs)[ii], aval(srcDirs)[jj]) == 0)
					{
						if (!is_none(aval(srcDirs)[ii]))
						{
							anyConfigErrors = TRUE;
							elog(ERROR, "ERROR: Conflict in directories within  %s variable.\n", srcNames);
						}
					}
				}
			}
		}
	}
	/* Check between src and destination */
	if (destNames)
	{
		for (ii = 0; aval(srcNames)[ii]; ii++)
		{
			if (is_none(aval(srcNames)[ii]))
				continue;
			for (jj = 0; aval(destNames)[jj]; jj++)
			{
				/* Resource names */
				if (checkName && (strcmp(aval(srcNames)[ii], aval(destNames)[jj]) == 0))
				{
					anyConfigErrors = TRUE;
					elog(ERROR, "ERROR: Conflict in names between  %s and %s variable.\n", srcNames, destNames);
				}
				if (destServers && !doesExist(destServers, jj))
					assign_arrayEl(destServers, jj, "none", NULL);
				if (srcServers && destServers && (strcmp(aval(srcServers)[ii], aval(destServers)[jj]) == 0) && !is_none(aval(srcServers)[ii]))
				{
					/* Ports and poolers */
					if (destPorts && !doesExist(destPorts, jj))
						assign_arrayEl(destPorts, jj, "-1", "-1");
					if (destPoolers && !doesExist(destPoolers, jj))
						assign_arrayEl(destPoolers, jj, "-1", "-1");
					if ((srcPorts && destPorts && (atoi(aval(srcPorts)[ii]) == atoi(aval(destPorts)[jj])) && (atoi(aval(srcPorts)[ii]) > 0)) ||
						(destPoolers && srcPorts && (destPoolers && (atoi(aval(srcPorts)[ii]) == atoi(aval(destPoolers)[jj]))) && (atoi(aval(srcPorts)[ii]) > 0))  ||
						(srcPoolers && destPorts && (atoi(aval(srcPoolers)[ii]) == atoi(aval(destPorts)[jj])) && (atoi(aval(srcPoolers)[ii]) > 0)) ||
						(srcPoolers && destPoolers && (atoi(aval(srcPoolers)[ii]) == atoi(aval(destPoolers)[jj])) && (atoi(aval(srcPoolers)[ii]) > 0)))
					{
						anyConfigErrors = TRUE;
						elog(ERROR, "ERROR: Conflict in port/pooler in %s and %s variable.\n", srcNames, destNames);
					}
					/* Dir Names */
					if (srcDirs && destDirs && !is_none(aval(srcDirs)[ii]) && (strcmp(aval(srcDirs)[ii], aval(destDirs)[jj]) == 0))
					{
						anyConfigErrors = TRUE;
						elog(ERROR, "ERROR: Conflict in directory names in %s and %s variable.\n", srcNames, destNames);
					}
				}
			}
		}
	}
}
예제 #4
0
int createHTKData(const string& lipiRootPath,const string& featureFilePath,const string& tempDir,int& outNumFeatures)
{

	string htkFeatFilesDestDir;
	string strNumFeatures;
	string statisticsFilePath;
	string cmdLine;

	string htkInstallationDir;

	#ifdef WIN32

		htkInstallationDir = lipiRootPath + SEPARATOR + "externaltools" + SEPARATOR + "htk" + SEPARATOR + "windows";
	#else
		htkInstallationDir = lipiRootPath + SEPARATOR + "externaltools" + SEPARATOR + "htk" + SEPARATOR + "linux";
	#endif
	
	
	string htkConfigFilePath = htkInstallationDir+string(SEPARATOR)+"config";

	ifstream checkHTKConfigExists(htkConfigFilePath.c_str());

	if(!checkHTKConfigExists)
	{
		cout<<"Unable to access HTK's config file:"<<htkConfigFilePath<<endl;
		return 1;
	}

	checkHTKConfigExists.close();

	cmdLine = "mkdir "+tempDir;

	system(cmdLine.c_str());

	statisticsFilePath = tempDir + string(SEPARATOR) + "class-train-statistics.txt";

	ofstream doesExist(statisticsFilePath.c_str());

	if(!doesExist)
	{

		cout<<"Unable to create files at:"<<tempDir<<endl;
		return 1;
	}

	doesExist.close();


	htkFeatFilesDestDir = tempDir+string(SEPARATOR)+"htktraindata";

	cmdLine = "mkdir "+htkFeatFilesDestDir;

	system(cmdLine.c_str());

	ifstream input(featureFilePath.c_str());

	if(input)
	{
		string eachLine;
		getline(input,eachLine,'\n'); //simply reading the first line of the feature file

		bool isSecondLine = true;

		int classId;

		int numPoints;

		int lineNumber = 1;

		while(input)
		{
			eachLine = "";

			++lineNumber;

			getline(input,eachLine,'\n');

			if(!eachLine.empty())
			{
				vector<string> tokens;
				LTKStringUtil::tokenizeString(eachLine," ",tokens);

				if(tokens.size()!=2)
				{
					cout<<"Error reading feature file at line number:"<<lineNumber<<endl;
					return 1;
				}

				classId  =atoi(tokens[0].c_str());

				vector<string> strFeaturePointsVec;
				LTKStringUtil::tokenizeString(tokens[1],"|",strFeaturePointsVec);

				numPoints = strFeaturePointsVec.size();
								

				if(numPoints <=0)
				{
					cout<<"Error reading feature file at line number:"<<lineNumber<<endl;
					return 1;
				}

				if(isSecondLine)
				{
					vector<string> tempTokens;
					LTKStringUtil::tokenizeString(strFeaturePointsVec[0],",",tempTokens);
					char buff[50];
					sprintf(buff,"%d",tempTokens.size()-1); //-1 to ignore the pen-up bit feature
					strNumFeatures = string(buff);
					outNumFeatures = atoi(strNumFeatures.c_str());
					isSecondLine = false;
				}

				if(classStatistics.find(classId)!=classStatistics.end())
				{
					  classStatistics[classId].numSamples+=1;
					  classStatistics[classId].totalNumPoints+=numPoints;

				}
				else
				{
					 ClassDetails cd;
					 cd.numSamples=1;
					 cd.totalNumPoints=numPoints;
					 classStatistics[classId]=cd;
					 string classDir=htkFeatFilesDestDir+SEPARATOR+tokens[0];
					 
					 cmdLine = "mkdir "+classDir;
					 system(cmdLine.c_str());
				}
				string tempFilePath = tempDir+string(SEPARATOR)+"tmp.txt";

				ofstream tempOutput(tempFilePath.c_str());

				for(int i=0;i<strFeaturePointsVec.size();++i)
				{
					vector<string> tempTokens;
					LTKStringUtil::tokenizeString(strFeaturePointsVec[i],",",tempTokens);

					for(int ii=0;ii<(tempTokens.size()-1);++ii) //-1 to ignore the pen-up bit feature
					{
						tempOutput<<tempTokens[ii]<<" ";
					}
				}
				tempOutput<<endl;
				tempOutput.close();

				char buffer[100];
				sprintf( buffer,"%03d",(classStatistics[classId].numSamples)-1);
				string strSampleIndex(buffer);

				char buff[100];
				sprintf(buff,"%d",strFeaturePointsVec.size());
				string strNumPoints(buff);

				string htkFeatFilePath=htkFeatFilesDestDir+SEPARATOR+tokens[0]+string(SEPARATOR)+"train_class"+tokens[0]+"_"+strSampleIndex;


				cmdLine=htkInstallationDir+string(SEPARATOR)+"ascii_htk "+tempFilePath+" "+strNumFeatures+" "+strNumPoints+" "+htkFeatFilePath;
				system(cmdLine.c_str());
				remove(tempFilePath.c_str());


			}
		}
	}
	else
	{
		cout<<"Unable to acess feature file:"<<featureFilePath<<endl;
		return 1;
	}

	input.close();

   ofstream output(statisticsFilePath.c_str());
   output<<"#Class_ID AVG_NUM_POINTS NUM_SAMPLES"<<endl;
   for(map<int,ClassDetails>::iterator iter=classStatistics.begin();iter!=classStatistics.end();++iter)
   {
	output<<iter->first<<" ";
	int numOfSamples=(iter->second).numSamples;
	int avgNumPoints=(iter->second).totalNumPoints/numOfSamples;
	output<<avgNumPoints<<" "<<numOfSamples<<endl;
   }
   output.close();
	
   return 0;

}