Remoto - VFS: VFS_tcp_export_sessionManager.cpp Source File
Remoto - VFS
VFS_tcp_export_sessionManager.cpp
Go to the documentation of this file.
1 
3 
4 #include "VFS.h"
5 
14 QMap<QString, VFS_session *> VFS_tcp_export_sessionManager::_sessions;
17 
25 {
26  QMutexLocker l(&_lock);
27 
28  if (_sessions.contains(id))
29  return _sessions[id];
30 
31  return nullptr;
32 }
33 
42 {
43  QMutexLocker l(&_lock);
44 
45  if (_requests.contains(id))
46  _requests.remove(id);
47 
48  if (_sessions.contains(id))
49  return false;
50 
51  _sessions[id] = session;
52 
53  connect( session, SIGNAL(finished(bool)), &_instance, SLOT(expireSession(bool)) );
54 
55  return true;
56 }
57 
66 {
67  QMutexLocker l(&_lock);
68 
69  if (!_requests.contains(id))
70  {
71  _requests[id] = true;
72 
73  VFS::LOG( QString("Issuing request for session: '%1'").arg(id), 9 );
74 
77  r->_metadata["sessionid"] = id;
78  r->_success = true; //to force include the metatdata
79  r->execute();
80  delete r;
81 
82  return true;
83  }
84 
85  return false;
86 }
87 
95 {
96  //printf("would expire session: %p\n",sender());
97 
98  QObject *o = sender();
99  VFS_session *s = dynamic_cast<VFS_session *>(o);
100 
101  if (s)
102  {
103  QMutexLocker l(&_lock);
104 
105  QString key = _sessions.key(s,"");
106 
107  if (key != "")
108  {
109  _sessions.remove(key);
110  _requests.remove(key);
111  s->deleteLater();
112  }
113  else
114  printf("COULD NOT FIND KEY FOR %p. Undefined behavior.\n", (void *) s);
115  }
116  //else
117  // printf("COULD NOT CAST TO VFS_SESSION. Undefined behavior. %p\n",o);
118 }
#define POST_ID_SESSION_DATA
Definition: VFS_node.h:18
bool _success
if the request was successfully completed
Definition: VFS_node.h:107
QJsonObject _metadata
the request payload
Definition: VFS_node.h:101
The VFS_session object represents a single session.
Definition: VFS_session.h:14
The socket client created by VFS_tcp_export.
QString _exportRoot
The VFS path to export.
The VFS_tcp_export class needs path information to translate between mounted VFS instances.
postID _id
The ID of this request.
virtual void execute()
DOCME.
A static class coupled with VFS_tcp_export_client for managing sessions.
static VFS_tcp_export_sessionManager _instance
A static instance of this class, used to receive expirations.
static QMutex _lock
A mutex for locking _sessions.
static QMap< QString, bool > _requests
Sessions which are currently under request.
static QMap< QString, VFS_session * > _sessions
The sessions registered to this node.
static bool registerSession(QString id, VFS_session *session)
Register a session with the session registry.
static VFS_session * fetchSession(QString id)
Fetch a session by id.
void expireSession(bool)
A session has expired.
static bool requestSession(QString id, VFS_tcp_export_client *client)
Request a session by id from a given VFS_tcp_export_client.
static void LOG(QString message, int level=0, QString user="server")
Send a message to the VFS::_messages VFS_stream.
Definition: VFS.cpp:209