Beispiel #1
0
/* Initialize module */
void __attribute__ ((constructor)) _init(void)
{
	int opt = 1;
	struct sockaddr_in sin;

	orig_sendto = preload("sendto");
	orig_recvfrom = preload("recvfrom");
	orig_setsockopt = preload("setsockopt");
	orig_bind = preload("bind");

	ctrl_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (ctrl_socket < 0) {
		printf ("Ajil lib failed to create control socket\n");
		exit (-1);
	}
	orig_setsockopt (ctrl_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

	memset (&sin, 0, sizeof(struct sockaddr_in));
	sin.sin_family = AF_INET;
	sin.sin_addr.s_addr = inet_addr(DADDRESS);
	sin.sin_port = htons(DPORT);

	if (connect (ctrl_socket, (struct sockaddr *) &sin, sizeof(struct sockaddr_in)) < 0) {
		printf ("Could not connect to Ajil daemon\n");
		exit (-1);
	} else {
		printf ("Connected to Ajil daemon\n");
		usleep (500);
		if (recv (ctrl_socket, (void *) &data_port, sizeof(uint16_t), 0) < 0) {
			printf ("Error receiving port number from daemon\n");
			exit (-1);
		}
	}
}
SlippyMapCache::SlippyMapCache()
: QObject(0), DownloadReply(0), DownloadBusy(false), theMap(0)
{
    baseUrl.setUrl("http://tile.openstreetmap.org");
    Download.setProxy(M_PREFS->getProxy(baseUrl));

    connect(&Download,SIGNAL(finished(QNetworkReply*)),this,SLOT(on_requestFinished(QNetworkReply*)));

    preload(Coord(0,0,0),":/Tiles/000.png");
    preload(Coord(0,0,1),":/Tiles/100.png");
    preload(Coord(0,1,1),":/Tiles/101.png");
    preload(Coord(1,0,1),":/Tiles/110.png");
    preload(Coord(1,1,1),":/Tiles/111.png");
}
SlippyMapCache::SlippyMapCache()
: QObject(0), DownloadId(0), DownloadBusy(false), theMap(0)
{
    Download.setProxy(M_PREFS->getProxy(QUrl(QString("http://tile.openstreetmap.org"))));
    Download.setHost("tile.openstreetmap.org");

    DownloadBuffer.setBuffer(&DownloadData);
    DownloadBuffer.open(QIODevice::WriteOnly);
    connect(&Download,SIGNAL(requestFinished(int,bool)),this,SLOT(on_requestFinished(int, bool)));

    preload(Coord(0,0,0),":/Tiles/000.png");
    preload(Coord(0,0,1),":/Tiles/100.png");
    preload(Coord(0,1,1),":/Tiles/101.png");
    preload(Coord(1,0,1),":/Tiles/110.png");
    preload(Coord(1,1,1),":/Tiles/111.png");
}
Beispiel #4
0
__int64 binstream::read_int64( )
{
	if (pos>inbuffer-8) preload();
	__int64 i64=*((__int64*)&buffer[pos]);
	pos+=8;
	return i64;
}
Beispiel #5
0
int binstream::read_int( )
{
	if (pos>inbuffer-4) preload();
	int i= *((int*)&buffer[pos]);
	pos+=4;
	return i;
}
Beispiel #6
0
__int16 binstream::read_int16( )
{
	if (pos>inbuffer-2) preload();
	int i= *((__int16*)&buffer[pos]);
	pos+=2;
	return i;
}
Beispiel #7
0
double binstream::read_double( )
{
	if (pos>inbuffer-8) preload();
	double d=*((double*)&buffer[pos]);
	pos+=8;
	return d;
}
Beispiel #8
0
SDL_Surface* Texture::preload(const std::string& path)
{
    SDL_RWops* rw = SDL_RWFromFile(path.c_str(), "rb");
    if(rw == NULL)
        return NULL;
    return preload(rw, true);
}
Beispiel #9
0
int binstream::readblock(void* dataPtr, int len)
{
	if (pos>inbuffer-len) preload();
	memcpy(dataPtr, &buffer[pos], len);
	pos+=len;
	return len;
}
Beispiel #10
0
bool binstream::read_bool( )
{
	if (pos>inbuffer-1) preload();
	bool b= *((bool*)&buffer[pos]);
	++pos;
	return b;
}
void 
MMRDecoder::VLSource::shift(const int n)
{ 
  codeword<<=n;
  lowbits+=n;
  if (lowbits>=16)
    preload();
}
Beispiel #12
0
char binstream::getchar()
{
	if (pos>inbuffer || inbuffer==0) preload();
	char c=buffer[pos];
	pos++;
	if (unicode) pos++;
	return c;
}
Options_Window::Options_Window() : 
Window(SCREEN_WIDTH, SCREEN_HEIGHT, "Options"),
tabs(*this),
content_area(*this)
{
  preload(10,10);

}
void
MMRDecoder::VLSource::init(const bool striped)
{
  if (striped)
    readmax = inp.read32();
  lowbits = 32;
  preload();
}
void HTMLResourcePreloader::takeAndPreload(PreloadRequestStream& r)
{
    PreloadRequestStream requests;
    requests.swap(r);

    for (PreloadRequestStream::iterator it = requests.begin(); it != requests.end(); ++it)
        preload(it->release());
}
Beispiel #16
0
void PEAC:: openanswerfile()
{
    name= QFileDialog::getOpenFileName (this,"Browse Files","~/Desktop",("PEAC File (*.peac)"));
    preload();

   // ui->textEdit_2->append(list[0]);
    checkNA();
}
Beispiel #17
0
int binstream::read_bigendianint()
{
	if (pos>inbuffer-4) preload();
	int i= (unsigned char)buffer[pos++];
	i = (i<<8) + (unsigned char)buffer[pos++];
	i = (i<<8) + (unsigned char)buffer[pos++];
	i = (i<<8) + (unsigned char)buffer[pos++];
	return i;
}
void ResourcePreloader::takeAndPreload(PreloadRequestStream& r)
{
    PreloadRequestStream requests;
    NetworkHintsInterfaceImpl networkHintsInterface;
    requests.swap(r);

    for (PreloadRequestStream::iterator it = requests.begin(); it != requests.end(); ++it)
        preload(it->release(), networkHintsInterface);
}
Beispiel #19
0
static void
ReadDependentCB(const char *aDependentLib, bool do_preload)
{
    if (do_preload)
        preload(aDependentLib);
    (void) NSAddImage(aDependentLib,
                      NSADDIMAGE_OPTION_RETURN_ON_ERROR |
                      NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME);
}
Beispiel #20
0
bool Texture::load(const std::string& path)
{
    SDL_Surface* surf = preload(path);
    if(surf == NULL)
        return false;
    if(!loadsdl(surf))
        return false;
    SDL_FreeSurface(surf);
    return true;
}
Beispiel #21
0
bool binstream::open(const wchar_t* filename)
{
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx
	if (opened)
	{
		flush();
		CloseHandle(f);
	}

	inbuffer=0;
	pos=0;
	fileStream = true;

	if (buffersize<2)
		throw "Buffer should be at least 2 characters long.";
	if (writable)
	{
		f = CreateFileW( filename, 
			GENERIC_WRITE,
			0, // No sharing
			NULL,
			CREATE_ALWAYS, // 
			FILE_ATTRIBUTE_NORMAL,
			NULL);
	} else
	{
		f = CreateFileW( filename, 
			GENERIC_READ,
			0, // No sharing
			NULL,
			OPEN_EXISTING, // 
			FILE_ATTRIBUTE_NORMAL,
			NULL);
		if (GetLastError()==ERROR_FILE_NOT_FOUND )
		{
		failbit=true;
			throw "File not found.";
		}
	}
	if (!f)
	{			
		failbit=true;
		return false;
	}

	if (!buffer)
		buffer = new char[buffersize]; 
	preload();

	testforUnicode();

	opened=true;
	return true;
} // binstream::open(wchar_t* filename)
Beispiel #22
0
wchar_t* binstream::read_wchar( )
{
	wchar_t* wc; //shared ptr would be better
	int len=read_int();
	if (pos>inbuffer-len*2) preload();
	wc=new wchar_t[len+1];
	memcpy(wc,&buffer[pos], len*2);
	pos+=len*2;
	wc[len]=0;
	return wc;
}
Beispiel #23
0
bool binstream::eof()
{
	if (pos<inbuffer)
		return false;
	
	if (!fileStream) return true; // end of the memory stream
	
	// read on more data if it is a file stream
	preload();
	return inbuffer==0;
}
Beispiel #24
0
char* binstream::read_char( )
{
	char* c; //shared ptr would be better
	int len=read_int();
	if (pos>inbuffer-len) preload();
	c=new char[len+1];
	memcpy(c,&buffer[pos], len);
	pos+=len;
	c[len]=0;
	return c;
}
Beispiel #25
0
int main(int argc, char *argv[])
{
	struct sigaction action;
	memset(&action, 0, sizeof(action));
	action.sa_handler = sigterm;
	sigaction(SIGTERM, &action, NULL);
	sigaction(SIGINT, &action, NULL);

	int verbose = 0;
	for (int i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-v") == 0) {
			verbose = 1;
		}
	}

	size_t total = 0;
	unsigned long attempted = 0;
	unsigned long loaded = 0;

	char line[linebuf];
	while (!end && fgets(line, linebuf, stdin)) {
		/* \n -> 0 */
		line[strlen(line) - 1] = 0;
		size_t size;
		if (preload(line, &size) == 0) {
			if (verbose) {
				fprintf(stderr, "Preloaded '%s'\n", line);
			}
			total += size;
			loaded++;
		}
		attempted++;
		/*
		 * In case the active IO scheduler doesn't already make us yield
		 * to other processes
		 */
		usleep(1000);
	}

	touch();

	fprintf(stderr, "Done, preloaded %lu/%lu files (%lluMB)\n", loaded, attempted, (long long unsigned int) (total >> 20));

	while (!end) {
		sleep(-1);
	}

	fprintf(stderr, "Unloading\n");
	unload();
	fprintf(stderr, "Unloaded\n");

	return 0;
}
Beispiel #26
0
boost::shared_ptr<wchar_t> binstream::read_wchar_sptr( )
{
	wchar_t* wc;
	int len=read_int();
	if (pos>inbuffer-len*2) preload();
	wc=new wchar_t[len+1];
	memcpy(wc,&buffer[pos], len*2);
	pos+=len*2;
	wc[len]=0;
	boost::shared_ptr<wchar_t> sptr (wc);
	return sptr;
}
static void
ReadDependentCB(const char *aDependentLib, bool do_preload)
{
#if defined(LINUX) && !defined(ANDROID)
    if (do_preload)
        preload(aDependentLib);
#endif
    void *libHandle = dlopen(aDependentLib, RTLD_GLOBAL | RTLD_LAZY);
    if (!libHandle)
        return;

    AppendDependentLib(libHandle);
}
	OpenALStream::OpenALStream(boost::shared_ptr<AudioFile> file,
		                       boost::function<void (void)> onStreamFinished,
	                           ALuint sourceId):
		Stream(file, onStreamFinished),
		mNUM_BUFFER(6),
		mSourceId(sourceId),
		mFinished(false)
    {
		mBufferIds.reset(new ALuint[mNUM_BUFFER]);
		alGenBuffers(mNUM_BUFFER, mBufferIds.get());
		alErrorHandler("OpenALStream::OpenALStream", "Error occured calling alGenBuffers.");
	
		preload();
    }
static void
ReadDependentCB(const char *aDependentLib, PRBool do_preload)
{
    wchar_t wideDependentLib[MAX_PATH];
    MultiByteToWideChar(CP_UTF8, 0, aDependentLib, -1, wideDependentLib, MAX_PATH);

    if (do_preload)
        preload(wideDependentLib);

    HINSTANCE h =
        LoadLibraryExW(wideDependentLib, NULL, MOZ_LOADLIBRARY_FLAGS);

    if (!h)
        return;

    AppendDependentLib(h);
}
void
MMRDecoder::VLSource::nextstripe(void)
{
  while (readmax>0)
    {
      int size = sizeof(buffer);
      if (readmax < size) 
        size = readmax;
      inp.readall(buffer, size);
      readmax -= size;
    }
  bufpos = bufmax = 0;
  memset(buffer,0,sizeof(buffer));
  readmax = inp.read32();
  codeword = 0; 
  lowbits = 32;
  preload();
}