From 86c43331eb0937384e408977dacecd7b6d0e9d70 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sun, 11 Nov 2018 01:36:15 +0100 Subject: [PATCH] meso: KBaseSession --- .../include/mesosphere/core/KAutoObject.hpp | 12 ++++ .../include/mesosphere/interfaces/IClient.hpp | 2 +- .../include/mesosphere/interfaces/IServer.hpp | 2 +- .../processes/KBaseClientSession.hpp | 45 ++++++++++++++ .../processes/KBaseServerSession.hpp | 58 +++++++++++++++++++ .../mesosphere/processes/KBaseSession.hpp | 39 +++++++++++++ .../include/mesosphere/processes/KEvent.hpp | 2 - .../source/processes/KBaseClientSession.cpp | 10 ++++ .../source/processes/KBaseServerSession.cpp | 11 ++++ mesosphere/source/processes/KBaseSession.cpp | 17 ++++++ 10 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 mesosphere/include/mesosphere/processes/KBaseClientSession.hpp create mode 100644 mesosphere/include/mesosphere/processes/KBaseServerSession.hpp create mode 100644 mesosphere/include/mesosphere/processes/KBaseSession.hpp create mode 100644 mesosphere/source/processes/KBaseClientSession.cpp create mode 100644 mesosphere/source/processes/KBaseServerSession.cpp create mode 100644 mesosphere/source/processes/KBaseSession.cpp diff --git a/mesosphere/include/mesosphere/core/KAutoObject.hpp b/mesosphere/include/mesosphere/core/KAutoObject.hpp index 2d10d94a9..76a5ac44e 100644 --- a/mesosphere/include/mesosphere/core/KAutoObject.hpp +++ b/mesosphere/include/mesosphere/core/KAutoObject.hpp @@ -23,6 +23,9 @@ class KEvent; class KReadableEvent; class KWritableEvent; class KInterruptEvent; +class KBaseSession; +class KBaseClientSession; +class KBaseServerSession; void intrusive_ptr_add_ref(KProcess *obj); void intrusive_ptr_release(KProcess *obj); @@ -42,6 +45,15 @@ void intrusive_ptr_release(KWritableEvent *obj); void intrusive_ptr_add_ref(KInterruptEvent *obj); void intrusive_ptr_release(KInterruptEvent *obj); +void intrusive_ptr_add_ref(KBaseSession *obj); +void intrusive_ptr_release(KBaseSession *obj); + +void intrusive_ptr_add_ref(KBaseClientSession *obj); +void intrusive_ptr_release(KBaseClientSession *obj); + +void intrusive_ptr_add_ref(KBaseClientSession *obj); +void intrusive_ptr_release(KBaseServerSession *obj); + class KAutoObject { public: diff --git a/mesosphere/include/mesosphere/interfaces/IClient.hpp b/mesosphere/include/mesosphere/interfaces/IClient.hpp index 81d5c334d..fd1d12611 100644 --- a/mesosphere/include/mesosphere/interfaces/IClient.hpp +++ b/mesosphere/include/mesosphere/interfaces/IClient.hpp @@ -21,7 +21,7 @@ class IClient : public IClientTag { void *operator new(size_t sz) noexcept = delete; void operator delete(void *ptr) noexcept {} - const SharedPtr& GetParent() const { return parent; } + ParentClass *GetParent() const { return parent.get(); } protected: friend class IClientServerParent; diff --git a/mesosphere/include/mesosphere/interfaces/IServer.hpp b/mesosphere/include/mesosphere/interfaces/IServer.hpp index 0e1330b8d..679f3d711 100644 --- a/mesosphere/include/mesosphere/interfaces/IServer.hpp +++ b/mesosphere/include/mesosphere/interfaces/IServer.hpp @@ -21,7 +21,7 @@ class IServer : public IServerTag { void *operator new(size_t sz) noexcept = delete; void operator delete(void *ptr) noexcept {}; - const SharedPtr &GetParent() const { return parent; } + ParentClass *GetParent() const { return parent.get(); } protected: friend class IClientServerParent; diff --git a/mesosphere/include/mesosphere/processes/KBaseClientSession.hpp b/mesosphere/include/mesosphere/processes/KBaseClientSession.hpp new file mode 100644 index 000000000..956db4dbb --- /dev/null +++ b/mesosphere/include/mesosphere/processes/KBaseClientSession.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include +#include + +namespace mesosphere +{ + +class KBaseServerSession; +class KBaseSession; +class KClientPort; +class KBaseClientSession : public KAutoObject, public IClient { + // Note: hidden from the KAutoObject hierarchy + + public: + + virtual ~KBaseClientSession(); + + // For covariant types + virtual KBaseSession *GetParentSession() const { return parent.get(); } + + protected: + + friend class KBaseSession; + friend class KBaseServerSession; + + KBaseClientSession() = default; + + bool isRemoteActive = false; + KClientPort *parentPort = nullptr; +}; + +inline void intrusive_ptr_add_ref(KBaseClientSession *obj) +{ + intrusive_ptr_add_ref((KAutoObject *)obj); +} + +inline void intrusive_ptr_release(KBaseClientSession *obj) +{ + intrusive_ptr_release((KAutoObject *)obj); +} + +} diff --git a/mesosphere/include/mesosphere/processes/KBaseServerSession.hpp b/mesosphere/include/mesosphere/processes/KBaseServerSession.hpp new file mode 100644 index 000000000..fae31e01b --- /dev/null +++ b/mesosphere/include/mesosphere/processes/KBaseServerSession.hpp @@ -0,0 +1,58 @@ +#pragma once + +#include +#include +#include +#include + +#include + +namespace mesosphere +{ + +class KBaseClientSession; +class KBaseSession; +class KClientPort; + +struct ServerSessionListTag; +using ServerSessionListBaseHook = boost::intrusive::list_base_hook >; + +class KBaseServerSession : + public KSynchronizationObject, + public IServer, + public ServerSessionListBaseHook { + // Note: hidden from the KAutoObject hierarchy + + public: + + using List = typename boost::intrusive::make_list< + KBaseServerSession, + boost::intrusive::base_hook, + boost::intrusive::constant_time_size + >::type; + + virtual ~KBaseServerSession(); + + // For covariant types + virtual KBaseSession *GetParentSession() const { return parent.get(); } + + virtual bool IsSignaled() const override { return false; } // hacky; to make it non-abstract + + protected: + + friend class KBaseSession; + + KBaseServerSession() = default; +}; + +inline void intrusive_ptr_add_ref(KBaseServerSession *obj) +{ + intrusive_ptr_add_ref((KAutoObject *)obj); +} + +inline void intrusive_ptr_release(KBaseServerSession *obj) +{ + intrusive_ptr_release((KAutoObject *)obj); +} + +} diff --git a/mesosphere/include/mesosphere/processes/KBaseSession.hpp b/mesosphere/include/mesosphere/processes/KBaseSession.hpp new file mode 100644 index 000000000..0fc92b65d --- /dev/null +++ b/mesosphere/include/mesosphere/processes/KBaseSession.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace mesosphere +{ + +class KBaseSession : public KAutoObject, public IClientServerParent { + // Note: hidden from the KAutoObject hierarchy + + public: + + virtual ~KBaseSession(); + + // For covariant types: + virtual KBaseClientSession *GetClientSession() { return &client; } + virtual KBaseServerSession *GetServerSession() { return &server; } + + protected: + + Result Initialize(); + KBaseSession() = default; +}; + +inline void intrusive_ptr_add_ref(KBaseSession *obj) +{ + intrusive_ptr_add_ref((KAutoObject *)obj); +} + +inline void intrusive_ptr_release(KBaseSession *obj) +{ + intrusive_ptr_release((KAutoObject *)obj); +} + +} diff --git a/mesosphere/include/mesosphere/processes/KEvent.hpp b/mesosphere/include/mesosphere/processes/KEvent.hpp index e09bde872..09a935a1f 100644 --- a/mesosphere/include/mesosphere/processes/KEvent.hpp +++ b/mesosphere/include/mesosphere/processes/KEvent.hpp @@ -1,7 +1,5 @@ #pragma once -class KProcess; - #include #include #include diff --git a/mesosphere/source/processes/KBaseClientSession.cpp b/mesosphere/source/processes/KBaseClientSession.cpp new file mode 100644 index 000000000..de8224ecc --- /dev/null +++ b/mesosphere/source/processes/KBaseClientSession.cpp @@ -0,0 +1,10 @@ +#include + +namespace mesosphere +{ + +KBaseClientSession::~KBaseClientSession() +{ +} + +} diff --git a/mesosphere/source/processes/KBaseServerSession.cpp b/mesosphere/source/processes/KBaseServerSession.cpp new file mode 100644 index 000000000..9a9f18c21 --- /dev/null +++ b/mesosphere/source/processes/KBaseServerSession.cpp @@ -0,0 +1,11 @@ +#include + +namespace mesosphere +{ + +KBaseServerSession::~KBaseServerSession() +{ + // Children classes will lock critical section + set client "isRemoteAlive" +} + +} diff --git a/mesosphere/source/processes/KBaseSession.cpp b/mesosphere/source/processes/KBaseSession.cpp new file mode 100644 index 000000000..c58e12e78 --- /dev/null +++ b/mesosphere/source/processes/KBaseSession.cpp @@ -0,0 +1,17 @@ +#include + +namespace mesosphere +{ + +KBaseSession::~KBaseSession() +{ +} + +Result KBaseSession::Initialize() +{ + SetClientServerParent(); + + return ResultSuccess(); +} + +}