WSF
WsfUCI_Interface.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_INTERFACE_HPP
13#define WSFUCI_INTERFACE_HPP
14
15#include "wsf_oms_uci_export.h"
16
17#include <map>
18#include <memory>
19#include <string>
20#include <iostream>
21
22class UtInput;
23#include "UtMemory.hpp"
24
25class WsfMessage;
26class WsfSimulation;
27
31
32//Fundamental Types
33#include "uci/base/AbstractServiceBusConnection.h"
34#include "uci/base/UUID.h"
35#include "uci/type/HeaderType.h"
36#include "uci/type/MessageType.h"
37
38//Factories
39#include "uci/factory/AMTI_ActivityFactory.h"
40#include "uci/factory/AMTI_CapabilityFactory.h"
41#include "uci/factory/AMTI_CapabilityStatusFactory.h"
42#include "uci/factory/AMTI_CommandFactory.h"
43#include "uci/factory/AMTI_CommandStatusFactory.h"
44#include "uci/factory/AMTI_SettingsCommandFactory.h"
45#include "uci/factory/AMTI_SettingsCommandStatusFactory.h"
46#include "uci/factory/CapabilityControlInterfacesEnumFactory.h"
47#include "uci/factory/ControlRequestFactory.h"
48#include "uci/factory/ControlRequestStatusFactory.h"
49#include "uci/factory/ControlStatusFactory.h"
50#include "uci/factory/EntityFactory.h"
51#include "uci/factory/EntityID_TypeFactory.h"
52#include "uci/factory/EntityMTFactory.h"
53#include "uci/factory/EntityMDTFactory.h"
54#include "uci/factory/ESM_ActivityFactory.h"
55#include "uci/factory/ESM_CapabilityFactory.h"
56#include "uci/factory/ESM_CapabilityStatusFactory.h"
57#include "uci/factory/ESM_CommandFactory.h"
58#include "uci/factory/ESM_CommandStatusFactory.h"
59#include "uci/factory/ESM_SettingsCommandFactory.h"
60#include "uci/factory/ESM_SettingsCommandStatusFactory.h"
61#include "uci/factory/KinematicsTypeFactory.h"
62#include "uci/factory/MessageStateEnumFactory.h"
63#include "uci/factory/PointingTypeEnumFactory.h"
64#include "uci/factory/POST_ActivityFactory.h"
65#include "uci/factory/POST_CapabilityFactory.h"
66#include "uci/factory/POST_CapabilityTypeFactory.h"
67#include "uci/factory/POST_CapabilityMDTFactory.h"
68#include "uci/factory/POST_CapabilityStatusFactory.h"
69#include "uci/factory/POST_CapabilityStatusTypeFactory.h"
70#include "uci/factory/POST_CommandFactory.h"
71#include "uci/factory/POST_CommandStatusFactory.h"
72#include "uci/factory/POST_SettingsCommandFactory.h"
73#include "uci/factory/POST_SettingsCommandStatusFactory.h"
74#include "uci/factory/POST_SubCapabilityTypeFactory.h"
75#include "uci/factory/SubsystemStatusFactory.h"
76#include "uci/factory/SystemStatusFactory.h"
77
78// Readers
79#include "uci/reader/EntityReader.h"
80#include "uci/reader/ESM_ActivityReader.h"
81#include "uci/reader/ESM_CapabilityReader.h"
82#include "uci/reader/ESM_CapabilityStatusReader.h"
83#include "uci/reader/ESM_CommandReader.h"
84#include "uci/reader/ESM_CommandStatusReader.h"
85#include "uci/reader/ESM_SettingsCommandReader.h"
86#include "uci/reader/ESM_SettingsCommandStatusReader.h"
87#include "uci/reader/POST_ActivityReader.h"
88#include "uci/reader/POST_CapabilityReader.h"
89#include "uci/reader/POST_CapabilityStatusReader.h"
90#include "uci/reader/POST_CommandReader.h"
91#include "uci/reader/POST_CommandStatusReader.h"
92#include "uci/reader/SubsystemStatusReader.h"
93#include "uci/reader/SystemStatusReader.h"
94
95// Writers
96#include "uci/writer/EntityWriter.h"
97#include "uci/writer/ESM_ActivityWriter.h"
98#include "uci/writer/ESM_CapabilityWriter.h"
99#include "uci/writer/ESM_CapabilityStatusWriter.h"
100#include "uci/writer/ESM_CommandWriter.h"
101#include "uci/writer/ESM_SettingsCommandWriter.h"
102#include "uci/writer/ESM_SettingsCommandStatusWriter.h"
103#include "uci/writer/ESM_CommandStatusWriter.h"
104#include "uci/writer/POST_ActivityWriter.h"
105#include "uci/writer/POST_CapabilityWriter.h"
106#include "uci/writer/POST_CapabilityStatusWriter.h"
107#include "uci/writer/POST_CommandWriter.h"
108#include "uci/writer/POST_CommandStatusWriter.h"
109#include "uci/writer/SubsystemStatusWriter.h"
110#include "uci/writer/SystemStatusWriter.h"
111
112namespace wsf
113{
114 class UCI_Component;
115
117 class WSF_OMS_UCI_EXPORT UCI_Interface
118 {
119 public:
120
121 UCI_Interface() = default;
122 UCI_Interface(const UCI_Interface& aSrc) = delete;
123 const UCI_Interface& operator=(const UCI_Interface& aRhs) = delete;
124 virtual ~UCI_Interface() = default;
125
126 bool ProcessInput(UtInput& aInput);
127 bool Initialize(WsfSimulation& aSimulation);
128
130 bool IsConfigured() const { return mIsConfigured; }
131
132 UCI_Component* GetUCI_Component(const std::string& aCapabilityId);
133
134 WsfSimulation& GetSimulation() { return *mSimulationPtr; } // Used for creating messages
135
136 void Shutdown();
137
138 void SetServiceDescriptor(const std::string& aServiceDescriptor) { mServiceDescriptor = aServiceDescriptor; }
139
140 void RegisterComponent(UCI_Component& aComponent);
141
142 void DeregisterComponent(UCI_Component& aComponent);
143
144 void RegisterCapabilities(UCI_Component& aComponent);
145
146 void DeregisterCapabilities(UCI_Component& aComponent);
147
149 uci::base::AbstractServiceBusConnection* GetConnection() const { return mAsbPtr; }
150
151 void ReceiveMessage(const uci::type::MessageType* aMessagePtr) const;
152
153 void PopulateHeader(const uci::type::DateTimeTypeValue& aSimTime,
154 uci::type::HeaderType& aHeader);
155
157 template<typename T> void CreateMessageService()
158 {
159 uci::base::accessorType::AccessorType type = T::GetUCI_TypeId();
160 std::string topic = T::GetUCI_TypeName();
161 auto topicsIter = mTopics.find(T::GetUCI_TypeName());
162 if (topicsIter != mTopics.end())
163 {
164 topic = topicsIter->second;
165 }
166 auto servicesIter = mServices.find(type);
167 if (servicesIter == mServices.end())
168 {
169 auto servicePtr = T::CreateMessageService(*this, mAsbPtr, topic.c_str());
170 mServices.emplace(std::make_pair(type, std::move(servicePtr)));
171 }
172 }
173
174 template<typename T> void GetMessageService(uci::base::accessorType::AccessorType aType, const T*& aServicePtr)
175 {
176 ServiceMap::iterator iter = mServices.find(aType);
177 if (iter != mServices.end())
178 {
179 aServicePtr = static_cast<T*>(iter->second.get());
180 }
181 else
182 {
183 aServicePtr = nullptr;
184 }
185 }
186
187 template<typename T> void GetTypeFactory(uci::base::accessorType::AccessorType aType, const T*& aFactoryPtr)
188 {
189 ServiceMap::iterator iter = mFactories.find(aType);
190 if (iter == mFactories.end())
191 {
192 mFactories.emplace(std::make_pair(aType, ut::make_unique<T>(mAsbPtr)));
193 // todo get the pointer in the return value above.
194 iter = mFactories.find(aType);
195 }
196 UCI_ServiceBase* sbp = iter->second.get();
197 aFactoryPtr = static_cast<T*>(sbp);
198 }
199
200 private:
201
202 // be able to map incoming messages to the components that can process them (TODO)
203 using ComponentMap = std::map<std::string, UCI_Component*>;
204 using ServiceMap = std::map<uci::base::accessorType::AccessorType, std::unique_ptr<UCI_ServiceBase>>;
205 using TopicMap = std::map<std::string, std::string>;
206
207 WsfSimulation* mSimulationPtr { nullptr };
208 uci::base::AbstractServiceBusConnection* mAsbPtr { nullptr };
209 std::string mServiceName;
210 std::string mServiceDescriptor { "uci" };
211 bool mIsInitialized { false };
212 bool mIsConfigured { false };
213 ServiceMap mServices;
214 ServiceMap mFactories;
215 ComponentMap mRegisteredComponents;
216 ComponentMap mRegisteredCapabilities;
217 TopicMap mTopics;
218
219 };
220}
221
222#endif
A base class for messages sent among simulation communication objects, processors and sensors.
Definition WsfMessage.hpp:33
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfUCI_Component.hpp:42
void CreateMessageService()
Create and store a message service. This must be called for all relevant message types.
Definition WsfUCI_Interface.hpp:157
void GetTypeFactory(uci::base::accessorType::AccessorType aType, const T *&aFactoryPtr)
Definition WsfUCI_Interface.hpp:187
UCI_Interface()=default
bool ProcessInput(UtInput &aInput)
Definition WsfUCI_Interface.cpp:75
void GetMessageService(uci::base::accessorType::AccessorType aType, const T *&aServicePtr)
Definition WsfUCI_Interface.hpp:174
virtual ~UCI_Interface()=default
UCI_Interface(const UCI_Interface &aSrc)=delete
uci::base::AbstractServiceBusConnection * GetConnection() const
Return the abstract service bus connection object.
Definition WsfUCI_Interface.hpp:149
bool Initialize(WsfSimulation &aSimulation)
Definition WsfUCI_Interface.cpp:122
WsfSimulation & GetSimulation()
Definition WsfUCI_Interface.hpp:134
void SetServiceDescriptor(const std::string &aServiceDescriptor)
Definition WsfUCI_Interface.hpp:138
bool IsConfigured() const
Return whether this interface has been configured in ProcessInput.
Definition WsfUCI_Interface.hpp:130
const UCI_Interface & operator=(const UCI_Interface &aRhs)=delete
Definition WsfUCI_ServiceBase.hpp:18
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved