diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2012-03-30 11:24:34 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2012-03-30 11:24:34 +0200 |
commit | ef2c53e36c9419aa1d311f62253646c7e85dabab (patch) | |
tree | 8e5bb1912d81c6a26b19d2ecf4df6e75febfe889 /src | |
parent | 69cb3c171df31efab500ae87146c35ace6f92db3 (diff) |
Assembled the oberve protocol.
Diffstat (limited to 'src')
-rw-r--r-- | src/observe_proto.cc | 66 | ||||
-rw-r--r-- | src/observe_proto.h | 14 |
2 files changed, 67 insertions, 13 deletions
diff --git a/src/observe_proto.cc b/src/observe_proto.cc index 8ea6104..a572d1e 100644 --- a/src/observe_proto.cc +++ b/src/observe_proto.cc @@ -27,20 +27,60 @@ */ #include "observe_proto.h" -#ifdef TEST_OBSERVE_PROTO -//Additional dependency files -//deps: -//Required cflags (autoconf vars may be used) -//cflags: -//Required link options (autoconf vars may be used) -//libs: -#include "test.h" +#include <stdio.h> +#include <string.h> -TEST_BEGIN; +#include <queue> +#include <map> -// TODO: Put some testcode here (see test.h for usable macros). -TEST_TRUE(false, "No tests yet!"); +#include "task.h" +#include "msgparser.h" +#include "xmlparser.h" -TEST_END; +#include "connectionhandler.h" -#endif/*TEST_OBSERVE_PROTO*/ +int callback_lws_observe(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, + void *user, void *in, size_t len) +{ + switch (reason) { + case LWS_CALLBACK_ESTABLISHED: + connection_handler.init(wsi); + break; + + case LWS_CALLBACK_CLOSED: + connection_handler.close(wsi); + break; + + case LWS_CALLBACK_RECEIVE: + { + std::string data; + data.append((char*)in, len); + + MessageList mlst = parse_msg(data); + for(MessageList::iterator i = mlst.begin(); i != mlst.end(); i++) { + message_t m = *i; + switch(m.cmd) { + case cmd::observe: { + connection_handler.observe(wsi, m.observe.id); + break; + } + case cmd::unobserve: { + connection_handler.unobserve(wsi, m.observe.id); + break; + } + default: + printf("Wrong command :(\n"); + break; + } + } + } + break; + + default: + break; + } + + return 0; +} diff --git a/src/observe_proto.h b/src/observe_proto.h index fea9ebd..6ef1e66 100644 --- a/src/observe_proto.h +++ b/src/observe_proto.h @@ -27,4 +27,18 @@ */ #ifndef __MUNIA_OBSERVE_PROTO_H__ #define __MUNIA_OBSERVE_PROTO_H__ + +#include <stdlib.h> + +#include <libwebsockets.h> + +int callback_lws_observe(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, + void *user, void *in, size_t len); + +struct per_session_data__lws_observe { + struct libwebsocket *wsi; +}; + #endif/*__MUNIA_OBSERVE_PROTO_H__*/ |