Exemplo n.º 1
0
int main(int argc, char** argv) {
  syssig_init(log_init_cast_user("test_route", LOG_PID|LOG_CONS|LOG_PERROR), NULL);
  rls();
  struct netroute_item_add_s a;
  bzero(&a, sizeof(struct netroute_item_add_s));
  strcpy(a.dst, "192.168.0.32");
  strcpy(a.gateway, "192.168.0.1");
  netroute_add(&a);
  rls();
  netroute_del(&a);
  rls();
  log_close();
  return 0;
}
Exemplo n.º 2
0
int CccModule::renderCMV2(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame)
{
    uint32_t numBlobs, numCCBlobs;
    BlobA *blobs;
    BlobB *ccBlobs;
    uint32_t numQvals, *qVals;

    Frame8 rawFrame(frame, width, height);
    rls(&rawFrame);
    m_blobs->blobify();
    m_blobs->getBlobs(&blobs, &numBlobs, &ccBlobs, &numCCBlobs);
    m_blobs->getRunlengths(&qVals, &numQvals);

    // render different layers...
    // starting with the background
    m_renderer->renderBA81(RENDER_FLAG_BLEND, width, height, frameLen, frame);
    // then based on the renderMode, render/blend the different layers in a stack
    if (m_renderMode==0)
        m_renderer->renderCCB2(RENDER_FLAG_BLEND | renderFlags, width/2, height/2, numBlobs*sizeof(BlobA)/sizeof(uint16_t), (uint16_t *)blobs, numCCBlobs*sizeof(BlobB)/sizeof(uint16_t), (uint16_t *)ccBlobs);
    else if (m_renderMode==1)
        m_renderer->renderCCQ1(RENDER_FLAG_BLEND | renderFlags, width/2, height/2, numQvals, qVals);
    else if (m_renderMode==2)
    {
        m_renderer->renderCCQ1(RENDER_FLAG_BLEND, width/2, height/2, numQvals, qVals);
        m_renderer->renderCCB2(RENDER_FLAG_BLEND | renderFlags, width/2, height/2, numBlobs*sizeof(BlobA)/sizeof(uint16_t), (uint16_t *)blobs, numCCBlobs*sizeof(BlobB)/sizeof(uint16_t), (uint16_t *)ccBlobs);
    }
    return 0;
}
Exemplo n.º 3
0
void
HTMLRenderTest::basicCallbackTest()
{
    // Theory of this test:
    // We implement a setTimeout function which will call a callback
    // after a period elapses.  We use setTimeout to stop the runloop
    // after 50ms.  We set another timer to stop the runloop in 120ms.
    // if the test takes longer than 100ms we assume that the setTimer
    // function didn't work, implying that callbacks are broken.

    bp::runloop::RunLoop rl;
    rl.init();

    boost::filesystem::path path = writeToTempFile(
        "<html><body>"
        "hello world" 
        "<script>"
        "var testFunc = function() {"
        "  BPDialog.setTimeout(function() { BPDialog.stop() }, 50);"
        "};"
        "if (window.addEventListener) {"
        "  window.addEventListener(\"load\", testFunc, true);"
        "} else if (window.attachEvent) {"
        "  window.attachEvent(\"onload\", testFunc);"
        "}"
        "</script>"
        "</body></html>");

    bp::html::ScriptableObject scriptableObject;
    CallbackScriptableFuncHost funcHost(&rl);

    // a function to stop the runloop via js callback
    scriptableObject.mountFunction(&funcHost, "setTimeout");
    scriptableObject.mountFunction(&funcHost, "stop");

    // a timer to stop the runloop in case the callback is not fired.
    bp::time::Timer t;
    RunLoopStopper rls(&rl);
    t.setListener(&rls);
    t.setMsec(250);

    {
        JavascriptRunner runner;
        runner.run(path, scriptableObject, "BPDialog");

        // now verify that we shutdown in less than 100ms with a stopwatch
        bp::time::Stopwatch sw;
        sw.start();
        rl.run();
        CPPUNIT_ASSERT( sw.elapsedSec() < .2 );
    }
    
    rl.shutdown();

    CPPUNIT_ASSERT(bp::file::safeRemove(path));
}
void ProcessBlobs::process(const Frame8 &frame, uint32_t *numBlobs, BlobA **blobs, uint32_t *numCCBlobs, BlobB **ccBlobs, uint32_t *numQvals, Qval **qMem)
{
#if 0
#if 0
    uint16_t boxes[] = {
        1, 20, 30, 10, 20,
        1, 35, 45, 25, 35,
        1, 20, 30, 10, 20,
        1, 21, 22, 11, 12,
        1, 25, 35, 20, 50,
        1, 25, 35, 20, 50,
        1, 25, 35, 20, 50,
        1, 80, 90, 40, 50,
        1, 80, 90, 60, 61
    };

    combine(boxes, 9);
    combine2(boxes, 9);
    compress(boxes, 9);
    return;
#endif

    rls(frame);
    m_blobs->blobify();
    m_blobs->getBlobs(blobs, numBlobs, ccBlobs, numCCBlobs);
    *numQvals = m_numQvals;
    *qMem = m_qMem;

    //processCoded();
#if 0 // uncomment if we only want to show structured blobs
    if (m_numCodedBoxes>0)
    {
        int i;
        for (i=0; i<m_numBoxes; i++)
        {
            m_boxes[i*4+0]=0;
            m_boxes[i*4+1]=0;
            m_boxes[i*4+2]=0;
            m_boxes[i*4+3]=0;
        }
    }
#endif
#endif
}
Exemplo n.º 5
0
void
TimerTest::simpleTest()
{
    bp::runloop::RunLoop rl;
    rl.init();

    RunLoopStopper rls(&rl);

    bp::time::Stopwatch sw;
    sw.start();

    bp::time::Timer t;
    t.setListener(&rls);
    t.setMsec(200);

    rl.run();

    sw.stop();
    
    // allow 20ms slop
    CPPUNIT_ASSERT( 0.180 < sw.elapsedSec() && sw.elapsedSec() < 0.220 );

    rl.shutdown();
}
Exemplo n.º 6
0
Arquivo: mftp.c Projeto: ryantlk/cs360
int main(int argc, char *argv[]){
	//check for correct args
	if(argc < 2){
		printerror("Error to few arguments: ");
		exit(EXIT_FAILURE);
	}

	int controlfd = makeconnection(argv[1], PORT_NUMBER);
	char *command = (char*)calloc(MAX_COMMAND_SIZE, sizeof(char));
	char *tokenize = (char*)calloc(MAX_COMMAND_SIZE, sizeof(char));
	char *token = (char*)calloc(MAX_COMMAND_SIZE, sizeof(char));
	char *delims = " \n\t";

	while(1){
		printf("mftp>");
		fgets(command, sizeof(char) * MAX_COMMAND_SIZE, stdin);
		if(!hasargs(command)){
			continue;	
		}
		memcpy(tokenize, command, sizeof(char) * MAX_COMMAND_SIZE);
		token = strtok(tokenize, delims);

		if(!strcmp(token, "ls")){
			ls();
		}else if(!strcmp(token, "rls")){
			int portnum;
			int rlssocket;
			if((portnum = getportnum(controlfd)) < 0){	
				printerror("rls not executed due to error");
				continue;
			}
			if((rlssocket = makeconnection(argv[1], portnum)) < 0){
				printerror("rls not executed due to error");
				continue;
			}
			rls(rlssocket, controlfd);
			close(rlssocket);
		}else if(!strcmp(token, "cd")){
			token = strtok(NULL, delims);
			cd(token);
		}else if(!strcmp(token, "rcd")){
			token = strtok(NULL, delims);
			rcd(token, controlfd);
		}else if(!strcmp(token, "get")){
			int portnum;
			int getsocket;
			int filefd;
			token = strtok(NULL, delims);
			if(token == NULL){
				printerror("Error expected parameter to get");
				continue;
			}
			char *filenamedelims = "/";
			char *filename = strtok(token, filenamedelims);
			char *lastname = filename;
			while((filename = strtok(NULL, filenamedelims)) != NULL){
				lastname = filename;
			}
			if((filefd = open(lastname, O_CREAT | O_APPEND | O_EXCL | O_WRONLY, S_IRUSR 
										| S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) < 0){
				perror("Error opening file");
				continue;
			}
			if((portnum = getportnum(controlfd)) < 0){
				printerror("get not executed due to error");
				continue;
			}
			if((getsocket = makeconnection(argv[1], portnum)) < 0){
				printerror("get not executed due to error");
				continue;
			}
			get(token, filefd, getsocket, controlfd);
			close(filefd);
			close(getsocket);
		}else if(!strcmp(token, "show")){
			int portnum;
			int showsocket;
			token = strtok(NULL, delims);
			if(token == NULL){
				printerror("Error expected parameter to show");
				continue;
			}
			if((portnum = getportnum(controlfd)) < 0){
				printerror("show not executed due to error");
				continue;
			}
			if((showsocket = makeconnection(argv[1], portnum)) < 0){
				printerror("show not executed due to error");
				continue;
			}
			show(token, showsocket, controlfd);
			close(showsocket);
		}else if(!strcmp(token, "put")){
			int portnum;
			int putsocket;
			int filefd;
			token = strtok(NULL, delims);
			if(token == NULL){
				printerror("Error expected parameter to put");
				continue;
			}
			char *filenamedelims = "/";
			char *filename = strtok(token, filenamedelims);
			char *lastname = filename;
			while((filename = strtok(NULL, filenamedelims)) != NULL){
				lastname = filename;
			}	
			if((filefd = open(token, O_RDONLY)) < 0){
				perror("Error opening file");
				continue;
			}
			if(isregular(token)){
				if((portnum = getportnum(controlfd)) < 0){
					printerror("put not executed due to error");
					continue;
				}
				if((putsocket = makeconnection(argv[1], portnum)) < 0){	
					printerror("put not executed due to error");
					continue;
				}
				put(lastname, filefd, putsocket, controlfd);
				close(filefd);
				close(putsocket);
			}else{
				close(filefd);
				printerror("File not regular put not executed");
			}
		}else if(!strcmp(token, "exit")){
			char *quit = "Q\n";
			char buf[100];
			write(controlfd, quit, sizeof(char) * 2);
			read(controlfd, buf, 100); 
			close(controlfd);
			exit(EXIT_SUCCESS);
		}else{
			printerror("Unknown command ignored");
		}
	}
}
Exemplo n.º 7
0
int loop(int sock) {
    struct stat obj;
    size_t size;
    int success;
    char buf[128], filename[96], command[8], *response;

    int i = 1;
    while(1)
    {
        printf("%s\n","Enter a command (ls, cd, pwd, rm, downl, upld, rpwd, rls, rcd, quit): ");
        scanf("%s", command);

        if(!strcmp(command, "ls")) {
            if(ls()) {
                printf("%s\n","The remote directory listing is as follows: ");
                system("cat ls.txt");
                system("rm ls.txt");
            }
        } else if(!strcmp(command, "cd")) {
            printf("%s\n","Enter the path to change the directory: ");
            scanf("%s", filename);
            printf("%s\n", cd(filename) ? "Directory changed successfully !" : "Error when trying to change directory");
        }  else if(!strcmp(command, "pwd")) {
            if(pwd()) {
                printf("%s\n","The current directory name is: \n");
                system("cat pwd.txt");
                system("rm pwd.txt");
            }
        }  else if(!strcmp(command, "rm")) {
            printf("%s\n","Enter the filename to remove: ");
            scanf("%s", filename);
            printf("%s\n", rm(filename) ? "File removed successfully !" : "Error when trying to remove file");
        } else if(!strcmp(command, "downl")) {
            printf("%s\n","Enter filename to get: ");
            scanf("%s", filename);
            success = downl(sock, filename, buf, size, i);
            printf(success ? "File successfully downloaded\n" : "Failed to download the requested file\n");
        } else if(!strcmp(command, "upld")) {
            printf("%s\n","Enter filename to put to server: ");
            scanf("%s", filename);
            success = upld(sock, filename, buf, obj, size);
            printf("%s\n", success ? "File successfully uploaded\n" : "Failed to upload the given file\n");
        } else if(!strcmp(command, "rpwd")) {
            response = rpwd(sock, buf);
            printf("%s%s\n","The current remote directory name is: ", response);
        } else if(!strcmp(command, "rls")) {
            success = rls(sock, buf, size);
            if(success) {
                printf("%s\n","The remote directory listing is as follows:\n");
                system("cat temp.txt");
                system("rm temp.txt");
            }
        } else if(!strcmp(command, "rcd")) {
            printf("%s\n", "Enter the path to change the remote directory: ");
            scanf("%s", filename);
            success = rcd(sock, filename, buf);
            printf("%s\n", success ? "Directory changed successfully !" : "Error when trying to change directory");
        } else if(!strcmp(command, "quit")) {
            success = quit(sock, buf);
            if(success) {
                printf("%s\n", "Server closed\nQuitting..\n");
                return 0;
            }
            printf("%s\n", "Server failed to close the connection\n");
        } else {
            printf("%s\n", "Please choose a choice from the list.");
        }
    }
}
Exemplo n.º 8
0
//
// The main entry point to sipXrls.
//
int main(int argc, char* argv[])
{
   // Configuration Database (used for OsSysLog)
   OsConfigDb configDb;

   UtlString argString;
   for (int argIndex = 1; argIndex < argc; argIndex++)
   {
      osPrintf("arg[%d]: %s\n", argIndex, argv[argIndex]);
      argString = argv[argIndex];
      NameValueTokenizer::frontBackTrim(&argString, "\t ");
      if (argString.compareTo("-v") == 0)
      {
         osPrintf("Version: %s (%s)\n", VERSION, PACKAGE_REVISION);
         return 1;
      }
      else
      {
         osPrintf("usage: %s [-v]\nwhere:\n -v provides the software version\n",
                  argv[0]);
         return 1;
      }
   }

   // Load configuration file.
   OsPath workingDirectory;
   if (OsFileSystem::exists(CONFIG_ETC_DIR))
   {
      workingDirectory = CONFIG_ETC_DIR;
      OsPath path(workingDirectory);
      path.getNativePath(workingDirectory);
   }
   else
   {
      OsPath path;
      OsFileSystem::getWorkingDirectory(path);
      path.getNativePath(workingDirectory);
   }

   UtlString fileName =  workingDirectory +
      OsPathBase::separator +
      CONFIG_SETTINGS_FILE;

   if (configDb.loadFromFile(fileName) != OS_SUCCESS)
   {
      fprintf(stderr, "Failed to load config DB from file '%s'",
              fileName.data());
      exit(1);
   }

   // Initialize log file
   initSysLog(&configDb);

   // Read the user agent parameters from the config file.
   int udpPort;
   if (configDb.get(CONFIG_SETTING_UDP_PORT, udpPort) != OS_SUCCESS)
   {
      udpPort = RLS_DEFAULT_UDP_PORT;
   }

   int tcpPort;
   if (configDb.get(CONFIG_SETTING_TCP_PORT, tcpPort) != OS_SUCCESS)
   {
      tcpPort = RLS_DEFAULT_TCP_PORT;
   }

    UtlString bindIp;
    if (configDb.get(CONFIG_SETTING_BIND_IP, bindIp) != OS_SUCCESS ||
            !OsSocket::isIp4Address(bindIp))
        bindIp = RLS_DEFAULT_BIND_IP;

   UtlString resourceListFile;
   if ((configDb.get(CONFIG_SETTING_RLS_FILE, resourceListFile) !=
        OS_SUCCESS) ||
       resourceListFile.isNull())
   {
      Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                    "Resource list file name is not configured");
      return 1;
   }

   UtlString domainName;
   if ((configDb.get(CONFIG_SETTING_DOMAIN_NAME, domainName) !=
        OS_SUCCESS) ||
       domainName.isNull())
   {
      Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                    "Resource domain name is not configured");
      return 1;
   }

   UtlString realm;
   if ((configDb.get(CONFIG_SETTING_AUTHENTICATE_REALM, realm) !=
        OS_SUCCESS) ||
       realm.isNull())
   {
      Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                    "Resource realm is not configured");
      return 1;
   }

   int resubscribeInterval;
   if (configDb.get(CONFIG_SETTING_RESUBSCRIBE_INTERVAL, resubscribeInterval) != OS_SUCCESS)
   {
      resubscribeInterval = RLS_DEFAULT_RESUBSCRIBE_INTERVAL;
   }

   int minResubscribeInterval;
   if (configDb.get(CONFIG_SETTING_MIN_RESUBSCRIBE_INTERVAL, minResubscribeInterval) != OS_SUCCESS)
   {
       minResubscribeInterval = RLS_DEFAULT_MIN_RESUBSCRIBE_INTERVAL;
   }

   int serverMinExpiration;
   if (configDb.get(CONFIG_SETTING_SERVER_MIN_EXPIRATION, serverMinExpiration) != OS_SUCCESS)
   {
       serverMinExpiration = RLS_DEFAULT_SERVER_MIN_EXPIRATION;
   }

   int serverDefaultExpiration;
   if (configDb.get(CONFIG_SETTING_SERVER_DEFAULT_EXPIRATION, serverDefaultExpiration) != OS_SUCCESS)
   {
       serverDefaultExpiration = RLS_DEFAULT_SERVER_DEFAULT_EXPIRATION;
   }

   int serverMaxExpiration;
   if (configDb.get(CONFIG_SETTING_SERVER_MAX_EXPIRATION, serverMaxExpiration) != OS_SUCCESS)
   {
       serverMaxExpiration = RLS_DEFAULT_SERVER_MAX_EXPIRATION;
   }

   // add the ~~sipXrls credentials so that sipXrls can respond to challenges
   SipLineMgr* lineMgr = addCredentials(domainName, realm);
   if(NULL == lineMgr)
   {
      return 1;
   }

   if (!gShutdownFlag)
   {
      // Initialize the ResourceListServer.
      ResourceListServer rls(domainName, realm, lineMgr,
                             DIALOG_EVENT_TYPE, DIALOG_EVENT_CONTENT_TYPE,
                             tcpPort, udpPort, PORT_NONE, bindIp,
                             &resourceListFile,
                             resubscribeInterval, minResubscribeInterval,
                             RLS_PUBLISH_DELAY,
                             20, 20, 20, 20,
                             serverMinExpiration,
                             serverDefaultExpiration,
                             serverMaxExpiration);
      rls.start();

      // Loop forever until signaled to shut down
      while (!Os::UnixSignals::instance().isTerminateSignalReceived() && !gShutdownFlag)
      {
         OsTask::delay(2000);
         // See if the list configuration file has changed.
         rls.getResourceListFileReader().refresh();
      }

      // Shut down the server.
      rls.shutdown();
   }

   lineMgr->requestShutdown();
   
   while (!lineMgr->isShutDown())
   {
      OsTask::delay(100);
   }
   
   // Delete the LineMgr Object
   delete lineMgr;

   
   // Flush the log file
   Os::Logger::instance().flush();
   
   
		    
   // Say goodnight Gracie...
   return 0;
}
Exemplo n.º 9
0
firms::firms(int n, double money, string model_name, int start)
{
	for (int i = start; i < n + start; i++)
	{
		_firms[i+1] = (firm(money));
	}
	vector<double> fi;
	fi.push_back(104);
	fi.push_back(-1.0/3);
	_rls = rls(fi, matrix(2));
	ofstream fout;
	ostringstream fn;
	for (int i = start + 1; i < n + start + 1; i++)
	{
		fn<<model_name<<"_salary"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";
		fout.close();
		fn.str("");
		fn<<model_name<<"_price"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";
		fout.close();
		fn.str("");;
		fn<<model_name<<"_sold"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";
		fout.close();
		fn.str("");
		fn<<model_name<<"_workers"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";		
		fout.close();
		fn.str("");
		fn<<model_name<<"_money"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";	
		fout.close();
		fn.str("");
		fn<<model_name<<"_profit"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";		
		fout.close();
		fn.str("");
		fn<<model_name<<"_desired"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";		
		fout.close();
		fn.str("");
		fn<<model_name<<"_stock"<<"_firm_"<<i<<".txt";
		fout.open(fn.str(), ios::trunc);
		fout<<"";		
		fout.close();
		fn.str("");
	}
	fn<<model_name<<"_average_price.txt";
	fout.open(fn.str(), ios::trunc);
    fout<<"";
	fout.close();
	fn.str("");
	fn<<model_name<<"_average_salary.txt";
	fout.open(fn.str(), ios::trunc);
	fout<<"";
	fout.close();
	fn.str("");
	fn<<model_name<<"_gdp.txt";
	fout.open(fn.str(), ios::trunc);
	fout<<"";
	fout.close();
	fn.str("");
	fn<<model_name<<"_consumption.txt";
	fout.open(fn.str(), ios::trunc);
	fout<<"";
	fout.close();
	fn.str("");
	fn<<model_name<<"_production.txt";
	fout.open(fn.str(), ios::trunc);
	fout<<"";
	fout.close();
	fn.str("");
	fn<<model_name<<"_firm_number.txt";
	fout.open(fn.str(), ios::trunc);
	fout<<"";
	fout.close();
	fn.str("");
}