예제 #1
0
// Constructors
BigInt::BigInt(const std::string& str)
{
	int startPos = 0;
	if (str.compare(0,1,"-") == 0) {
		sign = NEGATIVE;
		startPos = 1;
	} else {
		sign = POSITIVE;
	}

	for (unsigned int i=startPos; i < str.length(); ++i)
		digits.push_front(ascii2Int(str[i]));
	base = BASE;
}
예제 #2
0
파일: host.c 프로젝트: raegand/Lab8
void hostInitTransmit(hostState * hstate, char word[], char replymsg[]) {
	if (hstate->sendBuffer.busy == 1) {
   		strcpy(replymsg, "Transmit Aborted: Currently Trasmitting");
		return;
	}
	if (hstate->sendBuffer.valid == 0) {
   		strcpy(replymsg, "Transmit Aborted: No File to Transmit");
		return;
	}

	char dest[1000];
	int  dstaddr;
	
	findWord(dest, word, 2);
	dstaddr = ascii2Int(dest);
	hstate->sendBuffer.dstaddr = dstaddr;
	hstate->sendBuffer.busy = 1;
	hstate->sendBuffer.pos = 0;
   	strcpy(replymsg, "Transmit Started");
}
예제 #3
0
파일: host.c 프로젝트: raegand/Lab8
/* 
 * Main loop of the host node
 *
 * It polls the manager connection for any requests from
 * the manager, and replies
 *
 * Then it polls any incoming links and downloads any
 * incoming packets to its receive packet buffer
 *
 * Then it sleeps for 10 milliseconds
 *
 * Then back to the top of the loop
 *
 */
void hostMain(hostState * hstate)
{
char buffer[1000]; /* The message from the manager */
char word[1000];
int  value;
char replymsg[1000];   /* Reply message to be displayed at the manager */
packetBuffer tmpbuff;
int length = 0; /* Size of string in pipe */

while(1) {
   /* Check if there is a command message from the manager */
   length = hostCommandReceive(&(hstate->manLink),buffer);

   if (length > 1) { /* Execute the manager's command */
      findWord(word, buffer, 1);
      if (strcmp(word, "SetNetAddr")==0) {
         findWord(word, buffer, 2); /* Find net address */
         value = ascii2Int(word);   /* Convert it to integer */
         hostSetNetAddr(hstate, value, replymsg);
         hostReplySend(&(hstate->manLink),"DISPLAY",replymsg);
      }
      else if (strcmp(word, "SetMainDir")==0) {
         findWord(word, buffer, 2); /* Find directory name */
         hostSetMainDir(hstate, word, replymsg);
         hostReplySend(&(hstate->manLink),"DISPLAY",replymsg);
      }
      else if (strcmp(word, "ClearRcvFlg")==0) {
         hostClearRcvFlg(hstate, replymsg);
         hostReplySend(&(hstate->manLink),"DISPLAY",replymsg);
      }
      else if (strcmp(word, "UploadPacket")==0) {
         findWord(word, buffer, 2); /* Find file name */
         hostUploadPacket(hstate, word, replymsg); 
         hostReplySend(&(hstate->manLink), "DISPLAY",replymsg);
      }
      else if (strcmp(word, "DownloadPacket")==0) {
         findWord(word, buffer, 2); /* Find file name */
         hostDownloadPacket(hstate, word, replymsg);
         hostReplySend(&(hstate->manLink), "DISPLAY",replymsg);
      }
      else if (strcmp(word, "GetHostState")==0) {
         hostGetHostState(hstate, &(hstate->manLink), replymsg);
         hostReplySend(&(hstate->manLink), "GetHostStateAck",replymsg);
      }
      else if (strcmp(word, "TransmitPacket")==0) {
		 hostInitTransmit(hstate, buffer, replymsg);
		 hostReplySend(&(hstate->manLink), "DISPLAY",replymsg);
      }
   } /* end of if */

   if (hstate->sendBuffer.busy == 1) {
	   hostTransmitPacket(hstate, replymsg);
   }


   /* Check if there is an incoming packet */
   length = linkReceive(&(hstate->linkin), &tmpbuff);

   /* 
    * If there is a packet and if the packet's destination address 
    * is the host's network address then store the packet in the
    * receive packet buffer
    */
   if (tmpbuff.dstaddr == hstate->netaddr && tmpbuff.valid == 1) {
	  /* if there is already something in the buffer; clear it */
	  if (tmpbuff.start == 1) {
		  memset(hstate->rcvBuffer.data, 0, sizeof(hstate->rcvBuffer.data));
		  hstate->rcvBuffer.length = 0;
		  hstate->rcvflag = 0;
	  }
	  strcat(hstate->rcvBuffer.data, tmpbuff.payload);
	  hstate->rcvBuffer.length += tmpbuff.length;
	  hstate->rcvBuffer.srcaddr = tmpbuff.srcaddr;
	  hstate->rcvBuffer.dstaddr = tmpbuff.dstaddr;
	  if (tmpbuff.end == 1) {
		  hstate->rcvflag = 1;
		  hstate->rcvBuffer.valid = 1;
	  }
   }

   /* The host goes to sleep for 10 ms */
   usleep(TENMILLISEC);

} /* End of while loop */

}