Download presentation
Presentation is loading. Please wait.
Published byLewis Blake Shields Modified over 8 years ago
1
get_gmt 函数在 windows 下的实现 TimeOfDay TimeImpl:: get_gmt() throw(CORBA::SystemException) {time_t time_now=time(0); = time_t time_now=time(NULL); struct tm* time_p=localtime(&time_now);// 取本机的时间 struct tm* time_p=gmtime(&sys);// 取格林威治时间 TimeOfDay tod; tod.hour=time_p->tm_hour; tod.minute=time_p->tm_min; tod.second=time_p->tm_sec; return tod;}
2
get_gmt 函数在 windows 下的实现 TimeOfDay TimeImpl:: get_gmt() throw(CORBA::SystemException) { time_t time_now=time(0);// 取当前日期和时间的值 time_t 是整数类 型,例如: 1095876767 char *p=ctime(&time_now);// 把此值转换为字符串,例如: Thu sep 23 02:12:47 2004 TimeOfDay tod; tod.hour=((int)p[11]-48)*10+(p[12]-48); tod.minute=((int)p[14]-48)*10+(p[15]-48); tod.second=((int)p[17]-48)*10+(p[18]-48); return tod;}
3
get_gmt 函数在 windows 下的实现 TimeOfDay TimeImpl:: get_gmt() throw(CORBA::SystemException) {char *p=__TIME__; TimeOfDay tod; tod.hour=((int)p[0]-48)*10+(p[1]-48); tod.minute=((int)p[3]-48)*10+(p[4]-48); tod.second=((int)p[6]-48)*10+(p[7]-48); return tod; }
4
服务器 #include #include "time_s.hh" class TimeImpl: public virtual POA_Time, { public: virtual TimeOfDay get_gmt() throw(CORBA::SystemException); };
5
TimeOfDay TimeImpl:: get_gmt() throw(CORBA::SystemException) { time_t time_now=time(0); struct tm* time_p=localtime(&time_now); TimeOfDay tod; tod.hour=time_p->tm_hour; tod.minute=time_p->tm_min; tod.second=time_p->tm_sec; return tod; }
6
int main(int argc, char* const* argv) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // get a reference to the root POA CORBA::Object_var obj = orb- >resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(obj); // get the POA Manager PortableServer::POAManager_var poa_manager = rootPOA- >the_POAManager(); //Activate POA Manager poa_manager->activate();
7
// Create the servant TimeImpl time_servant; //Object to string Time_var tm=time_servant._this(); CORBA::String_var str=orb->object_to_string(tm); cout<<str<<endl; orb->run(); // Wait for incoming requests } catch(const CORBA::Exception& e) { cerr << e << endl; return 1; } return 0; }
8
客户程序 #include #include "time_c.hh" int main(int argc, char* const* argv) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); char string_obj[1000]; cin>>string_obj; string_obj[strlen(string_obj)+1]='\0';
9
CORBA::Object_var obj=orb->string_to_object(string_obj); if(CORBA::is_nil(obj)){ cerr<<"Nil Hello reference"<<endl; throw 0; } Time_var tm=Time::_narrow(obj); if(CORBA::is_nil(tm)){ cerr<<"Argument is not a Hello reference"<<endl; throw 0; }
10
TimeOfDay tod=tm->get_gmt(); cout<<"Time is:" <<setw(2)<<setfill('0')<<tod.hour<<":" <<setw(2)<<setfill('0')<<tod.minute<<":" <<setw(2)<<setfill('0')<<tod.second<<endl; } catch(const CORBA::Exception& e) { cerr << e << endl; return 1; } return 0; }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.