void info_out_data_listener_exec_i::on_one_data ( const ::DDSHello & datum, const ::CCM_DDS::ReadInfo & /* info */) { ++this->received_; ACE_CString rec (datum.hello.in ()); ACE_Date_Time now; int const sec_rec = ACE_OS::atoi (rec.substr (0, 2).c_str() ); if (sec_rec > 0) { int usec_rec = ACE_OS::atoi (rec.substr (3, 6).c_str ()); if (sec_rec != now.second ()) { usec_rec += 10000000; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("<%C> received <%C> - <%d>. difference <%d>\n"), this->name_.c_str (), datum.hello.in (), datum.iterator, now.microsec () - usec_rec)); } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("<%C> received <%C> - <%d>.\n"), this->name_.c_str (), datum.hello.in (), datum.iterator)); } }
ACE_CString Sender_exec_i::create_message (const ACE_CString &msg) { if (!this->log_time_) return msg; char timestamp[16]; ACE_Date_Time now; ACE_OS::sprintf (timestamp, "%02d.%06d", static_cast<int> (now.second()), static_cast<int> (now.microsec ())); ACE_CString ret (timestamp); ret = ret + " " + msg; return ret.c_str (); }
void set_system_time(const ACE_Time_Value& tv) { # if defined (ACE_WIN32) ACE_Date_Time curdt (tv); SYSTEMTIME sys_time; sys_time.wDay = ACE_Utils::truncate_cast <WORD> (curdt.day ()); sys_time.wMonth = ACE_Utils::truncate_cast <WORD> (curdt.month ()); sys_time.wYear = ACE_Utils::truncate_cast <WORD> (curdt.year ()); sys_time.wHour = ACE_Utils::truncate_cast <WORD> (curdt.hour ()); sys_time.wMinute = ACE_Utils::truncate_cast <WORD> (curdt.minute ()); sys_time.wSecond = ACE_Utils::truncate_cast <WORD> (curdt.second ()); sys_time.wMilliseconds = ACE_Utils::truncate_cast <WORD> (curdt.microsec () / 1000); if (!::SetLocalTime (&sys_time)) # else timespec_t curts; curts = tv; if (ACE_OS::clock_settime (CLOCK_REALTIME, &curts) != 0) # endif { ACE_DEBUG((LM_INFO, "(%P|%t) Unable to reset OS time. Insufficient privileges or not supported.\n")); } }
bool test_timer (ACE_Condition_Thread_Mutex& condition_, ACE_Time_Value& waittime, bool monotonic = false) { bool status = true; MyTask task1; task1.create_reactor (); task1.start (1); TestHandler test_handler (task1.get_reactor ()); // The second reactor that uses a hrtimer will trigger a timeout in // 5 seconds. At the same moment we calculate a timeout for the condition // 3 seconds in the future. Than we set the time 4 seconds back. // at the moment now the condition timeouts the trigger should have not // been executed. This is because with hrtime the trigger will call in 5 // seconds and the condition in 3 seconds, independent of any time change // meaning that the timeout should trigger if (!test_handler.trigger_in (ACE_Time_Value (5, 0))) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Unable to schedule trigger.\n"), false); waittime += ACE_Time_Value (3,0); // reset system clock 4 seconds backwards ACE_Time_Value curtime = ACE_OS::gettimeofday (); curtime -= ACE_Time_Value (4, 0); # if defined (ACE_WIN32) ACE_Date_Time curdt (curtime); SYSTEMTIME sys_time; sys_time.wDay = ACE_Utils::truncate_cast <WORD> (curdt.day ()); sys_time.wMonth = ACE_Utils::truncate_cast <WORD> (curdt.month ()); sys_time.wYear = ACE_Utils::truncate_cast <WORD> (curdt.year ()); sys_time.wHour = ACE_Utils::truncate_cast <WORD> (curdt.hour ()); sys_time.wMinute = ACE_Utils::truncate_cast <WORD> (curdt.minute ()); sys_time.wSecond = ACE_Utils::truncate_cast <WORD> (curdt.second ()); sys_time.wMilliseconds = ACE_Utils::truncate_cast <WORD> (curdt.microsec () / 1000); if (!::SetLocalTime (&sys_time)) # else timespec_t curts; curts = curtime; if (ACE_OS::clock_settime (CLOCK_REALTIME, &curts) != 0) # endif { ACE_DEBUG((LM_INFO, "(%P|%t) Unable to reset OS time. Insufficient privileges or not supported.\n")); } else { ACE_DEBUG((LM_INFO, "(%P|%t) Going to wait on condition until %#T.\n", &waittime)); if (condition_.wait (&waittime) != -1 || errno != ETIME) { ACE_ERROR ((LM_ERROR, "ERROR: No errno or return -1\n")); status = 1; } ACE_DEBUG((LM_INFO, "(%P|%t) Condition wait returned at %#T.\n", &waittime)); if (test_handler.timeout_triggered ()) { if (monotonic) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: timer handler shouldn't have " "triggered because we used monotonic condition timing!\n")); status = false; } else ACE_DEBUG ((LM_INFO, "(%P|%t) timer handler " "triggered because we used non-monotonic condition timing!\n")); } else { if (!monotonic) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: timer handler should have " "triggered because we used non-monotonic condition timing!\n")); status = false; } else ACE_DEBUG ((LM_INFO, "(%P|%t) timer handler has not " "triggered because we used monotonic condition timing!\n")); } // reset system clock to correct time curtime = ACE_OS::gettimeofday (); curtime += ACE_Time_Value (4, 0); # if defined (ACE_WIN32) curdt.update (curtime); SYSTEMTIME sys_time; sys_time.wDay = ACE_Utils::truncate_cast <WORD> (curdt.day ()); sys_time.wMonth = ACE_Utils::truncate_cast <WORD> (curdt.month ()); sys_time.wYear = ACE_Utils::truncate_cast <WORD> (curdt.year ()); sys_time.wHour = ACE_Utils::truncate_cast <WORD> (curdt.hour ()); sys_time.wMinute = ACE_Utils::truncate_cast <WORD> (curdt.minute ()); sys_time.wSecond = ACE_Utils::truncate_cast <WORD> (curdt.second ()); sys_time.wMilliseconds = ACE_Utils::truncate_cast <WORD> (curdt.microsec () / 1000); if (!::SetLocalTime (&sys_time)) # else curts = curtime; if (ACE_OS::clock_settime (CLOCK_REALTIME, &curts) != 0) # endif { ACE_DEBUG((LM_INFO, "(%P|%t) Unable to reset OS time. Insufficient privileges or not supported.\n")); } } ACE_DEBUG((LM_INFO, "(%P|%t) Asking worker thread to finish.\n")); task1.stop (); ACE_Thread_Manager::instance ()->wait (); return status; }
int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { ::DDS::ReturnCode_t retcode; ::DDS::StringDataWriter *string_writer = 0; ::DDS::Topic *topic = 0; ::DDS::DataWriter *data_writer = 0; int main_result = 1; /* error by default */ if (parse_args (argc, argv) != 0) return 1; ACE_Time_Value tv (0, 1000); //1 msec /* Create the domain participant */ ::DDS::DomainParticipant *participant = ::DDS::DomainParticipantFactory::get_instance()-> create_participant( 0, /* Domain ID */ DDS_PARTICIPANT_QOS_DEFAULT, /* QoS */ 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!participant) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create domain participant.\n"))); goto clean_exit; } /* Create the topic "Hello, World" for the String type */ topic = participant->create_topic( "Hello, World", /* Topic name*/ ::DDS::StringTypeSupport::get_type_name(), /* Type name */ DDS_TOPIC_QOS_DEFAULT, /* Topic QoS */ 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!topic) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create topic.\n"))); goto clean_exit; } /* Create the data writer using the default publisher */ data_writer = participant->create_datawriter( topic, DDS_DATAWRITER_QOS_DEFAULT, /* QoS */ 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!data_writer) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create data writer.\n"))); goto clean_exit; } /* Perform a safe type-cast from a generic data writer into a * specific data writer for the type "DDS::String" */ string_writer = ::DDS::StringDataWriter::narrow(data_writer); if (!string_writer) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("DDS_StringDataWriter_narrow failed.\n"))); /* In this specific case, this will never fail */ goto clean_exit; } // Sleep a couple seconds to allow discovery to happen ACE_OS::sleep (1); /* --- Write Data ----------------------------------------------------- */ for (int i = 0; i < number_of_iterations; i++) { char timestamp[16]; ACE_CString msg (send_string); ACE_CString ret; ACE_Date_Time now; ACE_OS::sprintf (timestamp, "%02d.%d", static_cast<int> (now.second()), static_cast<int> (now.microsec ())); ret.set (timestamp); ret = ret + " " + msg; retcode = string_writer->write( ret.c_str (), DDS_HANDLE_NIL); if (retcode != DDS_RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Write failed: %d.\n"), retcode)); } ACE_OS::sleep (tv); } /* --- Clean Up ------------------------------------------------------- */ main_result = 0; clean_exit: ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Exiting."))); if (participant) { retcode = participant->delete_contained_entities(); if (retcode != DDS_RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Deletion failed.\n"))); main_result = 1; } retcode = ::DDS::DomainParticipantFactory::get_instance()-> delete_participant(participant); if (retcode != DDS_RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Deletion failed.\n"))); main_result = 1; } } return main_result; }
int main(int argc, char **args) { // no parms if(argc < 3) { cout << "usage: " << args[0] << " dataName roiName [tr localPort remoteHost remotePort]" << endl; return 1; } // parms int arg = 1; string dataName(args[arg]); arg++; string roiName((argc > arg) ? args[arg] : "active"); arg++; float tr = atof((argc > arg) ? args[arg] : "2"); arg++; unsigned short localPort = (unsigned short) atoi((argc > arg) ? args[arg] : "15002"); arg++; string host((argc > arg) ? args[arg] : "localhost"); arg++; unsigned short remotePort = (unsigned short) atoi((argc > arg) ? args[arg] : "15003"); arg++; // Local server address. ACE_INET_Addr remote_addr(remotePort, host.c_str()); ACE_INET_Addr my_addr(localPort); // Data transfer object. ACE_SOCK_Stream stream; // Initialize the connector. ACE_SOCK_Connector connector; char messageTerminationChar = '\n'; bool entered = false; // keep making new connections FOREVER! for(int t = 1; !connector.connect(stream, remote_addr); t++) { entered = true; stringstream xml; ACE_Date_Time time; xml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << "<info>" << "<data name=\"" << dataName << "\" roi=\"" << roiName << "\" tr=\"" << t << "\">" << time.second() << "." << time.microsec() << "</data>" << "</info>"; unsigned int sent = stream.send_n(xml.str().c_str(), xml.str().length()); if(sent < xml.str().length()) { cerr << "incomplete send" << endl; return false; } stream.send_n(&messageTerminationChar,1); stream.close(); cout << "sent " << xml.str() << endl; sleep(tr); } if(!entered) { cout << "error connecting" << endl; } return 0; }