Add more reflexivity to client/server interfaces

This commit is contained in:
TuxSH 2018-11-05 23:53:29 +01:00 committed by Michael Scire
parent e2d8316401
commit ac6762bb6c
6 changed files with 38 additions and 20 deletions

View file

@ -4,22 +4,26 @@
#include <mesosphere/core/types.hpp> #include <mesosphere/core/types.hpp>
#include <mesosphere/interfaces/IClientServerParent.hpp> #include <mesosphere/interfaces/IClientServerParent.hpp>
#define MESOSPHERE_CLIENT_TRAITS(ParentId) using ParentClass = K##ParentId;
namespace mesosphere namespace mesosphere
{ {
struct IClientTag {};
template<typename Parent, typename Client, typename Server> template<typename Parent, typename Client, typename Server>
class IClient { class IClient : public IClientTag {
public: public:
using ParentType = Parent; using ParentClass = Parent;
using ClientType = Client; using ClientClass = Client;
using ServerType = Server; using ServerClass = Server;
~IClient() ~IClient()
{ {
parent->HandleClientDestroyed(); parent->HandleClientDestroyed();
} }
ParentType *GetParent() const { return parent; } ParentClass *GetParent() const { return parent; }
void SetParent(SharedPtr<Parent> parent) void SetParent(SharedPtr<Parent> parent)
{ {

View file

@ -2,15 +2,21 @@
#include <mesosphere/core/types.hpp> #include <mesosphere/core/types.hpp>
#define MESOSPHERE_CLIENT_SERVER_PARENT_TRAITS(ClientId, ServerId)\
using ClientClass = K##ClientId;\
using ServerClass = K##ServerId;
namespace mesosphere namespace mesosphere
{ {
struct IClientServerParentTag {};
template<typename Parent, typename Client, typename Server> template<typename Parent, typename Client, typename Server>
class IClientServerParent { class IClientServerParent : public IClientServerParentTag {
public: public:
using ParentType = Parent; using ParentClass = Parent;
using ClientType = Client; using ClientClass = Client;
using ServerType = Server; using ServerClass = Server;
void SetClientServerParent() void SetClientServerParent()
{ {
@ -21,8 +27,8 @@ class IClientServerParent {
protected: protected:
ClientType client{}; ClientClass client{};
ServerType server{}; ServerClass server{};
}; };
} }

View file

@ -4,22 +4,26 @@
#include <mesosphere/core/types.hpp> #include <mesosphere/core/types.hpp>
#include <mesosphere/interfaces/IClientServerParent.hpp> #include <mesosphere/interfaces/IClientServerParent.hpp>
#define MESOSPHERE_SERVER_TRAITS(ParentId) using ParentClass = K##ParentId;
namespace mesosphere namespace mesosphere
{ {
struct IServerTag {};
template<typename Parent, typename Client, typename Server> template<typename Parent, typename Client, typename Server>
class IServer { class IServer : public IServerTag {
public: public:
using ParentType = Parent; using ParentClass = Parent;
using ClientType = Client; using ClientClass = Client;
using ServerType = Server; using ServerClass = Server;
~IServer() ~IServer()
{ {
parent->HandleServerDestroyed(); parent->HandleServerDestroyed();
} }
ParentType *GetParent() const { return parent; } ParentClass *GetParent() const { return parent; }
void SetParentAndClient(SharedPtr<Parent> parent, SharedPtr<Client> client) void SetParentAndClient(SharedPtr<Parent> parent, SharedPtr<Client> client)
{ {

View file

@ -21,6 +21,7 @@ class KEvent final :
public ILimitedResource<KEvent> { public ILimitedResource<KEvent> {
public: public:
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Event); MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Event);
MESOSPHERE_CLIENT_SERVER_PARENT_TRAITS(ReadableEvent, WritableEvent);
virtual ~KEvent(); virtual ~KEvent();

View file

@ -13,9 +13,11 @@ namespace mesosphere
class KWritableEvent; class KWritableEvent;
class KEvent; class KEvent;
class KReadableEvent final : public KSynchronizationObject, public IClient<KEvent, KReadableEvent, KWritableEvent> { // Inherited by KInterruptEvent
class KReadableEvent : public KSynchronizationObject, public IClient<KEvent, KReadableEvent, KWritableEvent> {
public: public:
MESOSPHERE_AUTO_OBJECT_TRAITS(SynchronizationObject, ReadableEvent); MESOSPHERE_AUTO_OBJECT_TRAITS(SynchronizationObject, ReadableEvent);
MESOSPHERE_CLIENT_TRAITS(Event);
virtual bool IsAlive() const override { return true; } virtual bool IsAlive() const override { return true; }

View file

@ -15,6 +15,7 @@ class KEvent;
class KWritableEvent final : public KAutoObject, public IServer<KEvent, KReadableEvent, KWritableEvent> { class KWritableEvent final : public KAutoObject, public IServer<KEvent, KReadableEvent, KWritableEvent> {
public: public:
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, WritableEvent); MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, WritableEvent);
MESOSPHERE_SERVER_TRAITS(Event);
virtual bool IsAlive() const override { return true; } virtual bool IsAlive() const override { return true; }