diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-05 09:56:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-05 09:56:25 +0000 |
commit | d75fb1880a887a8f5339c5e8cf5e9d2b8755fdad (patch) | |
tree | f8dff53b4b88b0d87ca31a772607ee51fb0653ec /src/arm/gnunet-arm.c | |
parent | b9b0940e261a4b1713d909f0a2fd54134ed5b148 (diff) | |
download | gnunet-d75fb1880a887a8f5339c5e8cf5e9d2b8755fdad.tar.gz gnunet-d75fb1880a887a8f5339c5e8cf5e9d2b8755fdad.zip |
improving ARM API
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r-- | src/arm/gnunet-arm.c | 152 |
1 files changed, 129 insertions, 23 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 740fd2533..09a1305a5 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -65,7 +65,46 @@ static char *test; | |||
65 | */ | 65 | */ |
66 | static int ret; | 66 | static int ret; |
67 | 67 | ||
68 | /** | ||
69 | * Connection with ARM. | ||
70 | */ | ||
71 | static struct GNUNET_ARM_Handle *h; | ||
72 | |||
73 | /** | ||
74 | * Our scheduler. | ||
75 | */ | ||
76 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
77 | |||
78 | /** | ||
79 | * Our configuration. | ||
80 | */ | ||
81 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
82 | |||
83 | /** | ||
84 | * Processing stage that we are in. Simple counter. | ||
85 | */ | ||
86 | static unsigned int phase; | ||
87 | |||
68 | 88 | ||
89 | /** | ||
90 | * Main continuation-passing-style loop. Runs the various | ||
91 | * jobs that we've been asked to do in order. | ||
92 | * | ||
93 | * @param cls closure, unused | ||
94 | * @param tc context, unused | ||
95 | */ | ||
96 | static void | ||
97 | cps_loop (void *cls, | ||
98 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Callback invoked with the status of the last operation. Reports to the | ||
103 | * user and then runs the next phase in the FSM. | ||
104 | * | ||
105 | * @param cls pointer to "const char*" identifying service that was manipulated | ||
106 | * @param success GNUNET_OK if service is now running, GNUNET_NO if not, GNUNET_SYSERR on error | ||
107 | */ | ||
69 | static void | 108 | static void |
70 | confirm_cb (void *cls, int success) | 109 | confirm_cb (void *cls, int success) |
71 | { | 110 | { |
@@ -83,9 +122,21 @@ confirm_cb (void *cls, int success) | |||
83 | _("Error updating service `%s': ARM not running\n"), service); | 122 | _("Error updating service `%s': ARM not running\n"), service); |
84 | break; | 123 | break; |
85 | } | 124 | } |
125 | GNUNET_SCHEDULER_add_continuation (sched, | ||
126 | GNUNET_NO, | ||
127 | &cps_loop, | ||
128 | NULL, | ||
129 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
86 | } | 130 | } |
87 | 131 | ||
88 | 132 | ||
133 | /** | ||
134 | * Function called to confirm that a service is running (or that | ||
135 | * it is not running). | ||
136 | * | ||
137 | * @param cls pointer to "const char*" identifying service that was manipulated | ||
138 | * @param tc reason determines if service is now running | ||
139 | */ | ||
89 | static void | 140 | static void |
90 | confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 141 | confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
91 | { | 142 | { |
@@ -95,6 +146,11 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
95 | fprintf (stdout, _("Service `%s' is running.\n"), service); | 146 | fprintf (stdout, _("Service `%s' is running.\n"), service); |
96 | else | 147 | else |
97 | fprintf (stdout, _("Service `%s' is not running.\n"), service); | 148 | fprintf (stdout, _("Service `%s' is not running.\n"), service); |
149 | GNUNET_SCHEDULER_add_continuation (sched, | ||
150 | GNUNET_NO, | ||
151 | &cps_loop, | ||
152 | NULL, | ||
153 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
98 | } | 154 | } |
99 | 155 | ||
100 | 156 | ||
@@ -102,40 +158,90 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
102 | * Main function that will be run by the scheduler. | 158 | * Main function that will be run by the scheduler. |
103 | * | 159 | * |
104 | * @param cls closure | 160 | * @param cls closure |
105 | * @param sched the scheduler to use | 161 | * @param s the scheduler to use |
106 | * @param args remaining command-line arguments | 162 | * @param args remaining command-line arguments |
107 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | 163 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) |
108 | * @param cfg configuration | 164 | * @param c configuration |
109 | */ | 165 | */ |
110 | static void | 166 | static void |
111 | run (void *cls, | 167 | run (void *cls, |
112 | struct GNUNET_SCHEDULER_Handle *sched, | 168 | struct GNUNET_SCHEDULER_Handle *s, |
113 | char *const *args, | 169 | char *const *args, |
114 | const char *cfgfile, | 170 | const char *cfgfile, |
115 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 171 | const struct GNUNET_CONFIGURATION_Handle *c) |
116 | { | 172 | { |
117 | if (term != NULL) | 173 | sched = s; |
118 | { | 174 | cfg = c; |
119 | GNUNET_ARM_stop_service (term, cfg, sched, TIMEOUT, &confirm_cb, term); | 175 | h = GNUNET_ARM_connect (cfg, sched, NULL); |
120 | } | 176 | if (h == NULL) |
121 | if (end) | ||
122 | { | ||
123 | GNUNET_ARM_stop_service ("arm", | ||
124 | cfg, sched, TIMEOUT, &confirm_cb, "arm"); | ||
125 | } | ||
126 | if (start) | ||
127 | { | 177 | { |
128 | GNUNET_ARM_start_service ("arm", | 178 | fprintf (stderr, |
129 | cfg, sched, TIMEOUT, &confirm_cb, "arm"); | 179 | _("Fatal error initializing ARM API.\n")); |
180 | ret = 1; | ||
181 | return; | ||
130 | } | 182 | } |
131 | if (init != NULL) | 183 | GNUNET_SCHEDULER_add_continuation (sched, |
132 | { | 184 | GNUNET_NO, |
133 | GNUNET_ARM_start_service (init, cfg, sched, TIMEOUT, &confirm_cb, init); | 185 | &cps_loop, |
134 | } | 186 | NULL, |
135 | if (test != NULL) | 187 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
188 | } | ||
189 | |||
190 | |||
191 | /** | ||
192 | * Main continuation-passing-style loop. Runs the various | ||
193 | * jobs that we've been asked to do in order. | ||
194 | * | ||
195 | * @param cls closure, unused | ||
196 | * @param tc context, unused | ||
197 | */ | ||
198 | static void | ||
199 | cps_loop (void *cls, | ||
200 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
201 | { | ||
202 | while (1) | ||
136 | { | 203 | { |
137 | GNUNET_CLIENT_service_test (sched, | 204 | switch (phase++) |
138 | test, cfg, TIMEOUT, &confirm_task, test); | 205 | { |
206 | case 0: | ||
207 | if (term != NULL) | ||
208 | { | ||
209 | GNUNET_ARM_stop_service (h, term, TIMEOUT, &confirm_cb, term); | ||
210 | return; | ||
211 | } | ||
212 | break; | ||
213 | case 1: | ||
214 | if (end) | ||
215 | { | ||
216 | GNUNET_ARM_stop_service (h, "arm", TIMEOUT, &confirm_cb, "arm"); | ||
217 | return; | ||
218 | } | ||
219 | break; | ||
220 | case 2: | ||
221 | if (start) | ||
222 | { | ||
223 | GNUNET_ARM_start_service (h, "arm", TIMEOUT, &confirm_cb, "arm"); | ||
224 | return; | ||
225 | } | ||
226 | break; | ||
227 | case 3: | ||
228 | if (init != NULL) | ||
229 | { | ||
230 | GNUNET_ARM_start_service (h, init, TIMEOUT, &confirm_cb, init); | ||
231 | return; | ||
232 | } | ||
233 | break; | ||
234 | case 4: | ||
235 | if (test != NULL) | ||
236 | { | ||
237 | GNUNET_CLIENT_service_test (sched, test, cfg, TIMEOUT, &confirm_task, test); | ||
238 | return; | ||
239 | } | ||
240 | break; | ||
241 | default: /* last phase */ | ||
242 | GNUNET_ARM_disconnect (h); | ||
243 | return; | ||
244 | } | ||
139 | } | 245 | } |
140 | } | 246 | } |
141 | 247 | ||