Browse Source

add create_session() and close_session() for explicit session management

old_session_management
Roker 2 years ago
parent
commit
e7a99fdafe
3 changed files with 25 additions and 0 deletions
  1. +2
    -0
      server/ev_server.cc
  2. +18
    -0
      server/json-adapter.cc
  3. +5
    -0
      server/json-adapter.hh

+ 2
- 0
server/ev_server.cc View File

@ -139,6 +139,8 @@ const FunctionMap functions = {
FP( "deliverHandshakeResult" , new Func<PEP_STATUS, In_Pep_Session, In<sync_handshake_result>, In<const identity_list*> > (&deliverHandshakeResult) ),
FP( "pollForEvents" , new Func<js::Array, In<JsonAdapter*,ParamFlag::NoInput>, In<unsigned>> (&JsonAdapter::pollForEvents) ),
FP( "pollForEvents2" , new Func<js::Array, In<JsonAdapter*,ParamFlag::NoInput>, In<std::string>, In<unsigned>> (&JsonAdapter::pollForEvents2) ),
FP( "create_session" , new Func<std::string>(&JsonAdapter::create_session)),
FP( "close_session" , new Func<void, In<JsonAdapter*,ParamFlag::NoInput>, In<std::string>> (&JsonAdapter::close_session) ),
FP( "Sync", new Separator ),
FP( "leave_device_group" , new Func<PEP_STATUS, In_Pep_Session> (&leave_device_group) ),


+ 18
- 0
server/json-adapter.cc View File

@ -297,6 +297,24 @@ void JsonAdapter::connection_close_cb()
}
void JsonAdapter::close_session(const std::string& session_id)
{
Lock L{_mtx};
auto q = i->eventListener.find( session_id );
Log() << "Close session \"" << session_id << "\": " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map";
if(q != i->eventListener.end())
{
i->eventListener.erase(q);
}
}
std::string JsonAdapter::create_session()
{
return create_random_token(12);
}
void JsonAdapter::shutdown(timeval* t)
{
exit(0); // HACK for JSON-41


+ 5
- 0
server/json-adapter.hh View File

@ -47,6 +47,11 @@ public:
// non-static: does the real work. :-)
void connection_close_cb();
void close_session(const std::string& session_id);
static
std::string create_session();
// exits gracefully after the given number of seconds.
// if "tv" is NULL it means: exits immediately after _all_ currently processed events have been finished.
void shutdown(struct timeval* tv);


Loading…
Cancel
Save