IpuImage * ipu_stack_pop() { if (ipu_stack_is_empty()) return NULL; PackElement * pe = (PackElement *)_S->prev; IpuImage * I = (IpuImage *)pe->data; pack_delete(pe); return I; }
int db_put_profile(int node_no, const char *app, struct pack *args) { struct databases db; struct pack *old_args = NULL; int e, ret = -1; char *key = NULL; char *inst_key = NULL; char *inst_value = NULL; char *t, *t2, *data; size_t ts, size; if (open_env(&db, PROFILE_DB)) goto out; while (pack_get(args, &t, &ts)) { if (model_is_instance(node_no, t)) { inst_key = t; pack_get(args, &t, &ts); inst_value = t; } else { pack_get(args, &t, &ts); } } key = make_profile_key(node_no, app, inst_key, inst_value); if (!key) goto out; data = get_data(db.profile, key, &size, &e); // FIXME: handle notfound separately, see also csl.c/c_get_profile() if (e && e != DB_NOTFOUND) goto out; if (!e) { old_args = pack_wrap(data, size); args->pos = 0; while (pack_get(args, &t, &ts)) { pack_get(args,&t2, &ts); pack_replace(old_args, t, t2, ts); } e = put_data(db.profile, key, old_args->buffer, old_args->used); } else { e = put_data(db.profile, key, args->buffer, args->used); } if (e) goto out; ret = 0; out: close_env(&db); if (old_args) pack_delete(old_args); if (key) free(key); return ret; }
char * db_dump_profile(void) { struct databases db; struct pack *p; DBC *cursor = NULL; DBT pair[2]; int e; iks *xml = NULL, *item, *x; char *ret = NULL; memset(&pair[0], 0, sizeof(DBT) * 2); pair[1].flags = DB_DBT_MALLOC; if (open_env(&db, PROFILE_DB)) goto out; db.profile->cursor(db.profile, NULL, &cursor, 0); xml = iks_new("comarProfile"); iks_insert_cdata(xml, "\n", 1); while ((e = cursor->c_get(cursor, &pair[0], &pair[1], DB_NEXT)) == 0) { char *t; size_t ts; item = iks_insert(xml, "item"); iks_insert_cdata(iks_insert(item, "key"), pair[0].data, pair[0].size); p = pack_wrap(pair[1].data, pair[1].size); while (pack_get(p, &t, &ts)) { iks_insert_cdata(item, "\n", 1); x = iks_insert(item, "data"); iks_insert_attrib(x, "key", t); pack_get(p, &t, &ts); iks_insert_cdata(iks_insert(x, "value"), t, ts); } pack_delete(p); iks_insert_cdata(xml, "\n", 1); } if (e != DB_NOTFOUND) { goto out; } ret = iks_string(NULL, xml); out: if (cursor) cursor->c_close(cursor); close_env(&db); if (xml) iks_delete(xml); return ret; }
static int do_call(int node, struct pack *pak) { struct pack *p = NULL; char *apps; int ok = 0; log_debug(LOG_JOB, "Call(%s)\n", model_get_path(node)); if (model_flags(node) & P_GLOBAL) { p = pack_dup(pak); } if (db_get_apps(model_parent(node), &apps) != 0) { send_result(CMD_NONE, "noapp", 5); // FIXME: ok diyecek betik yoksa profile kayıt etmeli mi acaba exit(1); } if (strchr(apps, '/') == NULL) { // there is only one script if (0 == do_execute(node, apps, pak)) ok = 1; } else { // multiple scripts, run concurrently char *t, *s; struct ProcChild *p; int cmd; int cnt = 0; size_t size; // FIXME: package count send_result(CMD_RESULT_START, NULL, 0); for (t = apps; t; t = s) { s = strchr(t, '/'); if (s) { *s = '\0'; ++s; } bk_node = node; bk_app = t; bk_pak = pak; p = proc_fork(exec_proc, "ComarSubJob"); if (p) { ++cnt; } else { send_result(CMD_ERROR, "fork failed", 11); } } while(1) { struct ipc_struct ipc; struct pack *pak; pak = pack_new(128); proc_listen(&p, &cmd, &size, -1); if (cmd == CMD_FINISH) { --cnt; if (!cnt) break; } else { if (cmd == CMD_RESULT) ok++; proc_get(p, &ipc, pak, size); proc_put(TO_PARENT, cmd, &ipc, pak); } } send_result(CMD_RESULT_END, NULL, 0); } if ((model_flags(node) & P_GLOBAL) && ok) { db_put_profile(node, NULL, p); pack_delete(p); } return 0; }
static int do_execute(int node, const char *app, struct pack *pak) { struct timeval start, end; unsigned long msec; struct pack *p = NULL; char *code; char *res; size_t code_size; size_t res_size; int e; log_debug(LOG_JOB, "Execute(%s,%s)\n", model_get_path(node), app); bk_app = strdup(app); bk_node = node; if (model_flags(node) & P_PACKAGE) { p = pack_dup(pak); } csl_setup(); if (0 != db_get_code(model_parent(node), app, &code, &code_size)) { send_result(CMD_NONE, "noapp", 5); return -1; } gettimeofday(&start, NULL); e = csl_execute(code, code_size, model_get_method(node), pak, &res, &res_size); gettimeofday(&end, NULL); if (e) { if (e == CSL_NOFUNC) send_result(CMD_NONE, "nomethod", 8); else send_result(CMD_ERROR, "err", 3); } else { send_result(CMD_RESULT, res, res_size); free(res); } msec = time_diff(&start, &end); if (msec > 60*1000) { log_info("Script %s took %d seconds for %s call.\n", bk_app, msec / 1000, model_get_path(node)); } else { log_debug(LOG_PERF, "Script %s took %d miliseconds for %s call.\n", bk_app, msec, model_get_path(node)); } if (model_flags(node) & P_PACKAGE) { if (0 == e) { if (model_flags(node) & P_DELETE) db_del_profile(node, bk_app, p); else db_put_profile(node, bk_app, p); } pack_delete(p); } csl_cleanup(); return e; }