1 2 #include "debug.h" 3 #include "SystemTimeSource.h" 4 5 6 SystemTimeSource::SystemTimeSource() 7 : BMediaNode("System Clock"), 8 BTimeSource(), 9 fControlThread(-1) 10 { 11 TRACE("SystemTimeSource::SystemTimeSource\n"); 12 } 13 14 SystemTimeSource::~SystemTimeSource() 15 { 16 TRACE("SystemTimeSource::~SystemTimeSource enter\n"); 17 18 close_port(ControlPort()); 19 if (fControlThread != -1) { 20 status_t err; 21 wait_for_thread(fControlThread, &err); 22 } 23 TRACE("SystemTimeSource::~SystemTimeSource exit\n"); 24 } 25 26 BMediaAddOn* 27 SystemTimeSource::AddOn(int32 * internal_id) const 28 { 29 return NULL; 30 } 31 32 status_t 33 SystemTimeSource::TimeSourceOp(const time_source_op_info & op, void * _reserved) 34 { 35 TRACE("######## SystemTimeSource::TimeSourceOp\n"); 36 bigtime_t real = RealTime(); 37 PublishTime(real, real, 1.0); 38 return B_OK; 39 } 40 41 42 /* virtual */ void 43 SystemTimeSource::NodeRegistered() 44 { 45 ASSERT(fControlThread == -1); 46 fControlThread = spawn_thread(_ControlThreadStart, "System Clock control", 12, this); 47 resume_thread(fControlThread); 48 } 49 50 int32 51 SystemTimeSource::_ControlThreadStart(void *arg) 52 { 53 reinterpret_cast<SystemTimeSource *>(arg)->ControlThread(); 54 return 0; 55 } 56 57 void 58 SystemTimeSource::ControlThread() 59 { 60 TRACE("SystemTimeSource::ControlThread() enter\n"); 61 status_t err; 62 do { 63 err = WaitForMessage(B_INFINITE_TIMEOUT); 64 } while (err == B_OK || err == B_ERROR); 65 TRACE("SystemTimeSource::ControlThread() exit\n"); 66 } 67