Ejemplo n.º 1
0
JNIEXPORT jobject JNICALL OS_NATIVE(_1makeShot)
(JNIEnv *env, jclass jclazz, jobject jwnd)
{
	WebWindow* wnd = getWebWindow(env, jwnd);
	HBITMAP hBmp = printWindow(wnd->getWebViewWindowHandle());
	return wrap_pointer(env, hBmp);
}
Ejemplo n.º 2
0
BOOL CapturedImage::Capture(HWND hwnd, HDC hdc) {
	typedef BOOL(WINAPI *tPrintWindow)(HWND, HDC, UINT);
	tPrintWindow printWindow = NULL;
	HINSTANCE handle = ::LoadLibrary("User32.dll");
	BOOL ret = FALSE;
	if (handle) {
		printWindow = (tPrintWindow)::GetProcAddress(handle, "PrintWindow");
		if (printWindow) {
			ret = printWindow(hwnd, hdc, 0);
		} else {
			ret = FALSE;
		}
	}
	::FreeLibrary(handle);
	return ret;
}
Ejemplo n.º 3
0
int main(int argc, const char *argv[]) {
	
  	if (argc < 3) {
		fprintf(stderr, "Error: Invalid number of arguments.\n Try: ./getWindow ./genome.bin 384203\n");
		return 1;
	}
	
	unsigned long index = atoi(argv[2]);
	if (argc == 4 && strcmp(argv[3], "-r") == 0) {
	    index *= ALIGNED_SIZE * 4;
	}
	
  	long page_size = sysconf(_SC_PAGE_SIZE);
  	const char *filename = argv[1];
	int fd = open(filename, O_RDONLY);

	if (fd < 0) {
	    fprintf(stderr, "Error: Invalid filename.\n");
		return 1;
	}

	struct stat fileStat;

	if(fstat(fd, &fileStat) < 0) {
		fprintf(stderr, "Error: Couldn't get file size.\n");
        return 1;
	}

	unsigned int size = fileStat.st_size;
 	unsigned char * genome = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);

  	if (genome == MAP_FAILED) {
    	fprintf(stderr, "Error: Could not map genome.\n");
    	return 1;
	}

	unsigned char window[ALIGNED_SIZE] = {};
	getWindowAtIndex(genome, window, index);

	if (argc == 4 && strcmp(argv[3], "-b") == 0)
		fwrite(window, 1, ALIGNED_SIZE, stdout);
	else
    	printWindow(window);
		
}
Ejemplo n.º 4
0
int main(){
	int i;
	for(i = 10; i < 30; i++){
		insertIntoCWindow(i,0,10,1000);
	}
	
	printWindow();

	printf("\n\n (expected to fail: addeding pkts 30 31\n");
	insertIntoCWindow(30,0,10,1000);
	insertIntoCWindow(31,0,10,1000);
	
	printWindow();
	
	printf("\n\n removing from window pkts 10 11 12\n");
	removeFromCWindow(10);
	removeFromCWindow(11);
	removeFromCWindow(12);
	printWindow();
	//this should not move windowStartOfPacketBlock 
	printf("\n\n removing from window pkts 14 15\n");
	removeFromCWindow(14);
	removeFromCWindow(15);
	printWindow();
	//this should move windowStartOfPacketBlock
	printf("\n\n removing from window pkts 13\n");
	removeFromCWindow(13);
	printWindow();

	printf("\n\n (expected to success: addeding pkts 30 31\n");
	insertIntoCWindow(30,0,10,1000);
	insertIntoCWindow(31,0,10,1000);
	printWindow();

	printf("\n\n (expected to success: addeding pkts 32 33 34 35\n");
	insertIntoCWindow(32,0,10,1000);
	insertIntoCWindow(33,0,10,1000);
	insertIntoCWindow(34,0,10,1000);
	insertIntoCWindow(35,0,10,1000);
	printWindow();
	


}
Ejemplo n.º 5
0
void retransmit(int i, int sock, const struct sockaddr* cli_addr, socklen_t clilen){
	int j;
	for(j = i; j< window->startIndex + window->windowLength; j++){
		window->acked[j] = 0;
		window->timer[j] = timeOut;
	}
	window->nextToSend = i;
	window->startIndex =i;
	window->windowLength = 1;
	printWindow();
	double r= (rand() % 100) * 1.0 / 100.0;			//random chance of loss!
	if (r < (1.0 - ploss - pcorr)){
		printf("Random float : %f\n", r);
		printf("Retransmitting segment : %d\n", i);
		int n = sendto(sock,window->segments[i],1000,0,cli_addr,(socklen_t) clilen);
		if(n<0)
			printf("problem sending\n");
		window->acked[i]=1;
	}
  else if(r > (1 - pcorr)) {
    char corruptPacket[4];
    sprintf(corruptPacket, "%d", -1);
    int n = sendto(sock, corruptPacket, strlen(corruptPacket), 0,cli_addr,(socklen_t) clilen);
    if (n < 0)
         error("ERROR writing to socket");
    printf("-----------\nPacket corrupted! Sending corrupted packet...\n-----------\n");
  }
	else{
		printf("Random float : %f\n", r);
		printf("Packet %d sent but loss\n", i);
	}
  	
	if (window->nextToSend == window->segmentCount-1)
		window->nextToSend++;
	
	
	
}
Ejemplo n.º 6
0
void Game::play()
{
    // make sure all text is cleared so all future generational grids
    // line up with the first one
    std::cout.flush();
    system("clear");

    for (int gen = 0; gen < generations; ++gen)
    {
        // print the visible window, hiding the buffers
        printWindow();

        // pause to look at the current generation
        usleep(pauseLength);

        // clear console for next generation
        std::cout.flush();
        system("clear");

        // calculate the next generation
        tick();
    }
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
    signal(SIGALRM, timeOutHandler); // bind the timeOutHandler with the timer object.
   // int sockfd, newsockfd, cwnd_length, portno, pid;
	int newsockfd, cwnd_length, portno, pid;
    //float ploss, pcorr;
    char* tail;
    char* hi = "Received your message";

   // socklen_t clilen;
   //struct sockaddr_in serv_addr, cli_addr;


    if (argc < 5 && argc!=2) {
        fprintf(stderr,"ERROR, proper use: ./sender <port number> <cwnd> <p_loss> <p_corrupt>\n");
        exit(1);
    }
    if (argc==2){
	test=true;
    }

  if(test==false){
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    if (sockfd < 0)
        error("ERROR opening socket");

    bzero((char *) &serv_addr, sizeof(serv_addr));

    portno = atoi(argv[1]);
    cwnd_length = atoi(argv[2]);

    ploss = strtof(argv[3], &tail);
    pcorr = strtof(argv[4], &tail);

    printf( "Probability of Loss: %f\n",ploss);
    printf( "Probability of Corruption: %f\n\n", pcorr);

	

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(portno);

    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) //ANDREW CHANGE #2: casted &serv_addr to (struct sockaddr *) instead of (struct sockaddr_in*)
        error("ERROR on binding");

    clilen = sizeof(cli_addr);
  }

    FILE* requestFile; // FIXME: Read the document about allocate a new file in ram


   char* testInput;

   if (test==false){		//if not a test, read socket input into buffer
	while (1) {
		int n;
        	char buffer[256];

       	 	bzero(buffer, 256);
       		 n = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr*) &cli_addr, (socklen_t *) &clilen); //ANDREW CHANGE #3: casted &cli_addr to (struct sockaddr *)
        	if (n < 0)
            		error("ERROR reading from socket");
       		 else {
            		// fprintf(stdout, buffer);
           		 requestFile = findFile(buffer);
           		 break;
           		 // break out the initial round of request
            		// FIXME: if the file is not found, send something to client
       		 }
   	 } /* end of while */
   }
   else{		//if a test, read "test" into buffer
	 testInput = argv[1];
   	 printf( "\n\n\nmain()\n----------\nRequested Filename: %s\n\n\n",testInput);
	 requestFile = findFile(testInput);
   }

    /* init window */

    //FIRST BURST OF COMMANDS
	makeWindow(requestFile);		//allocate and construct window
	//if(test==true){
	if(1){
	  printWindow();
	}

    //FIXME: Not sure if anything missing
	
	
    int commandLength;	//single pointer to a single integer that saves the length of lastCommand()
    int* lastCommand = prepareToSend(&commandLength);
	printf( "Preparing to send\n{ ");
	 int p=0;
	for (p=0; p < commandLength; p++){
		if (p == commandLength - 1)
			printf( "%d }\n",lastCommand[p]);
		else
			printf( "%d, ",lastCommand[p]);
	}
	sendPacket(lastCommand, commandLength, sockfd, (struct sockaddr*)&cli_addr, clilen); // first send
        // TODO: free the lastCommand;

        free(lastCommand);
	commandLength=0;
	printWindow();
		
    alarm(1); // start timming cycle.
	
    while(1){
      //if timeout, resend
	if(resend == true){
		printf( "About to resend\n");
		lastCommand = prepareToSend(&commandLength);
		if(commandLength>0){
			printf( "Preparing to resend:\n{ ");
			printf( "%d }\n",lastCommand[0]);
			sendPacket(lastCommand, commandLength, sockfd, (struct sockaddr*)&cli_addr, clilen); 
		}
		free(lastCommand);
		resend=false;
	}
      // receving acks from recever:
      int n;
      char buffer[256]; // buffer for acks
      bzero(buffer, 256);
	
      n = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr*)&cli_addr, (socklen_t *) &clilen);
      if (n < 0)
          error("ERROR reading from socket");
      else {
        int ack = 0;

        // check if done
        if(strncmp("done", buffer, 4) == 0) {
          printf("Receiver signaled final fully sent! Terminating...\n");
          exit(0);
        }
        // TODO: parse the acks from buffer:
	ack = atoi(buffer);
        updateOnAcked(ack);

	 printWindow();
	if (isFinished()){
		printf( "Send complete! \n\n");
		break;
	}
	 
        lastCommand = prepareToSend(&commandLength);
	if(commandLength>0){
		printf( "Preparing to send:\n{ ");
		 int p=0;
		for (p=0; p < commandLength; p++){
			if (p == commandLength - 1)
				printf( "%d }\n",lastCommand[p]);
			else
				printf( "%d, ",lastCommand[p]);
		}
		sendPacket(lastCommand, commandLength, sockfd, (struct sockaddr*)&cli_addr, clilen); // first send
        	// TODO: free the lastCommand;
        	
   	}
	 else
		printf( "Nothing to Send \n\n");
	 printWindow();
	free(lastCommand);
	 commandLength=0;
        //TODO: free the lastCommand
        // free(lastCommand);
      }
    }
    return 0; /* we never get here */
}