| helics 3.6.1

core/Core.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8
9 #include "LocalFederateId.hpp"
10 #include "core-data.hpp"
11
12 #include <functional>
13 #include <memory>
14 #include <string>
15 #include <utility>
16 #include <vector>
17
37 namespace helics {
38 class CoreFederateInfo;
39
41 class Core {
42 public:
44 Core() = default;
46 virtual ~Core() = default;
47
54 virtual void configure(std::string_view configureString) = 0;
61 virtual void configureFromArgs(int argc, char* argv[]) = 0;
68 virtual void configureFromVector(std::vector<std::string> args) = 0;
72 virtual bool isConfigured() const = 0;
73
78 virtual bool connect() = 0;
82 virtual bool isConnected() const = 0;
83
87 virtual void disconnect() = 0;
88
89 /*return true if the core has an error*/
90 virtual bool hasError() const = 0;
94 virtual bool waitForDisconnect(
95 std::chrono::milliseconds msToWait = std::chrono::milliseconds(0)) const = 0;
96
99 virtual bool isOpenToNewFederates() const = 0;
102 virtual const std::string& getIdentifier() const = 0;
104 virtual const std::string& getAddress() const = 0;
105
112 virtual void globalError(LocalFederateId federateID,
113 int32_t errorCode,
114 std::string_view errorString) = 0;
115
122 virtual void
123 localError(LocalFederateId federateID, int32_t errorCode, std::string_view errorString) = 0;
124
126 virtual int getErrorCode() const = 0;
128 virtual std::string getErrorMessage() const = 0;
135 virtual void finalize(LocalFederateId federateID) = 0;
136
166 virtual bool enterInitializingMode(LocalFederateId federateID,
167 IterationRequest iterate = NO_ITERATION) = 0;
168
172 virtual void setCoreReadyToInit() = 0;
173
186 virtual iteration_time enterExecutingMode(LocalFederateId federateID,
187 IterationRequest iterate = NO_ITERATION) = 0;
188
197 virtual LocalFederateId registerFederate(std::string_view name,
198 const CoreFederateInfo& info) = 0;
199
204 virtual const std::string& getFederateName(LocalFederateId federateID) const = 0;
205
210 virtual LocalFederateId getFederateId(std::string_view name) const = 0;
211
216 virtual int32_t getFederationSize() = 0;
217
238 virtual Time timeRequest(LocalFederateId federateID, Time next) = 0;
239
268 virtual iteration_time
269 requestTimeIterative(LocalFederateId federateID, Time next, IterationRequest iterate) = 0;
270
279 virtual void processCommunications(LocalFederateId fedId,
280 std::chrono::milliseconds msToWait) = 0;
286 virtual void setTimeProperty(LocalFederateId federateID, int32_t property, Time timeValue) = 0;
292 virtual Time getTimeProperty(LocalFederateId federateID, int32_t property) const = 0;
298 virtual void
299 setIntegerProperty(LocalFederateId federateID, int32_t property, int16_t propValue) = 0;
305 virtual int16_t getIntegerProperty(LocalFederateId federateID, int32_t property) const = 0;
310 virtual Time getCurrentTime(LocalFederateId federateID) const = 0;
311
318 virtual void setFlagOption(LocalFederateId federateID, int32_t flag, bool flagValue) = 0;
319
326 virtual bool getFlagOption(LocalFederateId federateID, int32_t flag) const = 0;
341 virtual InterfaceHandle registerPublication(LocalFederateId federateID,
342 std::string_view key,
343 std::string_view type,
344 std::string_view units) = 0;
345
350 virtual InterfaceHandle getPublication(LocalFederateId federateID,
351 std::string_view key) const = 0;
352
362 virtual InterfaceHandle registerInput(LocalFederateId federateID,
363 std::string_view key,
364 std::string_view type,
365 std::string_view units) = 0;
370 virtual InterfaceHandle getInput(LocalFederateId federateID, std::string_view key) const = 0;
371
375 virtual const std::string& getHandleName(InterfaceHandle handle) const = 0;
380 virtual void removeTarget(InterfaceHandle handle, std::string_view targetToRemove) = 0;
381
385 virtual const std::string& getExtractionUnits(InterfaceHandle handle) const = 0;
394 virtual const std::string& getInjectionUnits(InterfaceHandle handle) const = 0;
395
403 virtual const std::string& getInjectionType(InterfaceHandle handle) const = 0;
404
411 virtual const std::string& getExtractionType(InterfaceHandle handle) const = 0;
412
418 virtual void setHandleOption(InterfaceHandle handle, int32_t option, int32_t option_value) = 0;
419
424 virtual int32_t getHandleOption(InterfaceHandle handle, int32_t option) const = 0;
425
429 virtual void closeHandle(InterfaceHandle handle) = 0;
437 virtual void setValue(InterfaceHandle handle, const char* data, uint64_t len) = 0;
438
445 virtual const std::shared_ptr<const SmallBuffer>& getValue(InterfaceHandle handle,
446 uint32_t* inputIndex = nullptr) = 0;
447
452 virtual const std::vector<std::shared_ptr<const SmallBuffer>>&
453 getAllValues(InterfaceHandle handle) = 0;
454
463 virtual const std::vector<InterfaceHandle>& getValueUpdates(LocalFederateId federateID) = 0;
464
476 virtual InterfaceHandle registerEndpoint(LocalFederateId federateID,
477 std::string_view name,
478 std::string_view type) = 0;
479
486 virtual InterfaceHandle registerTargetedEndpoint(LocalFederateId federateID,
487 std::string_view name,
488 std::string_view type) = 0;
489
494 virtual InterfaceHandle getEndpoint(LocalFederateId federateID,
495 std::string_view name) const = 0;
496
503 virtual InterfaceHandle registerDataSink(LocalFederateId federateID, std::string_view name) = 0;
504
509 virtual InterfaceHandle getDataSink(LocalFederateId federateID,
510 std::string_view name) const = 0;
511
523 virtual InterfaceHandle registerCloningFilter(std::string_view filterName,
524 std::string_view type_in,
525 std::string_view type_out) = 0;
526
538 virtual InterfaceHandle registerFilter(std::string_view filterName,
539 std::string_view type_in,
540 std::string_view type_out) = 0;
541
551 virtual InterfaceHandle registerTranslator(std::string_view translatorName,
552 std::string_view endpointType,
553 std::string_view units) = 0;
554
566 virtual void addDestinationTarget(InterfaceHandle handle,
567 std::string_view dest,
568 InterfaceType hint = InterfaceType::UNKNOWN) = 0;
569
579 virtual void addSourceTarget(InterfaceHandle handle,
580 std::string_view name,
581 InterfaceType hint = InterfaceType::UNKNOWN) = 0;
582
587 virtual const std::string& getDestinationTargets(InterfaceHandle handle) const = 0;
588
592 virtual const std::string& getSourceTargets(InterfaceHandle handle) const = 0;
593
598 virtual InterfaceHandle getFilter(std::string_view name) const = 0;
599
604 virtual InterfaceHandle getTranslator(std::string_view name) const = 0;
605
615 virtual void addDependency(LocalFederateId federateID, std::string_view federateName) = 0;
616
623 virtual void linkEndpoints(std::string_view source, std::string_view dest) = 0;
624
630 virtual void addAlias(std::string_view interfaceKey, std::string_view alias) = 0;
631
634 virtual void makeConnections(const std::string& file) = 0;
635
639 virtual void dataLink(std::string_view source, std::string_view target) = 0;
644 virtual void addSourceFilterToEndpoint(std::string_view filter, std::string_view target) = 0;
649 virtual void addDestinationFilterToEndpoint(std::string_view filter,
650 std::string_view target) = 0;
651
664 virtual void send(InterfaceHandle sourceHandle, const void* data, uint64_t length) = 0;
677 virtual void sendTo(InterfaceHandle sourceHandle,
678 const void* data,
679 uint64_t length,
680 std::string_view destination) = 0;
681
697 virtual void
698 sendAt(InterfaceHandle sourceHandle, const void* data, uint64_t length, Time time) = 0;
699
716 virtual void sendToAt(InterfaceHandle sourceHandle,
717 const void* data,
718 uint64_t length,
719 std::string_view destination,
720 Time time) = 0;
721
728 virtual void sendMessage(InterfaceHandle sourceHandle, std::unique_ptr<Message> message) = 0;
729
733 virtual uint64_t receiveCount(InterfaceHandle destination) = 0;
734
739 virtual std::unique_ptr<Message> receive(InterfaceHandle destination) = 0;
740
747 virtual std::unique_ptr<Message> receiveAny(LocalFederateId federateID,
748 InterfaceHandle& endpoint_id) = 0;
749
753 virtual uint64_t receiveCountAny(LocalFederateId federateID) = 0;
754
760 virtual void
761 logMessage(LocalFederateId federateID, int logLevel, std::string_view messageToLog) = 0;
762
767 virtual void setFilterOperator(InterfaceHandle filter,
768 std::shared_ptr<FilterOperator> callback) = 0;
769
774 virtual void setTranslatorOperator(InterfaceHandle translator,
775 std::shared_ptr<TranslatorOperator> callback) = 0;
776
781 virtual void setFederateOperator(LocalFederateId fed,
782 std::shared_ptr<FederateOperator> callback) = 0;
783
791 virtual void setLoggingCallback(
792 LocalFederateId federateID,
793 std::function<void(int, std::string_view, std::string_view)> logFunction) = 0;
794
796 virtual void setLoggingLevel(int logLevel) = 0;
797
799 virtual void setLogFile(std::string_view lfile) = 0;
800
806 virtual void setGlobal(std::string_view valueName, std::string_view value) = 0;
807
816 virtual void sendCommand(std::string_view target,
817 std::string_view commandStr,
818 std::string_view source,
819 HelicsSequencingModes mode) = 0;
820
823 virtual std::pair<std::string, std::string> getCommand(LocalFederateId federateID) = 0;
824
827 virtual std::pair<std::string, std::string> waitCommand(LocalFederateId federateID) = 0;
828
840 virtual std::string
841 query(std::string_view target, std::string_view queryStr, HelicsSequencingModes mode) = 0;
842
855 virtual void setQueryCallback(LocalFederateId federateID,
856 std::function<std::string(std::string_view)> queryFunction,
857 int order) = 0;
858
864 virtual void setInterfaceInfo(InterfaceHandle handle, std::string_view info) = 0;
865
871 virtual const std::string& getInterfaceInfo(InterfaceHandle handle) const = 0;
878 virtual void
879 setInterfaceTag(InterfaceHandle handle, std::string_view tag, std::string_view value) = 0;
885 virtual const std::string& getInterfaceTag(InterfaceHandle handle,
886 std::string_view tag) const = 0;
887
894 virtual void
895 setFederateTag(LocalFederateId fid, std::string_view tag, std::string_view value) = 0;
902 virtual const std::string& getFederateTag(LocalFederateId fid, std::string_view tag) const = 0;
903 };
904
905 } // namespace helics
NO_ITERATION
constexpr auto NO_ITERATION
simplified alias to indicate that no iterations are needed
Definition: CoreTypes.hpp:128
helics::CoreFederateInfo
Definition: CoreFederateInfo.hpp:16
helics::Core
Definition: core/Core.hpp:41
helics::Core::setFederateTag
virtual void setFederateTag(LocalFederateId fid, std::string_view tag, std::string_view value)=0
helics::Core::setLoggingLevel
virtual void setLoggingLevel(int logLevel)=0
helics::Core::setCoreReadyToInit
virtual void setCoreReadyToInit()=0
helics::Core::Core
Core()=default
helics::Core::addDependency
virtual void addDependency(LocalFederateId federateID, std::string_view federateName)=0
helics::Core::timeRequest
virtual Time timeRequest(LocalFederateId federateID, Time next)=0
helics::Core::setHandleOption
virtual void setHandleOption(InterfaceHandle handle, int32_t option, int32_t option_value)=0
helics::Core::setLogFile
virtual void setLogFile(std::string_view lfile)=0
helics::Core::registerTranslator
virtual InterfaceHandle registerTranslator(std::string_view translatorName, std::string_view endpointType, std::string_view units)=0
helics::Core::receiveAny
virtual std::unique_ptr< Message > receiveAny(LocalFederateId federateID, InterfaceHandle &endpoint_id)=0
helics::Core::setQueryCallback
virtual void setQueryCallback(LocalFederateId federateID, std::function< std::string(std::string_view)> queryFunction, int order)=0
helics::Core::getCommand
virtual std::pair< std::string, std::string > getCommand(LocalFederateId federateID)=0
helics::Core::setLoggingCallback
virtual void setLoggingCallback(LocalFederateId federateID, std::function< void(int, std::string_view, std::string_view)> logFunction)=0
helics::Core::setGlobal
virtual void setGlobal(std::string_view valueName, std::string_view value)=0
helics::Core::enterInitializingMode
virtual bool enterInitializingMode(LocalFederateId federateID, IterationRequest iterate=NO_ITERATION)=0
helics::Core::getFederateTag
virtual const std::string & getFederateTag(LocalFederateId fid, std::string_view tag) const =0
helics::Core::getErrorCode
virtual int getErrorCode() const =0
helics::Core::closeHandle
virtual void closeHandle(InterfaceHandle handle)=0
helics::Core::getInput
virtual InterfaceHandle getInput(LocalFederateId federateID, std::string_view key) const =0
helics::Core::getExtractionType
virtual const std::string & getExtractionType(InterfaceHandle handle) const =0
helics::Core::getAllValues
virtual const std::vector< std::shared_ptr< const SmallBuffer > > & getAllValues(InterfaceHandle handle)=0
helics::Core::getEndpoint
virtual InterfaceHandle getEndpoint(LocalFederateId federateID, std::string_view name) const =0
helics::Core::getFilter
virtual InterfaceHandle getFilter(std::string_view name) const =0
helics::Core::sendAt
virtual void sendAt(InterfaceHandle sourceHandle, const void *data, uint64_t length, Time time)=0
helics::Core::getTranslator
virtual InterfaceHandle getTranslator(std::string_view name) const =0
helics::Core::setFilterOperator
virtual void setFilterOperator(InterfaceHandle filter, std::shared_ptr< FilterOperator > callback)=0
helics::Core::removeTarget
virtual void removeTarget(InterfaceHandle handle, std::string_view targetToRemove)=0
helics::Core::getHandleName
virtual const std::string & getHandleName(InterfaceHandle handle) const =0
helics::Core::addDestinationFilterToEndpoint
virtual void addDestinationFilterToEndpoint(std::string_view filter, std::string_view target)=0
helics::Core::getIdentifier
virtual const std::string & getIdentifier() const =0
helics::Core::registerCloningFilter
virtual InterfaceHandle registerCloningFilter(std::string_view filterName, std::string_view type_in, std::string_view type_out)=0
helics::Core::addSourceTarget
virtual void addSourceTarget(InterfaceHandle handle, std::string_view name, InterfaceType hint=InterfaceType::UNKNOWN)=0
helics::Core::setFederateOperator
virtual void setFederateOperator(LocalFederateId fed, std::shared_ptr< FederateOperator > callback)=0
helics::Core::addSourceFilterToEndpoint
virtual void addSourceFilterToEndpoint(std::string_view filter, std::string_view target)=0
helics::Core::getFederateId
virtual LocalFederateId getFederateId(std::string_view name) const =0
helics::Core::setInterfaceTag
virtual void setInterfaceTag(InterfaceHandle handle, std::string_view tag, std::string_view value)=0
helics::Core::sendMessage
virtual void sendMessage(InterfaceHandle sourceHandle, std::unique_ptr< Message > message)=0
helics::Core::setInterfaceInfo
virtual void setInterfaceInfo(InterfaceHandle handle, std::string_view info)=0
helics::Core::receiveCount
virtual uint64_t receiveCount(InterfaceHandle destination)=0
helics::Core::getHandleOption
virtual int32_t getHandleOption(InterfaceHandle handle, int32_t option) const =0
helics::Core::linkEndpoints
virtual void linkEndpoints(std::string_view source, std::string_view dest)=0
helics::Core::getSourceTargets
virtual const std::string & getSourceTargets(InterfaceHandle handle) const =0
helics::Core::getFederateName
virtual const std::string & getFederateName(LocalFederateId federateID) const =0
helics::Core::registerDataSink
virtual InterfaceHandle registerDataSink(LocalFederateId federateID, std::string_view name)=0
helics::Core::getInjectionType
virtual const std::string & getInjectionType(InterfaceHandle handle) const =0
helics::Core::getInterfaceInfo
virtual const std::string & getInterfaceInfo(InterfaceHandle handle) const =0
helics::Core::localError
virtual void localError(LocalFederateId federateID, int32_t errorCode, std::string_view errorString)=0
helics::Core::isConfigured
virtual bool isConfigured() const =0
helics::Core::setTimeProperty
virtual void setTimeProperty(LocalFederateId federateID, int32_t property, Time timeValue)=0
helics::Core::getInterfaceTag
virtual const std::string & getInterfaceTag(InterfaceHandle handle, std::string_view tag) const =0
helics::Core::sendTo
virtual void sendTo(InterfaceHandle sourceHandle, const void *data, uint64_t length, std::string_view destination)=0
helics::Core::query
virtual std::string query(std::string_view target, std::string_view queryStr, HelicsSequencingModes mode)=0
helics::Core::waitCommand
virtual std::pair< std::string, std::string > waitCommand(LocalFederateId federateID)=0
helics::Core::receiveCountAny
virtual uint64_t receiveCountAny(LocalFederateId federateID)=0
helics::Core::isOpenToNewFederates
virtual bool isOpenToNewFederates() const =0
helics::Core::getDestinationTargets
virtual const std::string & getDestinationTargets(InterfaceHandle handle) const =0
helics::Core::getFlagOption
virtual bool getFlagOption(LocalFederateId federateID, int32_t flag) const =0
helics::Core::addDestinationTarget
virtual void addDestinationTarget(InterfaceHandle handle, std::string_view dest, InterfaceType hint=InterfaceType::UNKNOWN)=0
helics::Core::registerTargetedEndpoint
virtual InterfaceHandle registerTargetedEndpoint(LocalFederateId federateID, std::string_view name, std::string_view type)=0
helics::Core::makeConnections
virtual void makeConnections(const std::string &file)=0
helics::Core::receive
virtual std::unique_ptr< Message > receive(InterfaceHandle destination)=0
helics::Core::globalError
virtual void globalError(LocalFederateId federateID, int32_t errorCode, std::string_view errorString)=0
helics::Core::getDataSink
virtual InterfaceHandle getDataSink(LocalFederateId federateID, std::string_view name) const =0
helics::Core::processCommunications
virtual void processCommunications(LocalFederateId fedId, std::chrono::milliseconds msToWait)=0
helics::Core::send
virtual void send(InterfaceHandle sourceHandle, const void *data, uint64_t length)=0
helics::Core::getErrorMessage
virtual std::string getErrorMessage() const =0
helics::Core::configureFromArgs
virtual void configureFromArgs(int argc, char *argv[])=0
helics::Core::getInjectionUnits
virtual const std::string & getInjectionUnits(InterfaceHandle handle) const =0
helics::Core::setIntegerProperty
virtual void setIntegerProperty(LocalFederateId federateID, int32_t property, int16_t propValue)=0
helics::Core::sendToAt
virtual void sendToAt(InterfaceHandle sourceHandle, const void *data, uint64_t length, std::string_view destination, Time time)=0
helics::Core::registerFederate
virtual LocalFederateId registerFederate(std::string_view name, const CoreFederateInfo &info)=0
helics::Core::getFederationSize
virtual int32_t getFederationSize()=0
helics::Core::logMessage
virtual void logMessage(LocalFederateId federateID, int logLevel, std::string_view messageToLog)=0
helics::Core::sendCommand
virtual void sendCommand(std::string_view target, std::string_view commandStr, std::string_view source, HelicsSequencingModes mode)=0
helics::Core::addAlias
virtual void addAlias(std::string_view interfaceKey, std::string_view alias)=0
helics::Core::getExtractionUnits
virtual const std::string & getExtractionUnits(InterfaceHandle handle) const =0
helics::Core::waitForDisconnect
virtual bool waitForDisconnect(std::chrono::milliseconds msToWait=std::chrono::milliseconds(0)) const =0
helics::Core::setFlagOption
virtual void setFlagOption(LocalFederateId federateID, int32_t flag, bool flagValue)=0
helics::Core::getAddress
virtual const std::string & getAddress() const =0
helics::Core::finalize
virtual void finalize(LocalFederateId federateID)=0
helics::Core::getValueUpdates
virtual const std::vector< InterfaceHandle > & getValueUpdates(LocalFederateId federateID)=0
helics::Core::enterExecutingMode
virtual iteration_time enterExecutingMode(LocalFederateId federateID, IterationRequest iterate=NO_ITERATION)=0
helics::Core::configure
virtual void configure(std::string_view configureString)=0
helics::Core::getValue
virtual const std::shared_ptr< const SmallBuffer > & getValue(InterfaceHandle handle, uint32_t *inputIndex=nullptr)=0
helics::Core::connect
virtual bool connect()=0
helics::Core::getCurrentTime
virtual Time getCurrentTime(LocalFederateId federateID) const =0
helics::Core::registerPublication
virtual InterfaceHandle registerPublication(LocalFederateId federateID, std::string_view key, std::string_view type, std::string_view units)=0
helics::Core::setValue
virtual void setValue(InterfaceHandle handle, const char *data, uint64_t len)=0
helics::Core::getIntegerProperty
virtual int16_t getIntegerProperty(LocalFederateId federateID, int32_t property) const =0
helics::Core::getTimeProperty
virtual Time getTimeProperty(LocalFederateId federateID, int32_t property) const =0
helics::Core::getPublication
virtual InterfaceHandle getPublication(LocalFederateId federateID, std::string_view key) const =0
helics::Core::~Core
virtual ~Core()=default
helics::Core::setTranslatorOperator
virtual void setTranslatorOperator(InterfaceHandle translator, std::shared_ptr< TranslatorOperator > callback)=0
helics::Core::disconnect
virtual void disconnect()=0
helics::Core::dataLink
virtual void dataLink(std::string_view source, std::string_view target)=0
helics::Core::registerFilter
virtual InterfaceHandle registerFilter(std::string_view filterName, std::string_view type_in, std::string_view type_out)=0
helics::Core::registerEndpoint
virtual InterfaceHandle registerEndpoint(LocalFederateId federateID, std::string_view name, std::string_view type)=0
helics::Core::isConnected
virtual bool isConnected() const =0
helics::Core::requestTimeIterative
virtual iteration_time requestTimeIterative(LocalFederateId federateID, Time next, IterationRequest iterate)=0
helics::Core::configureFromVector
virtual void configureFromVector(std::vector< std::string > args)=0
helics::Core::registerInput
virtual InterfaceHandle registerInput(LocalFederateId federateID, std::string_view key, std::string_view type, std::string_view units)=0
helics::InterfaceHandle
Definition: LocalFederateId.hpp:65
helics::LocalFederateId
Definition: LocalFederateId.hpp:22
core-data.hpp
HelicsSequencingModes
HelicsSequencingModes
Definition: helics_enums.h:427
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::IterationRequest
IterationRequest
Definition: CoreTypes.hpp:103
helics::InterfaceType
InterfaceType
Definition: CoreTypes.hpp:112
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::iteration_time
Definition: helicsTime.hpp:43