00001 00002 // Copyright (c) 2005, 2006 Yigong Liu 00003 // Permission to use, copy, modify, distribute and sell this software for any 00004 // purpose is hereby granted without fee, provided that the above copyright 00005 // notice appear in all copies and that both that copyright notice and this 00006 // permission notice appear in supporting documentation. 00007 // The author makes no representations about the 00008 // suitability of this software for any purpose. It is provided "as is" 00009 // without express or implied warranty. 00011 00012 #include <DemoTask.h> 00013 #include <DemoTask_export.h> 00014 00015 //---------------------------------------------- 00016 // the following 3 methods should be overwritten 00017 // to implement application logic 00018 //---------------------------------------------- 00019 00020 //app hooks for resource reservation & cleanup 00021 Status Demo_Task::prepare(void) 00022 { 00023 //subscribe msg 00024 my_port()->subscribe_msg(TEST_STRING_MSG); 00025 return SUCCESS; 00026 } 00027 00028 Status Demo_Task::cleanup(void) 00029 { 00030 //unsubscribe msg 00031 my_port()->unsubscribe_msg(TEST_STRING_MSG); 00032 return SUCCESS; 00033 } 00034 00035 00036 int Demo_Task::work() { 00037 ACE_DEBUG ((LM_DEBUG, 00038 "(%t) %s demo_task coming up ...\n", my_name().c_str())); 00039 Msg *msg; 00040 Test_String_Msg *sm; 00041 00042 for(;;) { 00043 if(my_port()->recv_msg(msg) == SUCCESS) { 00044 //handle_msg(msg); 00045 if(msg->type == TEST_STRING_MSG) { 00046 sm = (Test_String_Msg *)msg->data(); 00047 sm->data[sm->len-1] = '\0'; 00048 00049 ACE_DEBUG ((LM_DEBUG, "(%t) (%s) receive the following: \n%s\n", 00050 my_name().c_str(),sm->data)); 00051 00052 delete msg; 00053 } 00054 00055 } else { 00056 //handle_error(); 00057 break; 00058 } 00059 } 00060 00061 ACE_DEBUG ((LM_DEBUG, 00062 "(%t) %s demo_task exits...\n", my_name().c_str())); 00063 00064 return 0; 00065 } 00066 00067 ACE_FACTORY_DEFINE (DemoTask, Demo_Task)