Skip to content
Snippets Groups Projects
Commit 36d10a74 authored by clohr's avatar clohr
Browse files

Préparation de la v0.5r2

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/trunk@1591 b32b6428-25c9-4566-ad07-03861ab6144f
parent 147bb332
No related branches found
No related tags found
No related merge requests found
......@@ -1178,3 +1178,29 @@ void dump_db(db_t *db, char *file) {
json_object_put(jdb);
}
/*
* Section Request Queues (http streams or websockets)
*/
/* Remove a wsi from requests queues */
void remove_wsi(db_t *db, struct lws *wsi) {
req_t *req;
TAILQ_FOREACH(req, &(db->msgreqs), entries)
if (req->wsi == wsi) {
TAILQ_REMOVE(&(db->msgreqs), req, entries);
fprintf(stderr, "remove msgreqs wsi:%p\n", wsi);
free(req);
return;
}
TAILQ_FOREACH(req, &(db->attrreqs), entries)
if (req->wsi == wsi) {
TAILQ_REMOVE(&(db->attrreqs), req, entries);
fprintf(stderr, "remove attrreqs wsi:%p\n", wsi);
free(req);
return;
}
}
......@@ -19,6 +19,7 @@
#ifndef _XAAGENTDB_
#define _XAAGENTDB_
#include <libwebsockets.h>
#include <sys/queue.h>
#include <json-c/json.h>
#include <xaal.h>
......@@ -114,7 +115,7 @@ typedef struct deviceentry {
typedef TAILQ_HEAD(reqhead, reqentry) reqs_t;
typedef struct reqentry {
// FCGX_Request *r;
struct lws *wsi;
TAILQ_ENTRY(reqentry) entries;
} req_t;
......@@ -329,6 +330,13 @@ struct json_object *get_device_by_addr(devices_t *devices, const char *addr);
void delete_device(devices_t * devices, device_t *device);
/*
* Section Request Queues (http streams or websockets)
*/
/* Remove a wsi from requests queues */
void remove_wsi(db_t *db, struct lws *wsi);
/*
* Section Database Itself
......
......@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <string.h>
#include <libwebsockets.h>
#include <sys/queue.h>
#include "proto-http.h"
#include "xaaws.h"
......@@ -156,6 +157,23 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
free(query_dev);
}
} else if (strcmp(in, REST_PREFIX "dump") == 0) {
req_t *req = (req_t *) malloc( sizeof(req_t) );
req->wsi = wsi;
fprintf(stderr, "msgreqs add wsi:%p\n", wsi);
TAILQ_INSERT_TAIL(&(db.msgreqs), req, entries);
pss->complete = false;
lws_callback_on_writable(wsi);
break;
} else if (strcmp(in, REST_PREFIX "attributesChange") == 0) {
req_t *req = (req_t *) malloc( sizeof(req_t) );
req->wsi = wsi;
fprintf(stderr, "attrreqs add wsi:%p\n", wsi);
TAILQ_INSERT_TAIL(&(db.attrreqs), req, entries);
pss->complete = false;
lws_callback_on_writable(wsi);
break;
}
if (pss->janswer) {
......@@ -251,6 +269,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
} else {
if ( serve_http_stream(wsi, pss->janswer) ) {
fprintf(stderr, "serve_http_stream\n");
json_object_put(pss->janswer);
pss->janswer = NULL;
//lws_client_http_body_pending(wsi, 1);
......@@ -264,6 +283,10 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
}
break;
case LWS_CALLBACK_WSI_DESTROY:
remove_wsi(&db, wsi);
break;
case LWS_CALLBACK_ADD_POLL_FD:
if (count_pollfds >= max_poll_elements) {
lwsl_err("LWS_CALLBACK_ADD_POLL_FD: too many sockets to track\n");
......
......@@ -172,7 +172,7 @@ bool receive_cachedDeviceAttribute(struct json_object *jqueryBody, db_t *db) {
json_object_array_add(jattributes, jattr);
json_object_object_add(jobj, "attributes", jattributes);
// fcgi_streams_feed(&(db->attrreqs), jobj);
streams_feed(&(db->attrreqs), jobj);
}
return true;
......@@ -223,7 +223,7 @@ bool receive_cachedDeviceAttributes(struct json_object *jqueryBody, db_t *db) {
}
/* send attributes to http streams */
// fcgi_streams_feed(&(db->attrreqs), json_object_get(jqueryBody));
streams_feed(&(db->attrreqs), json_object_get(jqueryBody));
return true;
}
......@@ -327,7 +327,7 @@ bool receive_deviceAttributes(const char *dev, const char *devType, struct json_
}
json_object_object_add(jobj, "attributes", jattributes);
// fcgi_streams_feed(&(db->attrreqs), jobj);
streams_feed(&(db->attrreqs), jobj);
}
return true;
......@@ -398,7 +398,7 @@ void callback_xaal(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, db_t *db
return;
/* send msg to http streams */
// fcgi_streams_feed(&(db->msgreqs), rebuild_msg(jtargets, source, devType, msgType, action, jbody));
streams_feed(&(db->msgreqs), rebuild_msg(jtargets, source, devType, msgType, action, jbody));
/* manage msg */
if (xAAL_targets_match(jtargets, me->addr)) {
......@@ -729,3 +729,21 @@ struct json_object *post_xAALrequest(const xAAL_businfo_t *bus, const xAAL_devin
json_object_object_add(janswer, "success", json_object_new_boolean(xAAL_write_bus(bus, me, "request", action, jbody, jtargets)));
return janswer;
}
/* Feed http stream or web sockets with interesting data from xAAL */
void streams_feed(reqs_t *reqs, json_object *jobj) {
req_t *req;
struct per_session_data__generic {
struct json_object *janswer;
} *user_space;
TAILQ_FOREACH(req, reqs, entries) {
user_space = lws_wsi_user(req->wsi);
user_space->janswer = json_object_get(jobj);
lws_callback_on_writable(req->wsi);
}
}
......@@ -42,4 +42,8 @@ void callback_checking(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, db_t
struct json_object *post_xAALrequest(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me, char *msg, size_t len);
/* Feed http stream and web sockets with interesting data from xAAL */
void streams_feed(reqs_t *reqs, json_object *jobj);
#endif
......@@ -47,8 +47,6 @@ struct lws_pollfd *pollfds;
int *fd_lookup;
int count_pollfds;
int debug_level;
volatile int force_exit = 0;
struct lws_context *context;
......@@ -122,7 +120,6 @@ int main(int argc, char **argv) {
} else {
lws_set_log_level(options.verbose, emit_log);
}
debug_level = options.verbose;
signal(SIGINT, sighandler);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment