00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef OPENDDS_DCPS_MESSAGETRACKER_H 00009 #define OPENDDS_DCPS_MESSAGETRACKER_H 00010 00011 #include "dds/DCPS/dcps_export.h" 00012 #include "dds/DCPS/PoolAllocator.h" 00013 #include "ace/Thread_Mutex.h" 00014 #include "ace/Condition_Thread_Mutex.h" 00015 00016 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 namespace OpenDDS { 00019 namespace DCPS { 00020 00021 /** 00022 * A simple message tracker to use to wait until all messages have been 00023 * accounted for being continuing processing. 00024 */ 00025 class OpenDDS_Dcps_Export MessageTracker { 00026 public: 00027 MessageTracker(const OPENDDS_STRING& msg_src); 00028 00029 /** 00030 * Indicate that a message has been to the transport layer. 00031 */ 00032 void message_sent(); 00033 00034 /** 00035 * Indicate that a message has been delivered by the transport layer. 00036 */ 00037 void message_delivered(); 00038 00039 /** 00040 * Indicate that a message has been dropped by the transport layer. 00041 */ 00042 void message_dropped(); 00043 00044 /** 00045 * Answer if there are any messages that have not been accounted for. 00046 */ 00047 bool pending_messages(); 00048 00049 /** 00050 * Block until all messages have been account for. 00051 */ 00052 void wait_messages_pending(OPENDDS_STRING& caller_message); 00053 00054 /** 00055 * For testing. 00056 */ 00057 int dropped_count(); 00058 00059 private: 00060 const OPENDDS_STRING msg_src_; // Source of tracked messages 00061 int dropped_count_; 00062 int delivered_count_; // Messages transmitted by transport layer 00063 int sent_count_; // Messages sent to transport layer 00064 00065 ACE_Thread_Mutex lock_; 00066 00067 /// All messages have been transported condition variable. 00068 ACE_Condition_Thread_Mutex done_condition_; 00069 }; 00070 00071 } // namespace DCPS 00072 } // namespace OpenDDS 00073 00074 OPENDDS_END_VERSIONED_NAMESPACE_DECL 00075 00076 #endif 00077