Loading...
Searching...
No Matches
SmartDataDistributionManager.h
Go to the documentation of this file.
1/*
2* Copyright 2023 MASES s.r.l.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*
16* Refer to LICENSE for more information.
17*/
18
19#if !defined(SMARTDATADISTRIBUTIONMANAGER_H__INCLUDED_)
20#define SMARTDATADISTRIBUTIONMANAGER_H__INCLUDED_
21
45{
46public:
61 void ResetTime();
94 void AddNanoseconds(unsigned int time);
95
96private:
97 ITimeMeasureWrapper *m_pITimeMeasureWrapper;
98};
99
106{
107public:
112
113protected:
118
119public:
135 void SetInformation(const char *channelName, IDataDistributionChannelBase *pIDataDistributionChannelBase, CHANNEL_HANDLE_PARAMETER, DDM_CHANNEL_DIRECTION direction);
143 OPERATION_RESULT StartChannel(unsigned long timeout);
151 OPERATION_RESULT StopChannel(unsigned long timeout);
159 OPERATION_RESULT Lock(unsigned long timeout);
173 OPERATION_RESULT SeekChannel(int64_t position);
186 OPERATION_RESULT WriteOnChannel(const char *key, size_t keyLen, void *buffer, size_t bufferLen, const BOOL waitAll = FALSE, const int64_t timestamp = DDM_NO_TIMESTAMP);
196 OPERATION_RESULT ReadFromChannel(int64_t offset, size_t *dataLen, void **buffer);
210 const char *GetChannelName();
216 int64_t GetTimestamp();
222 int64_t GetOffset();
234 virtual void OnDataAvailable(const char *key, size_t keyLen, const void *buffer, const size_t len);
245 virtual void OnDataAvailable(const std::string key, const void *buffer, const size_t len);
254 virtual void OnConditionOrError(const OPERATION_RESULT errorCode, const int nativeCode, const char *subSystemReason);
263 virtual void OnConditionOrError(const OPERATION_RESULT errorCode, const int nativeCode, const std::string subSystemReason);
264
265protected:
274
275private:
276 const char *m_ChannelName;
277 int64_t m_timestamp;
278 int64_t m_offset;
279 CHANNEL_HANDLE m_channelHandle;
280 IDataDistributionChannelBase *m_pIDataDistributionChannelBase;
281 DDM_CHANNEL_DIRECTION m_Direction;
282};
283
290{
291public:
309 OPERATION_RESULT Initialize(const char *conf_file, const char *hostAddress = 0, const char *channelTrailer = 0);
320 OPERATION_RESULT Initialize(const char *arrayParams[], int len, const char *hostAddress = 0, const char *channelTrailer = 0);
330 OPERATION_RESULT RequestMastershipManager(const char *hostAddress = NULL, const char *arrayParams[] = NULL, int len = 0);
338 BOOL Start(unsigned long timeout);
346 BOOL Stop(unsigned long timeout);
352 std::string GetProtocol();
358 std::string GetProtocolLib();
364 std::string GetMastershipLib();
365
366protected:
367 // IDataDistributionCallback
376 virtual const char *OnConfiguration(const char *channelName, const char *key, const char *value);
389 virtual void OnLogging(DDM_LOG_LEVEL level, const char *source, const char *function, const char *logStr);
398 virtual void OnCompletelyDisconnected(const char *channelName, const char *reason);
399 // IDataDistributionMastershipCallback
409 virtual void OnClusterStateChange(DDM_CLUSTEREVENT change, int64_t serverid);
419 virtual void OnStateChange(DDM_INSTANCE_STATE newState, DDM_INSTANCE_STATE oldState);
429 virtual void OnStateReady(void *pState, int64_t len);
439 virtual void OnRequestedState(void **pState, size_t *len);
449 virtual void OnMultiplePrimary(int64_t myId, int64_t otherId);
458 virtual void FirstStateChange(DDM_INSTANCE_STATE newState);
468 virtual void ChangingState(DDM_INSTANCE_STATE actualState, DDM_INSTANCE_STATE futureState);
477 virtual void ChangedState(DDM_INSTANCE_STATE actualState);
478
479protected:
483};
484
490template <typename T>
492{
493public:
512 T *CreateSmartChannel(const char *channelName, DDM_CHANNEL_DIRECTION direction = DDM_CHANNEL_DIRECTION::ALL, const char *arrayParams[] = NULL, int len = 0)
513 {
514 static_assert(std::is_base_of<SmartDataDistributionChannel, T>::value, "type parameter of this class must derive from SmartDataDistributionChannel");
516 return NULL;
517 T *pSmartChannelT = new T();
518 SmartDataDistributionChannel *pSmartChannel = (SmartDataDistributionChannel *)pSmartChannelT;
520 CHANNEL_HANDLE_PARAMETER = pChannelBase->CreateChannel(channelName, (IDataDistributionChannelCallback *)pSmartChannel, direction, arrayParams, len);
521 pSmartChannel->SetInformation(channelName, pChannelBase, channelHandle, direction);
522
523 return pSmartChannelT;
524 }
525};
526
527#endif // End SMARTDATADISTRIBUTIONMANAGER_H__INCLUDED_
DDM_CHANNEL_DIRECTION
DDM_CHANNEL_DIRECTION type.
Definition DataDistributionManagerEnums.h:70
DDM_LOG_LEVEL
DDM_LOG_LEVEL type.
Definition DataDistributionManagerEnums.h:87
DDM_INSTANCE_STATE
DDM_INSTANCE_STATE type.
Definition DataDistributionManagerEnums.h:112
DDM_CLUSTEREVENT
DDM_CLUSTEREVENT type.
Definition DataDistributionManagerEnums.h:133
#define DDM_NO_TIMESTAMP
Definition to avoid timestamp on write.
Definition DataDistributionManagerTypes.h:76
long OPERATION_RESULT
OPERATION_RESULT type.
Definition DataDistributionManagerTypes.h:102
#define CHANNEL_HANDLE_PARAMETER
Channel handle parameter definition.
Definition DataDistributionManagerTypes.h:89
#define CHANNEL_HANDLE
Channel handle definition.
Definition DataDistributionManagerTypes.h:84
#define OPERATION_FAILED(or)
Check if operation failed.
Definition DataDistributionManagerTypes.h:110
DataDistributionManager library.
The C++ callback interface to be externally implemented.
Definition DataDistributionManager.h:212
Base interface to be implemented from channel manager.
Definition DataDistributionManager.h:664
virtual CHANNEL_HANDLE CreateChannel(const char *channelName, IDataDistributionChannelCallback *dataCb, DDM_CHANNEL_DIRECTION direction=DDM_CHANNEL_DIRECTION::ALL, const char *arrayParams[]=NULL, int len=0)=0
Creates a new channel.
The C++ callback interface to be externally implemented.
Definition DataDistributionManager.h:405
The C++ callback interface to be externally implemented.
Definition DataDistributionManager.h:550
Interface to be implemented from mastership subsystem.
Definition DataDistributionManager.h:895
Interface to be implemented from common manager.
Definition DataDistributionManager.h:1027
virtual IDataDistributionSubsystem * GetSubsystemManager()=0
Returns the allocated communication subsystem.
Interface to manage time information.
Definition DataDistributionManager.h:111
Smart class to manage IDataDistributionCallback and IDataDistributionMastershipCallback.
Definition SmartDataDistributionManager.h:290
virtual void OnMultiplePrimary(int64_t myId, int64_t otherId)
Callback invoked when multiple primary server are detected.
virtual void OnStateReady(void *pState, int64_t len)
Callback invoked when a state transfer is completed.
IDataDistribution * m_pIDataDistribution
Definition SmartDataDistributionManager.h:480
IDataDistributionMastershipCommon * m_pIDataDistributionMastershipCommon
Definition SmartDataDistributionManager.h:481
~SmartDataDistributionBase()
Destructor of SmartDataDistributionBase.
virtual void OnClusterStateChange(DDM_CLUSTEREVENT change, int64_t serverid)
Callback invoked to report cluster state change.
virtual const char * OnConfiguration(const char *channelName, const char *key, const char *value)
Function invoked during configuration validation.
OPERATION_RESULT RequestMastershipManager(const char *hostAddress=NULL, const char *arrayParams[]=NULL, int len=0)
Allocate and initialize the mastership manager.
virtual void OnLogging(DDM_LOG_LEVEL level, const char *source, const char *function, const char *logStr)
Function invoked when a log is emitted from subsystem.
virtual void FirstStateChange(DDM_INSTANCE_STATE newState)
Callback invoked to report a first state change.
BOOL Stop(unsigned long timeout)
Stop the common manager.
virtual void OnStateChange(DDM_INSTANCE_STATE newState, DDM_INSTANCE_STATE oldState)
Callback invoked to report a state change.
virtual void OnCompletelyDisconnected(const char *channelName, const char *reason)
Callback invoked on a complete disconnection.
std::string GetMastershipLib()
Returns the mastership library in use from IDataDistribution instance.
BOOL Start(unsigned long timeout)
Start the common manager.
virtual void OnRequestedState(void **pState, size_t *len)
Callback invoked when a state transfer is requested.
SmartDataDistributionBase()
Initialize a new SmartDataDistributionBase.
std::string GetProtocolLib()
Returns the protocol library in use from IDataDistribution instance.
OPERATION_RESULT m_pInitializeHRESULT
Definition SmartDataDistributionManager.h:482
OPERATION_RESULT Initialize(const char *conf_file, const char *hostAddress=0, const char *channelTrailer=0)
Initialize SmartDataDistributionBase system.
OPERATION_RESULT Initialize(const char *arrayParams[], int len, const char *hostAddress=0, const char *channelTrailer=0)
Initialize IDataDistribution instance.
virtual void ChangingState(DDM_INSTANCE_STATE actualState, DDM_INSTANCE_STATE futureState)
Callback invoked to report a starting instance state change.
virtual void ChangedState(DDM_INSTANCE_STATE actualState)
Callback invoked to report a finished instance state change.
std::string GetProtocol()
Returns the protocol in use from IDataDistribution instance.
Smart class to manage IDataDistributionChannelCallback.
Definition SmartDataDistributionManager.h:106
OPERATION_RESULT StopChannel(unsigned long timeout)
Stops the channel.
int64_t GetTimestamp()
Returns the timestamp.
virtual void OnConditionOrError(const OPERATION_RESULT errorCode, const int nativeCode, const char *subSystemReason)
Function to override to receive condition or error.
virtual void OnDataAvailable(const char *key, size_t keyLen, const void *buffer, const size_t len)
Function to override to receive data available.
const char * GetChannelName()
Returns the channel name.
virtual void OnUnderlyingEvent(const CHANNEL_HANDLE_PARAMETER, const UnderlyingEventData *uEvent)
Function to override to receive UnderlyingEventData.
OPERATION_RESULT Unlock()
Unlock the channel.
int64_t GetOffset()
Returns the actual channel offset.
~SmartDataDistributionChannel()
Destructor of SmartDataDistributionChannel.
OPERATION_RESULT WriteOnChannel(const char *key, size_t keyLen, void *buffer, size_t bufferLen, const BOOL waitAll=FALSE, const int64_t timestamp=DDM_NO_TIMESTAMP)
Writes data on the channel.
OPERATION_RESULT ChangeChannelDirection(DDM_CHANNEL_DIRECTION direction)
Change the DDM_CHANNEL_DIRECTION of the channel.
SmartDataDistributionChannel()
Initialize a new SmartDataDistributionChannel.
void SetInformation(const char *channelName, IDataDistributionChannelBase *pIDataDistributionChannelBase, CHANNEL_HANDLE_PARAMETER, DDM_CHANNEL_DIRECTION direction)
Sets information on SmartDataDistributionChannel.
virtual void OnDataAvailable(const std::string key, const void *buffer, const size_t len)
Function to override to receive data available.
OPERATION_RESULT SeekChannel(int64_t position)
Seeks the channel.
DDM_CHANNEL_DIRECTION GetDirection()
Returns the DDM_CHANNEL_DIRECTION channel direction.
OPERATION_RESULT Lock(unsigned long timeout)
Locks the channel.
OPERATION_RESULT ReadFromChannel(int64_t offset, size_t *dataLen, void **buffer)
Reads data from the channel.
virtual void OnConditionOrError(const OPERATION_RESULT errorCode, const int nativeCode, const std::string subSystemReason)
Function to override to receive condition or error.
OPERATION_RESULT StartChannel(unsigned long timeout)
Starts the channel.
Smart class to manage DataDistribution.
Definition SmartDataDistributionManager.h:492
~SmartDataDistribution()
Destructor of SmartDataDistribution.
Definition SmartDataDistributionManager.h:501
SmartDataDistribution()
Initialize a new SmartDataDistribution.
Definition SmartDataDistributionManager.h:497
T * CreateSmartChannel(const char *channelName, DDM_CHANNEL_DIRECTION direction=DDM_CHANNEL_DIRECTION::ALL, const char *arrayParams[]=NULL, int len=0)
Creates a new smart channel.
Definition SmartDataDistributionManager.h:512
Smart class to manage ITimeMeasureWrapper.
Definition SmartDataDistributionManager.h:45
SmartTimeMeasureWrapper()
Initialize a new SmartTimeMeasureWrapper.
int64_t ElapsedMilliseconds()
Reports the elapsed time in milliseconds.
~SmartTimeMeasureWrapper()
Destructor of SmartTimeMeasureWrapper.
int64_t ElapsedMicroseconds()
Reports the elapsed time in microseconds.
void ResetTime()
Reset the timer.
int64_t ElapsedNanoseconds()
Reports the elapsed time in nanoseconds.
void AddNanoseconds(unsigned int time)
Adds nanoseconds time to actual value.
Class to reports information from transport subsystem.
Definition DataDistributionManager.h:274