From ef2c53e36c9419aa1d311f62253646c7e85dabab Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 30 Mar 2012 11:24:34 +0200 Subject: Assembled the oberve protocol. --- src/observe_proto.cc | 66 +++++++++++++++++++++++++++++++++++++++++----------- src/observe_proto.h | 14 +++++++++++ 2 files changed, 67 insertions(+), 13 deletions(-) (limited to 'src') 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 +#include -TEST_BEGIN; +#include +#include -// 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 + +#include + +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__*/ -- cgit v1.2.3