INOS
cinostaskexdef.h
Go to the documentation of this file.
1//******************************************************************************
24//******************************************************************************
25
26#ifndef INC_CINOSTASKEXDEF_H
27#define INC_CINOSTASKEXDEF_H
28
29//
30//------------------------------------------------------------------------------
31// includes
32//------------------------------------------------------------------------------
33
34// system
35#include <inos.h>
36#include <cincotype.h>
37
38// C++
39#include <typeinfo>
40// project
41
42
43//------------------------------------------------------------------------------
44// definitions
45//------------------------------------------------------------------------------
46//
53typedef uint32 tMcAppError;
54
55#define DF_INOS_TASKEX_MSG_PARAM_NAME_LENGTH 32
56
57
58//------------------------------------------------------------------------------
59// forward declarations
60//------------------------------------------------------------------------------
61//
62
70{
71 public:
72 // message types
73 enum EMsgTypes {
74 eMsgCmd,
75 eMsgCall,
76 eMsgEvent,
77 eMsgReply,
78 eMsgUser,
79 eMsgSub,
80 eMsgInternal,
81 eMsgMessage
82 };
83
84 // reply id's. If extending this, consider doing the same
85 // change/extension at CINOSTaskEx::ERplId. If extending this enum,
86 // consider extending the 'inix' INCOExplorer, CIncoProcedure.cpp,
87 // CIncoProcedure::TicketCompleted which has a switch case which
88 // converts these values into strings.
89 enum ERplId {
90 eRplOk=0,
91 eRplSkipped,
92 eRplInComplete,
93 eRplIgnored,
94 eRplPaused, // Deprecated
95 eRplStopped,
96 eRplCanceled,
97 eRplRejected,
98 eRplFailed,
99 eRplError,
100 eRplFatal,
101 eRplTimeout
102 };
103
104 // array with strings for all reply id's.
105 static constexpr char* const s_pReplyIdStrings[CINOSTaskExDef::eRplTimeout + 1] = {
106 "OK",
107 "Skipped",
108 "Incomplete",
109 "Ignored",
110 "Paused",
111 "Stopped",
112 "Canceled",
113 "Rejected",
114 "Failed",
115 "Error",
116 "Fatal",
117 "Timeout"
118 };
119};
120
121class CINOSTaskExMsg;
122
123
124//------------------------------------------------------------------------------
125// class CINOSTaskExMsgParam
126//------------------------------------------------------------------------------
127
129{
130 public :
132 enum {
136 };
137 char* GetName()
138 {return m_pName;};
139 const char* GetName() const
140 {return m_pName;};
141 uint16 GetType() const
142 {return m_uType;};
145 { return m_uFlags;};
149 {return m_uTypeSize;};
150 const std::type_info* GetTypeInfo() const;
151 void* GetValue() {
152 if( m_uType == defType_pointer) {
153 // don't return CPtrContainerBase, as this class should be considered
154 // begin an implementation detail. Instead, return the pointer value:
155 return const_cast<void*>(((CINOSTaskExMsgParam::CPtrContainerBase*)m_uValue)->GetPointer());
156 }
157 if (m_pValue) return m_pValue; else return m_uValue;
158 };
159 const void* GetValue() const
160 {return const_cast<CINOSTaskExMsgParam*>(this)->GetValue();};
163 template <typename T>
164 T GetTypedValue() const {
165 // Is this of type pointer
166 if(m_uType == defType_pointer) {
167 // yes -> The value is a pointer container
168 CINOSTaskExMsgParam::CPtrContainerBase* pContainer =
169 (CINOSTaskExMsgParam::CPtrContainerBase*)m_uValue;
170
171 // Check the type of the container
172 if(*(pContainer->GetTypeInfo()) == typeid(T)) {
173 // Type is correct, call receive on the container, gets the pointer and
174 // sets back internals of the container if needed.
175
176 return ((CINOSTaskExMsgParam::CPtrContainer<T>*)pContainer)->Receive();
177 // If the compiler prints the following line:
178 //
179 // error: 'class CINOSTaskExMsgParam::CPtrContainer<void*>' has no member named 'Receive'
180 //
181 // A message parameter of type "void*" has been tried to be instantiated
182 // this is forbidden because in case of a "lost" message it
183 // is not possible to delete the according object without type
184 // information.
185 // Instead it is possible to either use type 'const void*' for
186 // constant data that doesn't need deallocation or to use the correct
187 // type (e.g. AddParam<CMyClass*>, GetResult<CMyClass*>) in which case the
188 // object will be correctly deallocated in case of a "lost" message.
189 //
190 // Don't fix this problem here, go to "instantiated from here" and change
191 // the type accordingly.
192 }
193 return T();
194 }
195 else {
196 return m_pValue ? (*((T*)&m_pValue)) : (*((T*)&m_uValue));
197 }
198 };
199
201 template <typename T>
203 if(m_uType != TINCOType<T>::eType) {
204 return 1; // TODO error code
205 }
206
207 // Is param of type pointer
208 if(m_uType == defType_pointer) {
209 auto pContainer = (CINOSTaskExMsgParam::CPtrContainerBase*)m_uValue;
210 pContainer->SetPointer(aValue);
211 // If the compiler prints the following line:
212 //
213 // error: no matching function for call to 'CINOSTaskExMsgParam::CPtrContainer<void*>::SetPointer(void*)'
214 //
215 // A message parameter of type "void*" has been tried to be instantiated
216 // this is forbidden because in case of a "lost" message it
217 // is not possible to delete the according object without type
218 // information.
219 // Instead it is possible to either use type 'const void*' for
220 // constant data that does not need deallocation or use the correct
221 // type (e.g. AddParam<CINOSMcDataInst*>) in which case the
222 // object will be correctly deallocated in case of a "lost" message.
223 //
224 // Don't fix this problem here, go to "instantiated from here" and change
225 // the type accordingly.
226 }
227 else {
228 SetValue(&aValue, sizeof(T), false);
229 }
230 return INOS_OK;
231 }
232
235 SetValue(value, false);
236 return INOS_OK;
237
238 }
239
242 {if (m_pValue) return m_pPartition->GetPartitionSize(); else return sizeof(m_uValue);};
243 void SetValue(const char* apValue, bool abInINCOVContext);
246 void SetValue(const void* apValue, const uint32 auDataLength, bool abInINCOVContext);
247 void SetName(const char* apName);
248 virtual void SetFlag(uint32 auFlag) {
249 INOS_OR(m_uFlags, auFlag);
250 }
251 virtual void ClearFlag(uint32 auFlag) {
252 INOS_AND(m_uFlags, ~auFlag);
253 }
254 bool IsNumber() const
255 {return (m_uType != defType_string);}
256 bool IsString() const
257 {return (m_uType == defType_string);}
281 const uint32 auBufferSize, const uint32 auDataLength, const bool abCut = false) const;
285 { return m_pNext; }
286 void SetNext(CINOSTaskExMsgParam* apParam)
287 { m_pNext = apParam; }
288 enum {
289 eFlgMandatory = 0x00000001,
290 eFlgNoSubstitution = 0x00000002,
291 eFlgOversized = 0x00000004,
292 eFlgStructure = 0x0000008,
293 };
294
295 // Dummy implementations of additional methods in CINOSTaskExMsgDefaultParam
296 virtual real64 GetMinValue() { return REAL64MIN;};
297 virtual real64 GetMaxValue() { return REAL64MAX;};
298 virtual const char* GetUnit() { return "";};
299 virtual uint64 GetCharacteristics() { return 0;};
300 virtual const char* GetComboData() { return NULL;};
301
309 template <typename T>
310 CINOSTaskExMsgParam(T aValue, const char* apName = NULL, bool abInINCOVContext = false) {
311 m_pValue = NULL; m_uFlags = 0; m_pNext = 0;
312 SetName(apName);
313 m_uType = TINCOType<T>::eType;
314 // Is param of type pointer
315 if(m_uType == defType_pointer) {
316 // Yes -> Create a pointer container
317 static_assert(sizeof(CPtrContainer<T>) <= sizeof(m_uValue), "PtrContainer doesn't fit into preallocated buffer.");
318 m_uTypeSize = sizeof(CPtrContainer<T>);
319 // Create a container for the pointer in place, 32 Bytes should
320 // be fairly enough for the CPtrContainer
321 new (&(m_uValue)) CPtrContainer<T>(aValue);
322 // If the compiler prints the following line:
323 //
324 // error: no matching function for call to 'CINOSTaskExMsgParam::CPtrContainer<void*>::CPtrContainer(void*&)'
325 //
326 // A message parameter of type "void*" has been tried to be instantiated
327 // this is forbidden because in case of a "lost" message it
328 // is not possible to delete the according object without type
329 // information.
330 // Instead it is possible to either use type 'const void*' for
331 // constant data that does not need deallocation or use the correct
332 // type (e.g. AddParam<CINOSMcDataInst*>) in which case the
333 // object will be correctly deallocated in case of a "lost" message.
334 //
335 // Don't fix this problem here, go to "instantiated from here" and change
336 // the type accordingly.
337 }
338 else {
339 m_uTypeSize = sizeof(aValue);
340
341 SetValue(&aValue, sizeof(T), false);
342 }
343 }
346 CINOSTaskExMsgParam(char* aValue, const char* apName = NULL, bool abInINCOVContext = false) {
347 m_pValue = NULL; m_uFlags = 0; m_pNext = 0;
348 SetName(apName);
349 m_uType = defType_string;
350 m_uTypeSize = 0;
351 SetValue(aValue, abInINCOVContext);
352 }
355 CINOSTaskExMsgParam(const char* aValue, const char* apName = NULL, bool abInINCOVContext = false) {
356 m_pValue = NULL; m_uFlags = 0; m_pNext = 0;
357 SetName(apName);
358 m_uType = defType_string;
359 m_uTypeSize = 0;
360 SetValue(aValue, abInINCOVContext);
361 }
364 : m_uFlags(std::move(a.m_uFlags)),
365 m_uType(std::move(a.m_uType)),
366 m_uTypeSize(std::move(a.m_uTypeSize)),
367 m_pValue(std::move(a.m_pValue)),
368 m_pPartition(std::move(a.m_pPartition)),
369 m_pNext(std::move(a.m_pNext))
370 {
371 SetName(a.m_cName);
372 if( !m_pValue ) {
373 memcpy(m_uValue, a.m_uValue, m_uTypeSize);
374 }
375 }
376
379 return new CINOSTaskExMsgParam(*this);
380 }
383
384 private :
385 void AllocExBuffer();
386 void FreeExBuffer();
387
388 private :
389
390 friend class CINOSTaskEx;
391 friend class CINOSTaskExMsg;
392 friend class CINOSTaskExMsgDefaultParam;
393 friend class CINOSTaskExTracer;
394 friend class CINOSEvtLogMsgArg;
395 friend class CMcResult;
396 friend class CMcResultStream;
397 friend class CINOSMovePath;
398
401 { m_cName[0] = 0; m_uFlags = 0; m_pNext = 0; m_pValue = 0;
402 m_uTypeSize = 0; m_uType = defType_Invalid;
403 memset(m_uValue, 0, sizeof(m_uValue));};
406
407
409 char m_cName[DF_INOS_TASKEX_MSG_PARAM_NAME_LENGTH];
411 char* m_pName = m_cName;
413 uint32 m_uFlags;
415 uint16 m_uType;
418 uint16 m_uTypeSize;
422 double m_uValue[4];
424 void* m_pValue;
426 CINOSPartitionMemory* m_pPartition = nullptr;
428 CINOSTaskExMsgParam* m_pNext;
429
430 //------------------------------------------------------------------------------
431 // local class declaration
432 //------------------------------------------------------------------------------
433 //
434 // CPtrContainerBase is the abstract base of all pointer containers
435 class CPtrContainerBase
436 {
437 public:
438 CPtrContainerBase(const std::type_info* aTypeInfo) :
439 m_pTypeInfo(aTypeInfo) {};
440
441 virtual ~CPtrContainerBase() {};
442
443 // Returns the pointer value
444 virtual const void* GetPointer() = 0;
445
446 template <typename T>
447 bool SetPointer(T pPointer) {
448 if(&typeid(T) != m_pTypeInfo) {
449 return false;
450 }
451 iSetPointer(reinterpret_cast<const void*>(pPointer));
452 return true;
453 };
454
455 // To avoid compilation errors we need to implement the double variant
456 // directly, even it is never called
457 bool SetPointer(double pPointer) {
458 return false;
459 };
460
461 // Get the type info, used for type checking or for reflection.
462 const std::type_info* GetTypeInfo() { return m_pTypeInfo; };
463 protected:
464
465 virtual void iSetPointer(const void* pPointer) = 0;
466 private:
467 const std::type_info* m_pTypeInfo;
468 };
469
470 // CPtrContainer<T> is the type specific derived class for each type.
471 // The non-specialiced template is for non-pointer types. It
472 // Should never be instanciated. Only pointer type variants should be
473 // instanciated. The template still needs to be a valid class to avoid
474 // compiler warnings.
475 template <class T>
476 class CPtrContainer : CPtrContainerBase
477 {
478 protected:
479 virtual void iSetPointer(const void* pPointer) override {};
480 public:
481 // Constructer yields an assert, it should never be called.
482 explicit CPtrContainer(T aValue) :
483 CPtrContainerBase((const std::type_info*)NULL) { ASSERT_ALWAYS(false); };
484 virtual ~CPtrContainer() {};
485
486 T Receive() {
487 // Originally, it was 'return T();', which caused warning with gcc7,
488 // complaining that the returned value may be uninitialized. This matches
489 // the explanation here, and thus the following solution:
490 // http://stackoverflow.com/questions/2143022/how-to-correctly-initialize-variable-of-template-type
491 return T{};
492 }
493 virtual const void* GetPointer() override { return NULL; }
494 };
495
496 // CPtrContainer<T*> is the partial specialization for non-const pointers
497 // it implements all members and deletes the date on destruction if
498 // needed.
499 template <class T>
500 class CPtrContainer<T*> : CPtrContainerBase
501 {
502 public:
503 explicit CPtrContainer(T* apPointer) :
504 CPtrContainerBase(&typeid(T*)),
505 m_pPointer(apPointer) {};
506
507 virtual ~CPtrContainer() {
508 if(m_pPointer)
509 delete m_pPointer;
510 };
511
512 // Receive returns the pointer and invalidates the internal
513 // pointer to avoid double deletes.
514 T* Receive() {
515 T* pTemp = m_pPointer;
516 m_pPointer = NULL;
517 return pTemp;
518 };
519 virtual const void* GetPointer() override { return m_pPointer; };
520
521 virtual void iSetPointer(const void* pPointer) override {
522 m_pPointer = (T*)pPointer;
523 };
524 private:
525 T* m_pPointer;
526 };
527
528 // CPtrContainer<const T*> is the partial specialization for const pointers
529 // it implements all members and does not delete the date on destruction if
530 // needed.
531 template <class T>
532 class CPtrContainer<const T*> : CPtrContainerBase
533 {
534 public:
535 explicit CPtrContainer(const T* apPointer) :
536 CPtrContainerBase(&typeid(const T*)),
537 m_pPointer(apPointer) {};
538
539 virtual ~CPtrContainer() {};
540
541 // Returns the pointer, no need to invalidate the pointer, as no
542 // delete is pervormed on const pointers.
543 const T* Receive() { return m_pPointer; }
544 virtual const void* GetPointer() override { return m_pPointer; }
545 virtual void iSetPointer(const void* pPointer) override {
546 m_pPointer = (T*)pPointer;
547 };
548
549 private:
550 const T* m_pPointer;
551 };
552
555};
556
557//------------------------------------------------------------------------------
558// TTemplate specialization for CINOSTaskExMsgParam::GetTypedValue for types
559// char* and const char*
560//------------------------------------------------------------------------------
561//
562// They are needed for GetResult<char*> and GetResult<const char*> to work.
563// They are not needed for GetParam as GetParam with strings is over
564// loaded and not a template specialization.
565template <>
567
568template <>
569const char* CINOSTaskExMsgParam::GetTypedValue() const;
570//------------------------------------------------------------------------------
571// Template class specialization for CPtrContainer<void*>
572//------------------------------------------------------------------------------
573// This class constructor is intentionally private. Type "void*" should not be
574// used with this template, instead "const void*" or any specific pointer type
575// should be used.
576template <>
577class CINOSTaskExMsgParam::CPtrContainer<void*> : CINOSTaskExMsgParam::CPtrContainerBase
578{
579private:
580 CPtrContainer() : CPtrContainerBase(NULL) {};
581public:
585 virtual const void* GetPointer() {return NULL; };
586};
587// If the compiler prints the following lines:
588//
589// error: cannot allocate an object of abstract type 'CINOSTaskExMsgParam::CPtrContainer<void*>'
590// note: error: no matching function for call to 'CINOSTaskExMsgParam::CPtrContainer<void*>::CPtrContainer(void*&)'
591// note: note: candidates are: CINOSTaskExMsgParam::CPtrContainer<void*>::CPtrContainer()
592// note: CINOSTaskExMsgParam::CPtrContainer<void*>::CPtrContainer(const CINOSTaskExMsgParam::CPtrContainer<void*>&)
593//
594// A message parameter of type "void*" has been tried to be instantiated
595// this is forbidden because in case of a "lost" message it
596// is not possible to delete the according object.
597// Instead it is possible to either use type 'const void*' for
598// constant data that doesn't need deallocation or use the correct
599// type (e.g. AddParam<CINOSMcDataInst*>) in which case the
600// object will be correctly deallocated in case of a "lost" message.
601//
602// Don't fix this problem here, go to "instantiated from here" and change
603// the type accordingly.
604
605//------------------------------------------------------------------------------
606// class CINOSTaskExMsgDefaultParam
607//------------------------------------------------------------------------------
608
610{
611public:
612 // Param object with additional format value like inco characteristics
613 // unit and combo data min/max values for default param objects.
614 virtual real64 GetMinValue() { return m_rMinValue;};
615 virtual void SetMinValue(real64 aMinValue) { m_rMinValue = aMinValue;};
616
617 virtual real64 GetMaxValue() { return m_rMaxValue;};
618 virtual void SetMaxValue(real64 aMaxValue) { m_rMaxValue = aMaxValue;};
619
620 virtual const char* GetUnit() { return m_pUnit != NULL ? m_pUnit : "";};
621 virtual void SetUnit(const char* apUnit);
622
623 virtual uint64 GetCharacteristics() { return m_uCharacteristics;};
624 virtual void SetCharacteristics(uint64 auCharacteristics) { m_uCharacteristics = auCharacteristics;};
625
626 virtual const char* GetComboData() { return m_pComboData;};
627 virtual void SetComboData(const char* apComboData);
628
629 friend class CINOSTaskExMsg;
630
634 m_rMinValue(REAL64MIN),
635 m_rMaxValue(REAL64MAX),
636 m_uCharacteristics(0),
637 m_pUnit(NULL),
638 m_pComboData(NULL) {};
642 m_rMinValue(a.m_rMinValue),
643 m_rMaxValue(a.m_rMaxValue),
644 m_uCharacteristics(a.m_uCharacteristics),
645 m_pUnit(NULL),
646 m_pComboData(NULL)
647 {
648 SetUnit(a.m_pUnit);
649 SetComboData(a.m_pComboData);
650 };
653 template <typename T>
656 m_rMinValue(REAL64MIN),
657 m_rMaxValue(REAL64MAX),
658 m_uCharacteristics(0),
659 m_pUnit(NULL),
660 m_pComboData(NULL) {};
665 m_rMinValue(REAL64MIN),
666 m_rMaxValue(REAL64MAX),
667 m_uCharacteristics(0),
668 m_pUnit(NULL),
669 m_pComboData(NULL) {};
672 explicit CINOSTaskExMsgDefaultParam(const char* aValue) :
674 m_rMinValue(REAL64MIN),
675 m_rMaxValue(REAL64MAX),
676 m_uCharacteristics(0),
677 m_pUnit(NULL),
678 m_pComboData(NULL) {};
679
682 return new CINOSTaskExMsgDefaultParam(*this);
683 }
684
687
688private:
689 real64 m_rMinValue;
690 real64 m_rMaxValue;
691 uint64 m_uCharacteristics;
692 char* m_pUnit;
693 char* m_pComboData;
695};
696
697//------------------------------------------------------------------------------
698
699#endif // INC_CINOSTASKEXDEF_H
700
701
702//------------------------------------------------------------------------------
703// end of file
#define DECLARE_DYNAMIC(aClass)
Definition cinospartitionmemory.h:328
uint32 tMcAppError
Definition cinostaskexdef.h:53
Definition cinosmcmodule.h:1900
Definition cinosmovepath.h:566
Definition cinospartitionmemory.h:157
Definition cinostaskexdef.h:70
Definition cinostaskexdef.h:610
virtual ~CINOSTaskExMsgDefaultParam()
destructor
CINOSTaskExMsgDefaultParam()
constructor
Definition cinostaskexdef.h:632
virtual CINOSTaskExMsgParam * Clone()
clone function (to be able to copy also derived member variables)
Definition cinostaskexdef.h:681
CINOSTaskExMsgDefaultParam(const CINOSTaskExMsgDefaultParam &a)
copy constructor
Definition cinostaskexdef.h:640
CINOSTaskExMsgDefaultParam(char *aValue)
Definition cinostaskexdef.h:663
CINOSTaskExMsgDefaultParam(T aValue)
Definition cinostaskexdef.h:654
CINOSTaskExMsgDefaultParam(const char *aValue)
Definition cinostaskexdef.h:672
virtual const void * GetPointer()
Definition cinostaskexdef.h:585
Definition cinostaskexdef.h:129
uint32 GetValueBufferSize()
Definition cinostaskexdef.h:241
uint32 SetTypedValue(const char *value)
SetTypedValue, makes the cast internally.
Definition cinostaskexdef.h:234
void ToString(char *apDest, uint32 aSize)
Writes the string representation into the buffer, always 0 determinated.
T GetTypedValue() const
Definition cinostaskexdef.h:164
int32 ToINCOValue(uint16 *apINCOType, uint8 *apINCOValue, const uint32 auBufferSize, const uint32 auDataLength, const bool abCut=false) const
CINOSTaskExMsgParam(const char *aValue, const char *apName=NULL, bool abInINCOVContext=false)
Definition cinostaskexdef.h:355
virtual CINOSTaskExMsgParam * Clone()
clone function (to be able to copy also derived member variables)
Definition cinostaskexdef.h:378
CINOSTaskExMsgParam * GetNext() const
Definition cinostaskexdef.h:284
uint32 GetFlag()
get param flags
Definition cinostaskexdef.h:144
CINOSTaskExMsgParam(char *aValue, const char *apName=NULL, bool abInINCOVContext=false)
Definition cinostaskexdef.h:346
CINOSTaskExMsgParam(T aValue, const char *apName=NULL, bool abInINCOVContext=false)
Definition cinostaskexdef.h:310
uint32 SetTypedValue(T aValue)
SetTypedValue.
Definition cinostaskexdef.h:202
uint32 GetTypeSize() const
Definition cinostaskexdef.h:148
virtual ~CINOSTaskExMsgParam()
destructor
void SetValue(const void *apValue, const uint32 auDataLength, bool abInINCOVContext)
CINOSTaskExMsgParam(CINOSTaskExMsgParam &&a)
Move CTOR used by e.g. CINCOVServerSession::AsyncResultReady.
Definition cinostaskexdef.h:363
void AddPrintfFormat(char *&apDest, bool abWithReadabilitySupport)
@ ePrintfFormatMaxSize
Definition cinostaskexdef.h:135
Definition cinostaskex.h:396
Definition cinostaskex.h:2362
Definition cinostaskex.h:966
uint32 INOS_OK
Definition inoserror.h:1677
#define INOS_OR(variable, mask)
Definition inosmacro.h:201
#define ASSERT_ALWAYS(f)
Definition inosmacro.h:696
#define INOS_AND(variable, mask)
Definition inosmacro.h:210