aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-15 09:02:08 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-15 09:02:08 +0000
commit23372aee7dc3347c4098c7a041271799794bd61f (patch)
treeeb07004034f8863f7950d1dfcb8444719647857b
parentf5cfe33fcee3bc563c5dc20463845197fa70d984 (diff)
downloadgnunet-23372aee7dc3347c4098c7a041271799794bd61f.tar.gz
gnunet-23372aee7dc3347c4098c7a041271799794bd61f.zip
- new program_run and run_2
-rw-r--r--src/include/gnunet_program_lib.h22
-rw-r--r--src/util/program.c41
2 files changed, 59 insertions, 4 deletions
diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h
index 48d5280ee..5bce4820b 100644
--- a/src/include/gnunet_program_lib.h
+++ b/src/include/gnunet_program_lib.h
@@ -60,6 +60,28 @@ typedef void (*GNUNET_PROGRAM_Main) (void *cls, char *const *args,
60 * @param argc number of command line arguments 60 * @param argc number of command line arguments
61 * @param argv command line arguments 61 * @param argv command line arguments
62 * @param binaryName our expected name 62 * @param binaryName our expected name
63 * @param binaryHelp help text for the program
64 * @param options command line options
65 * @param task main function to run
66 * @param task_cls closure for task
67 * @param run_with_schedule GNUNET_YES start the scheduler, GNUNET_NO do not
68 * start the scheduler just run the main task
69 * @return GNUNET_SYSERR on error, GNUNET_OK on success
70 */
71int
72GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
73 const char *binaryHelp,
74 const struct GNUNET_GETOPT_CommandLineOption *options,
75 GNUNET_PROGRAM_Main task, void *task_cls,
76 int run_with_schedule);
77
78/**
79 * Run a standard GNUnet command startup sequence (initialize loggers
80 * and configuration, parse options).
81 *
82 * @param argc number of command line arguments
83 * @param argv command line arguments
84 * @param binaryName our expected name
63 * @param binaryHelp helptext for "-h" option (about the app) 85 * @param binaryHelp helptext for "-h" option (about the app)
64 * @param options command line options 86 * @param options command line options
65 * @param task main function to run 87 * @param task main function to run
diff --git a/src/util/program.c b/src/util/program.c
index 6a0e5a555..597bd7584 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -125,13 +125,16 @@ cmd_sorter (__const void *a1, __const void *a2)
125 * @param options command line options 125 * @param options command line options
126 * @param task main function to run 126 * @param task main function to run
127 * @param task_cls closure for task 127 * @param task_cls closure for task
128 * @param run_with_schedule GNUNET_NO start the scheduler, GNUNET_YES do not
129 * start the scheduler just run the main task
128 * @return GNUNET_SYSERR on error, GNUNET_OK on success 130 * @return GNUNET_SYSERR on error, GNUNET_OK on success
129 */ 131 */
130int 132int
131GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, 133GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
132 const char *binaryHelp, 134 const char *binaryHelp,
133 const struct GNUNET_GETOPT_CommandLineOption *options, 135 const struct GNUNET_GETOPT_CommandLineOption *options,
134 GNUNET_PROGRAM_Main task, void *task_cls) 136 GNUNET_PROGRAM_Main task, void *task_cls,
137 int run_with_schedule)
135{ 138{
136 struct CommandContext cc; 139 struct CommandContext cc;
137 char *path; 140 char *path;
@@ -247,8 +250,15 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
247 } 250 }
248 /* run */ 251 /* run */
249 cc.args = &argv[ret]; 252 cc.args = &argv[ret];
250 GNUNET_SCHEDULER_run (&program_main, &cc); 253 if (GNUNET_NO == run_with_schedule)
251 254 {
255 GNUNET_SCHEDULER_run (&program_main, &cc);
256 }
257 else
258 {
259 GNUNET_RESOLVER_connect (cc.cfg);
260 cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg);
261 }
252 /* clean up */ 262 /* clean up */
253 GNUNET_CONFIGURATION_destroy (cfg); 263 GNUNET_CONFIGURATION_destroy (cfg);
254 GNUNET_free_non_null (cc.cfgfile); 264 GNUNET_free_non_null (cc.cfgfile);
@@ -257,5 +267,28 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
257 return GNUNET_OK; 267 return GNUNET_OK;
258} 268}
259 269
270/**
271 * Run a standard GNUnet command startup sequence (initialize loggers
272 * and configuration, parse options).
273 *
274 * @param argc number of command line arguments
275 * @param argv command line arguments
276 * @param binaryName our expected name
277 * @param binaryHelp help text for the program
278 * @param options command line options
279 * @param task main function to run
280 * @param task_cls closure for task
281 * @return GNUNET_SYSERR on error, GNUNET_OK on success
282 */
283int
284GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
285 const char *binaryHelp,
286 const struct GNUNET_GETOPT_CommandLineOption *options,
287 GNUNET_PROGRAM_Main task, void *task_cls)
288{
289 return GNUNET_PROGRAM_run2 (argc, argv, binaryName, binaryHelp, options, task, task_cls, GNUNET_NO);
290}
291
292
260 293
261/* end of program.c */ 294/* end of program.c */