summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
Diffstat (limited to 'binding')
-rw-r--r--binding/task-manager-binding.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/binding/task-manager-binding.c b/binding/task-manager-binding.c
index 6b4c80c..d3ce89d 100644
--- a/binding/task-manager-binding.c
+++ b/binding/task-manager-binding.c
@@ -10,7 +10,7 @@
#include <signal.h>
#include <errno.h>
-#define AFB_BINDING_VERSION 2
+#define AFB_BINDING_VERSION 3
#include <afb/afb-binding.h>
struct pstat {
@@ -32,12 +32,12 @@ struct process_container {
struct pstat pstat_values;
};
-void get_process_list(struct afb_req request);
+void get_process_list(afb_req_t request);
int fill_pstat(proc_t *proc_info, struct pstat *pstat);
void cpu_calculate(struct pstat*, struct pstat*, struct cpu_percentage *perc);
void fill_process_container(char* process_name, int euid, struct pstat *pstat_values, struct process_container *pc);
-void get_process_list(struct afb_req request){
+void get_process_list(afb_req_t request){
struct pstat last_pstat_values, cur_pstat_values;
struct cpu_percentage cpu_usage;
@@ -52,7 +52,7 @@ void get_process_list(struct afb_req request){
PROCTAB* proc = openproc(PROC_FILLMEM | PROC_FILLSTAT);
if (!proc){
AFB_REQ_ERROR(request, "Unable to open /proc!");
- afb_req_fail(request, "Failed", "Error processing arguments.");
+ afb_req_reply(request, NULL, "Failed", "Error processing arguments.");
return;
}
@@ -80,7 +80,7 @@ void get_process_list(struct afb_req request){
proc = openproc(PROC_FILLMEM | PROC_FILLSTAT);
if (!proc){
AFB_REQ_ERROR(request, "Unable to open /proc!");
- afb_req_fail(request, "Failed", "Error processing arguments.");
+ afb_req_reply(request, NULL, "Failed", "Error processing arguments.");
return;
}
@@ -108,12 +108,12 @@ void get_process_list(struct afb_req request){
}
json_object_object_add(ret_json, "msgType", json_object_new_string("processList"));
json_object_object_add(ret_json, "processes", json_array);
- afb_req_success(request, ret_json, NULL);
+ afb_req_reply(request, ret_json, NULL, NULL);
closeproc(proc);
}
-void kill_process(struct afb_req request)
+void kill_process(afb_req_t request)
{
struct json_object *ret_json;
ret_json = json_object_new_object();
@@ -125,11 +125,11 @@ void kill_process(struct afb_req request)
/* XXX: add checks */
ret = kill(tid, SIGTERM);
if (ret < 0)
- afb_req_fail_f(request, "Failed", "Error %d", errno);
+ afb_req_reply_f(request, NULL, "Failed", "Error %d", errno);
/* we don't signal success, there's no use for it */
}
-void get_extra_info(struct afb_req request)
+void get_extra_info(afb_req_t request)
{
struct json_object *ret_json, *json_obj;
json_object *req = afb_req_json(request);
@@ -146,7 +146,7 @@ void get_extra_info(struct afb_req request)
FILE *fsched = fopen(path, "r");
if (fsched == NULL) {
- afb_req_fail(request, "Failed", "Error processing arguments.");
+ afb_req_reply(request, NULL, "Failed", "Error processing arguments.");
return;
}
else {
@@ -173,10 +173,10 @@ void get_extra_info(struct afb_req request)
json_object_object_add(ret_json, "msgType", json_object_new_string("extraInfo"));
json_object_object_add(ret_json, "info", json_obj);
- afb_req_success(request, ret_json, NULL);
+ afb_req_reply(request, ret_json, NULL, NULL);
}
-void get_load_avg(struct afb_req request)
+void get_load_avg(afb_req_t request)
{
struct json_object *ret_json, *json_obj;
float value = 1.;
@@ -187,7 +187,7 @@ void get_load_avg(struct afb_req request)
FILE *floadAvg = fopen("/proc/loadavg", "r");
if (floadAvg == NULL) {
- afb_req_fail(request, "Failed", "Error processing arguments.");
+ afb_req_reply(request, NULL, "Failed", "Error processing arguments.");
return;
}
else {
@@ -201,10 +201,10 @@ void get_load_avg(struct afb_req request)
}
fclose(floadAvg);
- afb_req_success(request, ret_json, NULL);
+ afb_req_reply(request, ret_json, NULL, NULL);
}
-void get_netstat(struct afb_req request)
+void get_netstat(afb_req_t request)
{
struct json_object *ret_json, *json_obj;
char names_str[1024], values_str[1024];
@@ -213,7 +213,7 @@ void get_netstat(struct afb_req request)
FILE *fnetstat = fopen("/proc/net/netstat", "r");
if (fnetstat == NULL) {
- afb_req_fail(request, "Failed", "Error processing arguments.");
+ afb_req_reply(request, NULL, "Failed", "Error processing arguments.");
return;
}
@@ -222,13 +222,13 @@ void get_netstat(struct afb_req request)
} while (pnames && !feof(fnetstat) && strncmp(pnames, "IpExt: ", 7));
if (feof(fnetstat)) {
fclose(fnetstat);
- afb_req_fail(request, "Failed", "Parse error");
+ afb_req_reply(request, NULL, "Failed", "Parse error");
return;
}
pvalues = fgets(pvalues, 1024, fnetstat);
fclose(fnetstat);
if (pvalues == NULL) {
- afb_req_fail(request, "Failed", "Parse error");
+ afb_req_reply(request, NULL, "Failed", "Parse error");
return;
}
@@ -248,7 +248,7 @@ void get_netstat(struct afb_req request)
json_object_object_add(ret_json, "msgType", json_object_new_string("netStatInfo"));
json_object_object_add(ret_json, "netstat", json_obj);
- afb_req_success(request, ret_json, NULL);
+ afb_req_reply(request, ret_json, NULL, NULL);
}
int fill_pstat(proc_t *proc_info, struct pstat *pstat_values)
@@ -303,49 +303,50 @@ void fill_process_container(char *process_name, int euid, struct pstat *pstat_va
pc->pstat_values = *pstat_values;
}
-static const struct afb_verb_v2 _afb_verbs_v2_taskmanager[] = {
+static const afb_verb_t _afb_verbs_taskmanager[] = {
{
.verb = "get_process_list",
.callback = get_process_list,
.auth = NULL,
.info = "Get an array of all processes currently running on the system",
- .session = AFB_SESSION_NONE_V2
+ .session = AFB_SESSION_NONE
},
{
.verb = "kill_process",
.callback = kill_process,
.auth = NULL,
.info = "Kill the process specified by tid",
- .session = AFB_SESSION_NONE_V2
+ .session = AFB_SESSION_NONE
},
{
.verb = "get_extra_info",
.callback = get_extra_info,
.auth = NULL,
.info = "Get exta info about current process",
- .session = AFB_SESSION_NONE_V2
+ .session = AFB_SESSION_NONE
},
{
.verb = "get_load_avg",
.callback = get_load_avg,
.auth = NULL,
.info = "Get exta info about system load average",
- .session = AFB_SESSION_NONE_V2
+ .session = AFB_SESSION_NONE
},
{
.verb = "get_netstat",
.callback = get_netstat,
.auth = NULL,
.info = "Get network (IP) statistics",
- .session = AFB_SESSION_NONE_V2
+ .session = AFB_SESSION_NONE
},
+ { .verb = NULL }
};
-const struct afb_binding_v2 afbBindingV2 = {
+const afb_binding_t afbBindingExport = {
.api = "taskmanager",
.specification = NULL,
.info = "Task Manager service",
- .verbs = _afb_verbs_v2_taskmanager,
+ .verbs = _afb_verbs_taskmanager,
.noconcurrency = 0
};