Exemplo n.º 1
0
bool CLTool::readInput( int argc, char**argv, FILE* in, FILE*out ){
  plumed_massert( inputdata!=unset,"You have not specified where your tool reads its input. "
                                   "If it is from the command line (like driver) add inputdata=commandline to the "
                                   "tools constructor. If it reads everything from an input file (like simplemd) "
                                   "add inputdata=ifile to the tools constructor");
  if(inputdata==commandline) return readCommandLineArgs( argc, argv, out );
  if(inputdata==ifile) return readInputFile( argc, argv, in, out );
  return true;
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
    /* save in case of crash */
    g_argc = argc;
    g_argv = argv;

    readCommandLineArgs(argc, argv);
    init_motes();

    // NOTREACHED
    return (EXIT_FAILURE);      // should never get here
}
Exemplo n.º 3
0
int
main(int argc, char **argv)
{
    static char	namebuf[1024];	/* space for tuple */
    static char	namebuf2[1024];	/* space for tuple */
    BUNDLE_AGENT	ba;
    BUNDLE_SPEC	bs;
    BUNDLE_TUPLE	tuple = { { 0, namebuf} , 0 };
    BUNDLE_TUPLE	dst = { { 0, namebuf2}, 0};
    BUNDLE_WAITING	bw;
    BUNDLE_ITERATOR iterator = BUNDLE_ITERATOR_NONE  ;
    uint32_t	reg_cookie = BUNDLE_REG_COOKIE_NONE;

    //
    // Read any defaults of out $HOME/.snd_bundlerc
    //
    readResourceFile();

    //
    // Read off the command arguments
    //
    readCommandLineArgs(argc, argv);

    if ( debug>4 ) {
        writeDefaultsFile(1); // Write to stderr
    }

    //
    // Sanity check parameters
    //
    if ( theSource==0 ) {
        usage("snd_bundle", "-s option is required.");
        exit(EXIT_FAILURE);
    }

    if ( (theSource==2 || theSource==3) && (strlen(fname)==0) ) {
        usage("snd_bundle", "");
        fprintf(stderr, "theSource (%d) specifies sending from file\n", theSource);
        fprintf(stderr, "but no [-f file_name] option given.\n");
        exit(EXIT_FAILURE);
    }

    //
    // Open connection to bundle agent.
    //
    if ( debug>0 ) {
        printf("SND BUNDLE:  ***opening bundle agent on host %s\n", bahost);
    }
    if ((ba = open_agent(bahost)) == NULL) {
        fprintf(stderr, "couldn't contact bundle daemon on %s\n", bahost);
        exit(1);
    }
    if ( debug>1 ) {
        printf("    Bundle agent on host %s open.\n", bahost);
    }

    //
    // Local tuple
    //
    if ( debug>0 ) {
        printf("snd_bundle: building local tuple with localstuff: '%s'\n",
               localstuff);
    }
    //
    // If the user specified a source region and source admin part, use those,
    // otherwise call local_tuple which will use one of our regions (the first
    // it finds in the config file) and our hostname.
    //
    if ( strlen(sourceIntf)>0 ) {
        if ( local_tuple(ba, sourceIntf, localstuff, &tuple) < 0 ) {
            fprintf(stderr, "trouble building local tuple with source (%s, %s)\n",
                    sourceIntf, localstuff);
            exit(EXIT_FAILURE);
        }
    } else {
        if (local_tuple(ba, NULL, localstuff, &tuple) < 0) {
            fprintf(stderr, "trouble building tuple with local stuff %s\n", localstuff);
            exit(EXIT_FAILURE);
        }
    }
    if ( debug>0 ) {
        print_tuple(tuple);
    }


    //
    // Destination tuple
    //
    if ( debug>0 ) {
        printf("snd_bundle: building destination tuple: (%s)\n",
               destTuple);
    }
    if (remote_tuple(destTuple, &dst) < 0) {
        fprintf(stderr, "trouble building destination tuple\n");
        exit(1);
    }
    if ( debug>0 ) {
        print_tuple(dst);
    }

    // Register the local tuple (dest demux string of inbound bundles)
    // in expectation of receiving responses to what we're going to
    // send.
    if ( pollForResponse ) {
        if ( debug>0 ) printf("registering tuple...");
        if (demux_register(ba, tuple, BUNDLE_REG_ABORT, &reg_cookie) < 0) {
            fprintf(stderr, "trouble registering tuple\n");
            exit(1);
        }
        if ( debug>1 ) printf("ok, cookie was 0x%x\n", reg_cookie);
    }

    while ( timesToLoop-->0 ) {
        //
        // Send a bundle from memory
        //
        if ( theSource==1 || theSource==3 ) {
            if ( debug>0 ) {
                printf("sending bundle from memory...\n");
            }
            /* build a bundle spec */
            if (bundle_spec(COS_NORMAL, COS_NONE, tuple, dst, tuple, expire, &bs) < 0) {
                fprintf(stderr, "trouble building bundle_spec\n");
                exit(1);
            }
            /* send the bundle with the spec */
            if (send_bundle_mem(ba, bs, bundle_data, strlen(bundle_data)) < 0) {
                fprintf(stderr, "trouble sending bundle from memory\n");
                exit(1);
            }
        }

        //
        // Send a bundle from a file
        //
        if ( theSource==2 || theSource==3 ) {
            if ( debug>0 ) {
                printf("sending bundle from file...\n");
            }
            if (bundle_spec(COS_NORMAL, COS_NONE, tuple, dst, tuple, expire, &bs) < 0) {
                fprintf(stderr, "trouble building bundle_spec\n");
                exit(EXIT_FAILURE);
            }
            if (send_bundle_file(ba, bs, fname) < 0) {
                fprintf(stderr, "trouble sending bundle from file '%s'\n", fname);
                exit(EXIT_FAILURE);
            }
        }
    }

    //
    // If we were looking for a response, here's how to poll
    //
    if ( pollForResponse ) {
        if ( debug>0 ) printf("Sleeping for a bit...\n");
        sleep(15);
        if ( debug>0 ) {
            printf("polling for tuple:\n");
            print_tuple(tuple);
        }

        while (bundle_poll(ba, tuple, &iterator, &bw) == BUNDLE_SUCCESS) {
            printf("yup, got a bundle at %s\n", bw.filename.filename_val);
            printf("with bundle spec:\n");
            print_bundle_spec(bw.bs);
        }
        printf("no more incoming bundles...\n");
        printf("unregistering tuple...\n");
        if (demux_register_cancel(ba, reg_cookie) < 0) {
            fprintf(stderr, "trouble unregistering tuple\n");
            exit(1);
        }
    }

    if ( debug>0 ) {
        printf("\n***all done (success)\n");
    }
    close_agent(ba);

    if ( writeResourceFile ) {
        writeDefaultsFile(0);
    }
    exit(0);
}
Exemplo n.º 4
0
int
main(int argc, char** argv)
{
	static char	namebuf[1024];	/* space for tuple */
	BUNDLE_AGENT	ba;
	BUNDLE_TUPLE	tuple = { { 0, namebuf} , 0 };
	BUNDLE_WAITING	bw;
	int first_time = 1;

	int 		c, ret;
        int 		received_bundle_count = 0;


	//
	// Read any defaults of out $HOME/.polling_rcvrrc
	// 
	readResourceFile();

	//
	// Read off the command arguments
	//
	readCommandLineArgs(argc, argv);

	if ( debug>4 ) {
	  writeDefaultsFile(1); // Write to stderr
	}

	//
	// Sanity check arguments
	//
	if ( strlen(bahost)==0 ) {
	  usage("polling_rcvr", "bundleAgent required");
	  exit(-1);
	}
	if ( strlen(demuxString)==0 ) {
	  usage("polling_rcvr", "demuxString required.\n");
	  exit(-1);
	}

	//
	// Open connection to bundle agent.
	//
	if ( debug>0) {
	  printf("polling_rcvr: ***opening bundle agent on host %s\n", bahost);
	}
	if ((ba = open_agent(bahost)) == NULL) {
		fprintf(stderr, "couldn't contact bundle daemon on %s\n", bahost);
		exit(1);
	}
	if ( debug>1 ) {
	  printf("    Bundle agent open.\n");
	}

	/* API doesn't do mem alloc for us; we must do it */
	if ( strlen(matchstr)>0 ) {
	  	if ( debug>0 ) printf("creating local tuple with name...\n");
		if (local_tuple(ba, matchstr, localstuff, &tuple) < 0) {
			fprintf(stderr, "trouble building tuple with source matchstr %s\n",
					matchstr);
			exit(1);
	        }
	} else {
	        if ( debug>0 ) printf("creating local tuple...\n");
		if (local_tuple(ba, NULL, localstuff, &tuple) < 0) {
			fprintf(stderr, "trouble building tuple with localstuff %s\n", localstuff);
			exit(1);
		}
	}

	if ( debug>0 ) {
	  print_tuple(tuple);
	}

	if ( debug>0 ) {
	  printf("polling for tuple:\n");
	  print_tuple(tuple);
	}

	for (c = 0; c < timesToPoll; c++ ) {
	     if ((ret =
		bundle_poll(ba, tuple, &iterator, &bw)) == BUNDLE_SUCCESS) {
		if (first_time == 1) {
		  if ( debug>0 ) printf("Bundle poll iterator set to %d\n", iterator);
		  first_time = 0;
		}
		received_bundle_count++;
		if ( debug>0 ) {
		  printf("yup, got a bundle[%d] at %s\n", 
			 received_bundle_count, bw.filename.filename_val);
		  //printf("with bundle spec:\n");
		  //print_bundle_spec(bw.bs);
		  //printf("and iterator 0x%x\n", iterator);
		}
	     } else { 
		if (first_time == 1) {
		  if ( debug>0 ) printf("Bundle poll iterator set to %d\n", iterator);
		  first_time = 0;
		}
		if ( debug>0 ) {
		  printf(".");
		  fflush(stdout);
		}
		sleep(1);
	     }

	}
	if ( debug>0 ) {
	  printf("I'm tired of waiting for bundles...\n");
	  printf("\n***all done (success)\n");
	}
	close_agent(ba);
	
	if ( writeResourceFile ) {
	  writeDefaultsFile(0);
	}
	exit(0);
}