WSF
WsfUCI_MessageService.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI//REL TO USA ONLY
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2019 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFUCI_MESSAGESERVICE_HPP
13#define WSFUCI_MESSAGESERVICE_HPP
14
16
17#include "uci/base/AbstractServiceBusConnection.h"
18#include "UtMemory.hpp"
19
22
23namespace wsf
24{
25 class UCI_Interface;
26
28 template< class MessageType,
29 class FactoryType,
30 class ReaderType,
31 class WriterType,
32 class ListenerType > // see definition of UCI_GenericListner.
34 {
35 using GenericListenerType = UCI_GenericListener<MessageType, ListenerType>;
36
37 public:
39 uci::base::AbstractServiceBusConnection* aAsbPtr,
40 const char* aTopic)
42 mFactoryService(aAsbPtr),
43 mReaderPtr(&mFactoryService.GetFactory().createReader(aTopic)),
44 mWriterPtr(&mFactoryService.GetFactory().createWriter(aTopic)),
45 mListenerPtr(ut::make_unique<GenericListenerType>(aInterface))
46 {
47 mReaderPtr->addListener(*mListenerPtr);
48 }
49 virtual ~UCI_MessageService() = default;
52 const UCI_MessageService& operator=(const UCI_MessageService& aRhs) = delete;
53
54 const UCI_FactoryService<MessageType, FactoryType>& GetTypeFactory() const { return mFactoryService; }
55 FactoryType& GetFactory() const { return mFactoryService.GetFactory(); }
56 WriterType& GetWriter() const { return *mWriterPtr; }
57 ReaderType& GetReader() const { return *mReaderPtr; }
58
61 void Shutdown()
62 {
63 mReaderPtr->removeListener(*mListenerPtr); // ... but not deleted.
64 mReaderPtr->close();
65 mFactoryService.GetFactory().destroyReader(*mReaderPtr);
66 mWriterPtr->close();
67 mFactoryService.GetFactory().destroyWriter(*mWriterPtr);
68 mFactoryService.Shutdown();
69 }
70 private:
71
73 ReaderType* mReaderPtr = nullptr;
74 WriterType* mWriterPtr = nullptr;
75 std::unique_ptr<GenericListenerType> mListenerPtr = nullptr;
76 };
77
78
79//#define DEFINE_UCI_MESSAGE_SERVICE(WSF_MESSAGE_SERVICE_TYPE, UCI_MESSAGE_TYPE, WSF_TYPE_NAME, TOPIC_NAME)
80//class WSF_MESSAGE_SERVICE_TYPE : public UCI_MessageService<uci::type::UCI_MESSAGE_TYPE,
81// uci::factory::UCI_MESSAGE_TYPE##Factory,
82// uci::reader::UCI_MESSAGE_TYPE##Reader,
83// uci::writer::UCI_MESSAGE_TYPE##Writer,
84// uci::reader::UCI_MESSAGE_TYPE##Listener>
85//{
86// public:
87// explicit WSF_MESSAGE_SERVICE_TYPE(UCI_Interface& aInterface,
88// uci::base::AbstractServiceBusConnection* aAsbPtr,
89// const char* aTopic) : UCI_MessageService(aInterface, aAbsPtr, aTopic) {}
90// explicit WSF_MESSAGE_SERVICE_TYPE(UCI_Interface& aInterface) : UCI_MessageType(aInterface) { SetType(GetTypeId()); }
91// WSF_MESSAGE_SERVICE_TYPE(UCI_Interface& aInterface, const uci::type::UCI_MESSAGE_TYPE& aType) : UCI_MessageType(aInterface, aType) { SetType(GetTypeId()); }
92// WSF_MESSAGE_SERVICE_TYPE(const WSF_MESSAGE_SERVICE_TYPE& aSrc) = default;
93// ~WSF_MESSAGE_SERVICE_TYPE() override = default;
94// WsfMessage* Clone() const override { return new WSF_MESSAGE_SERVICE_TYPE(*this); }
95// const char* GetScriptClassName() const override { return #WSF_MESSAGE_SERVICE_TYPE; }
96// static WsfStringId GetTypeId() { return #WSF_TYPE_NAME; }
97//};
98
99}
100
101#endif
Define a generic factory service that can be parameterized with any factory-enabled UCI type.
Definition WsfUCI_FactoryService.hpp:25
Define a generic interface that passes received messages to the interface to dispatch to UCI componen...
Definition WsfUCI_GenericListener.hpp:38
The OMS / UCI Interface Object to the UCI middleware.
Definition WsfUCI_Interface.hpp:118
FactoryType & GetFactory() const
Definition WsfUCI_MessageService.hpp:55
ReaderType & GetReader() const
Definition WsfUCI_MessageService.hpp:57
const UCI_MessageService & operator=(const UCI_MessageService &aRhs)=delete
virtual ~UCI_MessageService()=default
const UCI_FactoryService< MessageType, FactoryType > & GetTypeFactory() const
Definition WsfUCI_MessageService.hpp:54
WriterType & GetWriter() const
Definition WsfUCI_MessageService.hpp:56
UCI_MessageService(UCI_Interface &aInterface, uci::base::AbstractServiceBusConnection *aAsbPtr, const char *aTopic)
Definition WsfUCI_MessageService.hpp:38
void Shutdown()
Definition WsfUCI_MessageService.hpp:61
UCI_MessageService(const UCI_MessageService &aSrc)=delete
UCI_ServiceBase()=default
Definition WsfSensorErrorModel.hpp:21
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved