4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
28 #include <sys/types.h>
50 #define ROOT_RUNNERS_COUNT 32
51 #define MAX_RUNNER_COUNT 32767
53 static struct apprun *runners[ROOT_RUNNERS_COUNT];
54 static int runnercount = 0;
55 static int runnerid = 0;
57 static struct apprun *getrunner(int id)
59 struct apprun *result = runners[id & (ROOT_RUNNERS_COUNT - 1)];
60 while (result && result->id != id)
61 result = result->next;
65 static void freerunner(struct apprun *runner)
67 struct apprun **prev = &[runner->id & (ROOT_RUNNERS_COUNT - 1)];
69 while(*prev != runner) {
70 prev = &(*prev)->next;
78 static struct apprun *createrunner()
80 struct apprun *result;
82 if (runnercount >= MAX_RUNNER_COUNT)
86 if (runnerid > MAX_RUNNER_COUNT)
88 } while(getrunner(runnerid));
89 result = malloc(sizeof * result);
91 result->id = runnerid;
92 result->state = as_in_progress;
95 result->next = runners[runnerid & (ROOT_RUNNERS_COUNT - 1)];
96 runners[runnerid & (ROOT_RUNNERS_COUNT - 1)] = result;
102 int appfwk_run_start(struct json_object *appli)
106 int appfwk_run_stop()
111 static struct json_object *mkrunner(const char *appid, const char *runid)
113 struct json_object *result = json_object_new_object();
115 if(json_add_str(result, "id", appid)
116 || json_add_str(result, "runid", runid)
117 || json_add_str(result, "state", NULL)) {
118 json_object_put(result);
125 const char *appfwk_start(struct appfwk *af, const char *appid)
127 struct json_object *appli;
128 struct json_object *runner;
131 /* get the application description */
132 appli = appfwk_get_application(af, appid);
138 /* prepare the execution */
139 snprintf(buffer, sizeof buffer, "{\"id\":\"%s\",\"runid\":\"%s\"
142 int appfwk_stop(struct appfwk *af, const char *runid)
144 struct json_object *runner;
145 runner = appfwk_state(af, runid);
146 if (runner == NULL) {
150 json_object_get(runner);
151 json_object_object_del(af->runners, runid);
165 json_object_put(runner);
168 int appfwk_suspend(struct appfwk *af, const char *runid)
172 int appfwk_resume(struct appfwk *af, const char *runid)
176 struct json_object *appfwk_running_list(struct appfwk *af)
181 struct json_object *appfwk_state(struct appfwk *af, const char *runid)
183 struct json_object *result;
184 int status = json_object_object_get_ex(af->runners, runid, &result);
185 return status ? result : NULL;
194 #if defined(TESTAPPFWK)
198 struct appfwk *af = appfwk_create();
199 appfwk_add_root(af,FWK_APP_DIR);
200 appfwk_update_applications(af);
201 printf("array = %s\n", json_object_to_json_string_ext(af->applications.pubarr, 3));
202 printf("direct = %s\n", json_object_to_json_string_ext(af->applications.direct, 3));
203 printf("byapp = %s\n", json_object_to_json_string_ext(af->applications.byapp, 3));