Пример #1
0
Config::Config(std::string filePath, bool implicitLoad) : mConfData(), mFilePath(filePath), mFile()
{
	SAssert(str::contains(filePath, ".cfg"), "config file: " + filePath + " is of unknown format");
	if(implicitLoad)
	{
		loadToMemory(mFilePath);
	}
}
Пример #2
0
void TcpReceiver::executeThread()
{
	serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
	if (serverSocket < 0)
		return;

    u32 enable = 1;
	setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));

	struct sockaddr_in bindAddress;
	memset(&bindAddress, 0, sizeof(bindAddress));
	bindAddress.sin_family = AF_INET;
	bindAddress.sin_port = serverPort;
	bindAddress.sin_addr.s_addr = INADDR_ANY;

	s32 ret;
	if ((ret = bind(serverSocket, (struct sockaddr *)&bindAddress, sizeof(bindAddress))) < 0) {
		socketclose(serverSocket);
		return;
	}

	if ((ret = listen(serverSocket, 3)) < 0) {
		socketclose(serverSocket);
		return;
	}

	struct sockaddr_in clientAddr;
	s32 addrlen = sizeof(struct sockaddr);

    while(!exitRequested)
    {
        s32 clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &addrlen);
        if(clientSocket >= 0)
        {
            u32 ipAddress = clientAddr.sin_addr.s_addr;
            serverReceiveStart(this, ipAddress);
            int result = loadToMemory(clientSocket, ipAddress);
            serverReceiveFinished(this, ipAddress, result);
            socketclose(clientSocket);

            if(result > 0)
                break;
        }
        else
        {
            os_usleep(100000);
        }
    }

    socketclose(serverSocket);
}
Пример #3
0
void Cache::flush()
{
	for (unsigned i = 0; i < setsPerCache; i++)
	{
		try
		{
			set[i]->flush();
		}
		catch (dataIsDirtyException e)
		{
			unsigned storeAddress = e.getTag()*wordsPerBlock*bytesPerWord;
			loadToMemory(storeAddress, e.dirtyLocation());
			i--;
		}
	}
}
Пример #4
0
static uint8_t* getMemoryInternal(PluginData* data, const char* tempfile, size_t* readSize, uint16_t address, uint16_t addressEnd)
{
	*readSize = 0;

#ifndef _WIN32
	if (unlink(tempfile) < 0)
	{
		printf("c64_vice: Unable to delete %s (error %d)\n", tempfile, errno);
	}
#else
	// TODO: Implement me.
	/*
	if (DeleteFile(tempfile) != 0)
	{
		printf("failed to delete %s\n", timepfile); 
		return 0;
	}
	*/
#endif

    sendCommand(data, "save \"%s\" 0 %04x %04x\n", tempfile, address, addressEnd);

    // Wait 10 ms for operation to complete and if we can't open the file we try for a few times and if we still can't we bail

    sleepMs(10);

    for (int i = 0; i < 10; ++i)
    {
        uint8_t* mem = loadToMemory(data->tempFileFull, readSize);

        if (!mem)
        {
            sleepMs(1);
            continue;
        }

        printf("returing mem...\n");

        return mem;
    }

    printf("Unable to get memory...\n");

    return 0;
}
Пример #5
0
void Cache::storeFromMemory(unsigned byteAddress)
{
	unsigned setIndex = (byteAddress / (wordsPerBlock*bytesPerWord)) % setsPerCache;
	unsigned tag = byteAddress / (wordsPerBlock*bytesPerWord);
	unsigned offset = byteAddress % (wordsPerBlock*bytesPerWord);
	Byte* data = new Byte[bytesPerWord*wordsPerBlock];
	memory->read(data, byteAddress - offset, (bytesPerWord*wordsPerBlock));
	try{
		set[setIndex]->storeFromMemory(data, tag, NULL);
	}
	catch (dataIsDirtyException e)
	{
		unsigned storeAddress = e.getTag()*wordsPerBlock*bytesPerWord;
		loadToMemory(storeAddress, e.dirtyLocation());
		set[setIndex]->storeFromMemory(data, tag, e.dirtyLocation());
	}
	delete[] data;
}
Пример #6
0
/// Writes the contents of assetname to filename
bool LoaderSDT::saveAsset(size_t index, const std::string& filename,
                          bool asWave) {
    char* raw_data = loadToMemory(index, asWave);
    if (!raw_data) return false;

    FILE* dumpFile = fopen(filename.c_str(), "wb");
    if (dumpFile) {
        LoaderSDTFile asset;
        if (findAssetInfo(index, asset)) {
            fwrite(raw_data, 1, asset.size + (asWave ? sizeof(WaveHeader) : 0),
                   dumpFile);
            printf("=> SDT: Saved %zu to disk with filename %s\n", index,
                   filename.c_str());
        }
        fclose(dumpFile);

        delete[] raw_data;
        return true;
    } else {
        delete[] raw_data;
        return false;
    }
}
Пример #7
0
int main(int argc, const char * argv[])
{
    
    
    if(argc < 5 || argc > 5)
    {
        printf("Usage: ./bikehelper start_long start_lat end_long end_lat (in degrees) \n");
        exit(1);
    }
     
    int h;

    for( h = 1; h < argc; h++)
    {
    	checkInputError(h, argv);
    }

    if(-180 > atof(argv[1]) || atof(argv[1]) > 180.0) 
    {
        printf("Longtitude between -180 and 180 only \n");
        exit(1);
    }
     
     if(-180 > atof(argv[3]) || atof(argv[3]) > 180.0) 
     {
	printf("Longtitude between -180 and 180 only \n");
        exit(1);	
     }
     
    if(-90 > atof(argv[2]) || atof(argv[2]) > 90 )
    {
        printf("Latitude between -90 and 90 only \n");
        exit(1);
    }
    
    if(-90 > atof(argv[4]) || atof(argv[4]) > 90)
    {
	 printf("Latitude between -90 and 90 only \n");
         exit(1);
    }

    char *first_bikestop;
    
    char *destination_file;
    
    int file_size = (int)loadToMemory("/usr/local/unnc/ae1prg/npb/stops.txt" , &destination_file);
    
    char *second_bikestop;
    
    double longtitude_bus[3];
    
    double latitude_bus[3];
    
    char busStop_name[3][40];
    
    char *direction[3];
    
    int bearing[3];
    
    printf("Starting from %s %s \n", argv[1], argv[2]);
    
    
    /* ---------------------------------- First part of the output ----------------------------------- */
    
    
    char *stop =  toBikeStop(destination_file, atof(argv[1]), atof(argv[2]), file_size, &first_bikestop);
    
    sscanf(first_bikestop, "%lf %lf %s", &longtitude_bus[0], &latitude_bus[0], busStop_name[0]);
    
    bearing[0] = getBearing(atof(argv[1]), atof(argv[2]), longtitude_bus[0], latitude_bus[0]);

    getDirection(bearing[0], &direction[0]);
    
    printf("Walk %s to %s at %f, %f \n", direction[0], busStop_name[0], longtitude_bus[0], latitude_bus[0]);

    
    
    /* ---------------------------------- Second part of the output ----------------------------------- */

    
    char * stop1 = toBikeStop(destination_file, atof(argv[3]), atof(argv[4]), file_size, &second_bikestop);
    
    sscanf(second_bikestop, "%lf %lf %s", &longtitude_bus[1], &latitude_bus[1], busStop_name[1]);
    
    bearing[1] = getBearing(longtitude_bus[0], latitude_bus[0], longtitude_bus[1], latitude_bus[1]);

    getDirection(bearing[1], &direction[1]);
    
    printf("Cycle %s to %s at %f, %f \n", direction[1], busStop_name[1], longtitude_bus[1],latitude_bus[1]);



    /* ---------------------------------- Third part of the output ----------------------------------- */
    
    bearing[2] = getBearing(longtitude_bus[1], latitude_bus[1], atof(argv[3]), atof(argv[4])),
    
    getDirection(bearing[2], &direction[2]);
    
    printf("Walk %s to your destination at %f, %f \n",direction[2],atof(argv[3]), atof(argv[4]));
    
    free(stop);
    free(stop1);
    free(destination_file);
    return 0;
    
}