16 #include <nn/pia/clone/clone_Definitions.h>
17 #include <nn/pia/clone/clone_CloneElementBase.h>
18 #include <nn/pia/common/common_TreeMapNode.h>
19 #include <nn/pia/common/common_OffsetTreeMap.h>
20 #include <nn/pia/common/common_OffsetList.h>
73 return static_cast<Id>(m_TreeMapNode.GetKey() & 0xffffffff);
83 return m_pProtocol != NULL;
129 return m_ElementCollection.Find(elementId);
140 return m_ElementCollection.Find(elementId);
152 return (m_State == State_Active);
186 return m_pSendProfiler;
197 return m_pReceiveProfiler;
389 virtual void Trace(uint64_t flag)
const;
399 Type_Sequential = 0x04
402 virtual Type GetTypeVirtual()
const = 0;
405 typedef uint64_t Key;
408 static int32_t GetTreeMapNodeOffset()
410 NN_PIA_PRAGMA_PUSH_WARNINGS
411 NN_PIA_DISABLE_WARNING_CLANG_INVALID_OFFSETOF
412 return offsetof(CloneBase, m_TreeMapNode);
413 NN_PIA_PRAGMA_POP_WARNINGS
416 void UnregisterElementForce(CloneElementBase* pElement);
418 bool CheckElementSize(uint32_t sizeMax);
419 void AttachProtocol(CloneProtocol* pProtocol);
420 void DetachProtocol();
424 return static_cast<Type
>(m_TreeMapNode.GetKey() >> 48);
428 return static_cast<StationIndex>((m_TreeMapNode.GetKey() >> 32) & 0xff);
432 return m_TreeMapNode.GetKey();
436 return (static_cast<uint64_t>(type) << 48) | (
static_cast<uint64_t
>(stationIndex) << 32) | id;
447 State_SendingRestForUnregister,
448 State_SendFinishedForUnregister,
449 State_EndedForUnregister
452 State GetState()
const
457 CloneProfilerBase* GetSendProfilerPtr()
459 return m_pSendProfiler;
461 CloneProfilerBase* GetReceiveProfilerPtr()
463 return m_pReceiveProfiler;
475 OnEnter(stationIndex);
479 OnExit(stationIndex);
481 void Disconnect(
StationIndex stationIndex,
bool isValid)
483 OnDisconnect(stationIndex, isValid);
487 bool IsReceiveData()
const
489 return m_State != State_Inactive;
492 bool IsSendingData(
StationIndex stationIndex,
bool isDebug =
false)
const;
493 void TraceSendDataList()
const;
496 virtual void OnStartup()
499 virtual void OnCleanup()
505 virtual void OnSendFinished()
508 virtual bool IsEndProcessFinished()
521 virtual void OnDisconnect(
StationIndex stationIndex,
bool isValid)
526 virtual void OnRegister()
531 virtual bool IsReadyToSetValue()
const
535 virtual uint32_t GetDestBitmap()
const = 0;
536 virtual bool IsInRequest()
const
541 virtual uint8_t GetLocalRegisterCount()
const
545 virtual uint64_t GetRegisterCountAll()
const
549 virtual bool IsMatchLocalRegisterCount(uint64_t registerCountAll)
const
551 NN_PIA_UNUSED(registerCountAll);
555 void AddSendData(CloneElementBase::ISendToken* pToken);
556 void CancelSendData(CloneElementBase::ISendToken* pToken);
557 void ErrorEventDropped();
561 typedef common::OffsetList<CloneElementBase::ISendToken> SendDataList;
562 typedef common::OffsetList<CloneElementBase::ResendableSendToken> ResendableDataList;
565 class DataTokenAccessor
568 DataTokenAccessor(CloneBase* pClone, SystemTime time, SystemTime resendSpan,
bool isUnicast,
StationIndex stationIndex);
569 CloneElementBase::ISendToken* Get()
const
573 void Reset(
bool isUnicast,
StationIndex stationIndex, SystemTime resendSpan);
575 void Commit(uint32_t dispatchCount, uint32_t destBitmap);
579 void NextUnicastToken();
584 SystemTime m_ResendSpan;
585 CloneElementBase::ISendToken* m_pToken;
588 uint32_t m_TargetBitmap;
598 ListState m_ListState;
611 CommandType_Announce,
619 INVALID_COMMAND_INDEX = 0
625 explicit CommandToken(CloneBase* pClone)
626 : m_ListNode(), m_pClone(pClone), m_LastSendTime(InvalidSystemTime)
631 bool IsInList()
const
633 return m_ListNode.IsFreeListNode() ==
false;
635 virtual CommandType GetType()
const = 0;
636 virtual uint32_t GetDestStationBitmap()
const = 0;
637 Id GetCloneId()
const
639 return m_pClone->GetId();
641 SystemTime GetLastSendTime(
StationIndex stationIndex)
const
645 return m_LastSendTime;
649 PIA_ASSERT(IsUnicast());
651 return m_LastSendTimeArray[stationIndex];
654 void SetLastSendTime(SystemTime time,
StationIndex stationIndex)
658 m_LastSendTime = time;
662 PIA_ASSERT(IsUnicast());
664 m_LastSendTimeArray[stationIndex] = time;
667 const CloneBase* GetClone()
const
671 static int32_t GetListNodeOffset()
673 NN_PIA_PRAGMA_PUSH_WARNINGS
674 NN_PIA_DISABLE_WARNING_CLANG_INVALID_OFFSETOF
675 return offsetof(CommandToken, m_ListNode);
676 NN_PIA_PRAGMA_POP_WARNINGS
678 CloneBase* GetClonePtr()
683 virtual bool IsUnicast()
const
689 common::ListNode m_ListNode;
691 SystemTime m_LastSendTime;
696 class ClockCommandToken :
public CommandToken
699 ClockCommandToken(CloneBase* pClone)
700 : CommandToken(pClone)
712 explicit DataToken(CloneBase* pClone)
713 : m_ListNode(), m_pClone(pClone)
716 bool IsInList()
const
718 return m_ListNode.IsFreeListNode() ==
false;
720 CloneBase* GetClone()
724 bool IsReadyToEraseFromList()
const
726 return m_pClone->IsSendDataEmpty();
728 static int32_t GetListNodeOffset()
730 NN_PIA_PRAGMA_PUSH_WARNINGS
731 NN_PIA_DISABLE_WARNING_CLANG_INVALID_OFFSETOF
732 return offsetof(DataToken, m_ListNode);
733 NN_PIA_PRAGMA_POP_WARNINGS
737 common::ListNode m_ListNode;
742 CloneProtocol* GetProtocolPtr()
747 void RequestInitialData();
751 bool IsSendDataEmpty()
const
753 return m_SendDataList.IsEmpty() && m_ResendDataList.IsEmpty();
757 common::TreeMapNode<Key> m_TreeMapNode;
758 CloneProtocol* m_pProtocol;
762 typedef common::OffsetTreeMap<CloneElementBase::Id, CloneElementBase> ElementCollection;
763 ElementCollection m_ElementCollection;
766 SendDataList m_SendDataList;
767 ResendableDataList m_ResendDataList;
769 DataToken m_DataToken;
772 CloneProfilerBase* m_pSendProfiler;
773 CloneProfilerBase* m_pReceiveProfiler;
776 template <
int TEST_ID,
typename Arg>
777 static void Test(
const CloneBase& obj, Arg* pArg = NULL);
781 void SetElementNumToMonitoringData();
783 NN_PIA_DISALLOW_COPY(CloneBase);