NRP Core  1.4.1
transceiver_datapack_interface.h
Go to the documentation of this file.
1 /* * NRP Core - Backend infrastructure to synchronize simulations
2  *
3  * Copyright 2020-2023 NRP Team
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * This project has received funding from the European Union’s Horizon 2020
18  * Framework Programme for Research and Innovation under the Specific Grant
19  * Agreement No. 945539 (Human Brain Project SGA3).
20  */
21 
22 #ifndef TRANSCEIVER_DATAPACK_INTERFACE_H
23 #define TRANSCEIVER_DATAPACK_INTERFACE_H
24 
27 
28 //#include "nrp_general_library/transceiver_function/transceiver_function_interpreter.h"
29 
30 #include <boost/python.hpp>
31 
32 class FunctionManager;
33 using TransceiverFunctionInterpreterSharedPtr = std::shared_ptr<FunctionManager>;
34 using TransceiverFunctionInterpreterConstSharedPtr = std::shared_ptr<const FunctionManager>;
35 
36 
41  : public PtrTemplates<TransceiverDataPackInterface>
42 {
43  public:
44  TransceiverDataPackInterface() = default;
45  virtual ~TransceiverDataPackInterface() = default;
46 
52  template<class TRANSCEIVER_DATAPACK>
54  {
55  static_assert((std::is_base_of_v<TransceiverDataPackInterface, TRANSCEIVER_DATAPACK>) || (std::is_same_v<TransceiverDataPackInterface, TRANSCEIVER_DATAPACK>),"Parameter TRANSCEIVER_DATAPACK must derive from TransceiverDataPackInterface or be same");
56 
57  this->_nextDecorator = tfDataPack;
58 
59  auto thisPtr = this->moveToSharedPtr<TRANSCEIVER_DATAPACK>();
60 
61  TransceiverDataPackInterface::shared_ptr *const registryPtr = this->_nextDecorator->getTFInterpreterRegistry();
62  assert(registryPtr != nullptr);
63 
64  *registryPtr = thisPtr;
65  return thisPtr;
66  }
67 
71  virtual const std::string &linkedEngineName() const;
72 
76  virtual bool isPreprocessing() const;
77 
84  virtual boost::python::object runTf(boost::python::tuple &args, boost::python::dict &kwargs, datapacks_set_t dataPacks);
85 
92 
97 
102  static void setTFInterpreter(FunctionManager *interpreter);
104  {
106  }
107 
108  protected:
113 
114  template<class TRANSCEIVER_DATAPACK>
116  {
117  static_assert((std::is_base_of_v<TransceiverDataPackInterface, TRANSCEIVER_DATAPACK>) || (std::is_same_v<TransceiverDataPackInterface, TRANSCEIVER_DATAPACK>),"Parameter TRANSCEIVER_DATAPACK must derive from TransceiverDataPackInterface or be same");
118  return typename PtrTemplates<TRANSCEIVER_DATAPACK>::shared_ptr(new TRANSCEIVER_DATAPACK(std::move(static_cast<TRANSCEIVER_DATAPACK&>(*this))));
119  }
120 
126 
127  private:
132 };
133 
136 
137 #endif
TransceiverDataPackInterface::getFunctionManager
static const FunctionManager * getFunctionManager()
Definition: transceiver_datapack_interface.h:103
datapacks_set_t
std::set< std::shared_ptr< const DataPackInterface >, DataPackPointerComparator > datapacks_set_t
Definition: datapack_interface.h:219
TransceiverDataPackInterface::isPreprocessing
virtual bool isPreprocessing() const
Indicates if this is a preprocessing function.
Definition: transceiver_datapack_interface.cpp:32
TransceiverDataPackInterfaceConstSharedPtr
TransceiverDataPackInterface::const_shared_ptr TransceiverDataPackInterfaceConstSharedPtr
Definition: transceiver_datapack_interface.h:135
python_json_engine.args
Namespace args
Definition: python_json_engine.py:196
TransceiverDataPackInterface::~TransceiverDataPackInterface
virtual ~TransceiverDataPackInterface()=default
PtrTemplates< TransceiverDataPackInterface >::const_shared_ptr
std::shared_ptr< const TransceiverDataPackInterface > const_shared_ptr
Definition: ptr_templates.h:32
engine_client_interface.h
TransceiverDataPackInterface::runTf
virtual boost::python::object runTf(boost::python::tuple &args, boost::python::dict &kwargs, datapacks_set_t dataPacks)
Execute Transceiver Function. Base class will simply call runTf on _function.
Definition: transceiver_datapack_interface.cpp:37
datapack_identifiers_set_t
std::set< DataPackIdentifier > datapack_identifiers_set_t
Definition: datapack_interface.h:221
TransceiverDataPackInterface::getTFInterpreterRegistry
virtual TransceiverDataPackInterface::shared_ptr * getTFInterpreterRegistry()
Gets address of ptr under which the _functionManager has registered this TF. Mainly used during setup...
Definition: transceiver_datapack_interface.cpp:62
PtrTemplates
Definition: ptr_templates.h:28
TransceiverDataPackInterface::TransceiverDataPackInterface
TransceiverDataPackInterface()=default
TransceiverDataPackInterface
Base of TF Decorators.
Definition: transceiver_datapack_interface.h:40
ptr_templates.h
TransceiverFunctionInterpreterConstSharedPtr
std::shared_ptr< const FunctionManager > TransceiverFunctionInterpreterConstSharedPtr
Definition: transceiver_datapack_interface.h:34
PtrTemplates< TransceiverDataPackInterface >::shared_ptr
std::shared_ptr< TransceiverDataPackInterface > shared_ptr
Definition: ptr_templates.h:31
TransceiverDataPackInterfaceSharedPtr
TransceiverDataPackInterface::shared_ptr TransceiverDataPackInterfaceSharedPtr
Definition: transceiver_datapack_interface.h:134
TransceiverFunctionInterpreterSharedPtr
std::shared_ptr< FunctionManager > TransceiverFunctionInterpreterSharedPtr
Definition: transceiver_datapack_interface.h:33
TransceiverDataPackInterface::getRequestedDataPackIDs
virtual datapack_identifiers_set_t getRequestedDataPackIDs() const
Returns datapack IDs of this DataPack that should be requested from the engines. TODO: Make protected...
Definition: transceiver_datapack_interface.cpp:52
TransceiverDataPackInterface::updateRequestedDataPackIDs
virtual datapack_identifiers_set_t updateRequestedDataPackIDs(datapack_identifiers_set_t &&datapackIDs=datapack_identifiers_set_t()) const
Appends its own datapack requests onto datapackIDs. Uses getRequestedDataPackIDs to check which IDs a...
Definition: transceiver_datapack_interface.cpp:42
TransceiverDataPackInterface::setTFInterpreter
static void setTFInterpreter(FunctionManager *interpreter)
Set global TF Interpreter. All Transceiver Functions will register themselves with it upon creation.
Definition: transceiver_datapack_interface.cpp:57
TransceiverDataPackInterface::linkedEngineName
virtual const std::string & linkedEngineName() const
Get name of engine this transceiver is linked to.
Definition: transceiver_datapack_interface.cpp:27
TransceiverDataPackInterface::moveToSharedPtr
PtrTemplates< TRANSCEIVER_DATAPACK >::shared_ptr moveToSharedPtr()
Definition: transceiver_datapack_interface.h:115
TransceiverDataPackInterface::pySetup
TransceiverDataPackInterface::shared_ptr pySetup(const TransceiverDataPackInterface::shared_ptr &tfDataPack)
Decorator call() function. Takes the lower decorator as a parameter. Moves the given class into a sha...
Definition: transceiver_datapack_interface.h:53
FunctionManager
Manages all types of Python functions that can be run as part of NRP Core.
Definition: function_manager.h:73
TransceiverDataPackInterface::_functionManager
static FunctionManager * _functionManager
Pointer to TF Interpreter. Will be used to register a new TF function.
Definition: transceiver_datapack_interface.h:112