135 lines
4.8 KiB
C++
135 lines
4.8 KiB
C++
#pragma once
|
|
|
|
#include "ddkit/base/IConfig.hpp"
|
|
#include "ddkit/access/Dispatcher.hpp"
|
|
#include "ddkit/access/ICleanup.hpp"
|
|
#include "ddkit/actors/ActorInfoDbCaretaker.hpp"
|
|
#include "ddkit/actors/ActorInfoDb.hpp"
|
|
#include "ddkit/actors/ActorInfoWriter.hpp"
|
|
#include "ddkit/actors/Session.hpp"
|
|
#include "ddkit/actors/MonitorSession.hpp"
|
|
#include "ddkit/actors/ILocalServices.hpp"
|
|
|
|
#include <list>
|
|
#include <map>
|
|
#include <set>
|
|
|
|
namespace ddkit {
|
|
namespace actors {
|
|
|
|
class IActor;
|
|
typedef std::shared_ptr<IActor> ActorPtr;
|
|
typedef std::weak_ptr<IActor> ActorPtrWeak;
|
|
|
|
class SimpleActor;
|
|
typedef std::shared_ptr<SimpleActor> SimpleActorPtr;
|
|
|
|
class MultiplexActor;
|
|
typedef std::shared_ptr<MultiplexActor> MultiplexActorPtr;
|
|
|
|
class SessionImpl final : public std::enable_shared_from_this<SessionImpl>,
|
|
public access::ICleanup,
|
|
public ILocalServices {
|
|
public:
|
|
SessionImpl(base::IConfig& config, int domain, bool isMonitor);
|
|
~SessionImpl();
|
|
|
|
void init();
|
|
|
|
// create a new SessionImpl (even if another Session with same domain exists already)
|
|
static SessionImplPtr create(int domain, bool isMonitor);
|
|
|
|
// needed from generated createSome (api) (friend access on Session)
|
|
static SessionImplPtr getSessionImpl(Session& session);
|
|
static SessionImplPtr getSessionImpl(MonitorSession& session);
|
|
|
|
// getter
|
|
int domain();
|
|
access::Participant& participant();
|
|
std::string sessionId();
|
|
std::shared_ptr<access::Dispatcher> dispatcher();
|
|
ddkit_intern::Session sessionInfo();
|
|
bool isMonitor();
|
|
|
|
bool isCheckMostDerivedClassType();
|
|
int timeoutSecsWaitUntilConnected();
|
|
|
|
// key2actor
|
|
bool hasActor(const std::string& serviceName, bool isService, const std::string& module);
|
|
SimpleActorPtr findActor(const std::string& serviceName, bool isService, const std::string& module);
|
|
SimpleActorPtr createActor(const std::string& serviceName, bool isService, const std::string& module);
|
|
MultiplexActorPtr createActorMultiplex(
|
|
bool isService,
|
|
const std::string& module,
|
|
const std::function<SimpleActorPtr(SessionImplPtr, const std::string&)>& createActor);
|
|
SimpleActorPtr createOrFindActor(const std::string& serviceName, bool isService, const std::string& module);
|
|
|
|
// ICleanup
|
|
void cleanup() override; // called from dispatcher regularly for removing non-referenced actors
|
|
bool isShutdownRequested() override;
|
|
|
|
// ids for Actors
|
|
int nextSequenceId() { return m_nextSequenceId++; }
|
|
|
|
// ActorInfo (sending to dds - actor-specific-part)
|
|
void publishActorInfo(ddkit_intern::ActorInfo actorInfo);
|
|
void disposeActorInfo(ddkit_intern::ActorInfo actorInfo);
|
|
|
|
// ActorInfo (using dds-meta-info)
|
|
std::vector<ServiceInfo> findRunningServices(const std::string& module);
|
|
std::vector<ServiceInfo> findRunningServices(const std::string& serviceName, const std::string& module); // max 1
|
|
std::vector<ClientInfo> findRunningClients(const std::string& module);
|
|
std::vector<ClientInfo> findRunningClients(const std::string& serviceName, const std::string& module);
|
|
|
|
// ILocalServices
|
|
bool isLocalService(ActorConfiguration config); // called from ActorInfoDb
|
|
|
|
std::string clientActorId2clientName(const std::string& clientActorId); // access meta-infos for callbackInfo
|
|
|
|
void shutdownActors();
|
|
void shutdownMultiplexActors();
|
|
|
|
void requestShutdown();
|
|
void requestCleanup();
|
|
|
|
void removeMultiplexActor(std::shared_ptr<IActor> multiplexActor);
|
|
|
|
private:
|
|
std::recursive_mutex m_mutex;
|
|
std::condition_variable_any m_condition;
|
|
|
|
bool m_isMonitor;
|
|
int m_domain;
|
|
access::Participant m_participant;
|
|
std::string m_sessionId; // identifies this session globally!
|
|
int m_nextSequenceId; // identifiying-addition for Actors
|
|
|
|
std::shared_ptr<access::Dispatcher> m_dispatcher;
|
|
|
|
std::vector<SimpleActorPtr> m_simpleActors; // 'normal'-actors (including internal actors of multiplex)
|
|
std::vector<MultiplexActorPtr> m_multiplexActors; // 'multiplex'-actors (have no serviceName for key, thus extra)
|
|
|
|
// ActorInfo (sending to dds - session-specific-part)
|
|
ddkit_intern::Process m_process;
|
|
ddkit_intern::Session m_sessionInfo;
|
|
ActorInfoWriter m_actorInfoWriter;
|
|
std::vector<ActorConfiguration> m_localServices; // log which services accountable for
|
|
|
|
// ActorInfo (reading from dds - monitor-intern-part)
|
|
ActorInfoDb m_actorInfoDb;
|
|
ActorInfoDbCaretaker m_ActorInfoDbCaretaker;
|
|
|
|
bool m_isCheckMostDerivedClassType;
|
|
int m_timeoutSecsWaitUntilConnected;
|
|
|
|
std::atomic<bool> m_shutdownRequested;
|
|
|
|
// no copying
|
|
SessionImpl(SessionImpl const&) = delete;
|
|
SessionImpl(SessionImpl&&) = delete;
|
|
void operator=(SessionImpl const&) = delete;
|
|
};
|
|
|
|
} // namespace actors
|
|
} // namespace ddkit
|