00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00016 #include "ace/OS_main.h"
00017 #include "ace/ACE.h"
00018 #include "ace/Auto_Ptr.h"
00019 #include "ace/OS_NS_string.h"
00020 #include "ace/OS_NS_stdio.h"
00021 #include "ace/Get_Opt.h"
00022
00023 #include <iostream>
00024 #include <string>
00025 #include <Channel.h>
00026
00027 using namespace std;
00028 using namespace channel;
00029
00030
00031
00032
00033
00034 typedef string IdType;
00035
00036
00037
00038
00039
00040
00041
00042
00043 std::string PING_MSG = "_PING_";
00044 std::string PONG_MSG = "_PONG_";
00045 std::string TEST_STRING_MSG = "_TEST_";
00046
00047 struct Test_String_Msg {
00048 enum { MAX_STR_LEN = 1024 };
00049 int len;
00050 char data[MAX_STR_LEN];
00051 Test_String_Msg() {
00052 }
00053 };
00054
00055
00056
00057
00058 typedef Channel<IdType> Chan;
00059 typedef Channel<IdType>::Msg ChanMsg;
00060
00061
00062
00063
00064 class My_Callback: public Chan::Callback {
00065 public:
00066 My_Callback(Chan *c) : Chan::Callback(c) {}
00067 Status process(Chan::Msg *msg) {
00068 Test_String_Msg *sm = (Test_String_Msg *)msg->data_holder_->data_;
00069 ACE_DEBUG ((LM_DEBUG, "(%t) text_recv/My_Callback recv the following: \n%s\n",
00070 sm->data));
00071 ACE_DEBUG ((LM_DEBUG, "(%t) Please notice callback borrow Channel internal thread\n"));
00072
00073 delete msg;
00074
00075 return SUCCESS;
00076 }
00077 };
00078
00079 int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
00080 ACE_UNUSED_ARG(argc);
00081 ACE_UNUSED_ARG(argv);
00082
00083 ACE::debug('y');
00084
00085 ACE_LOG_MSG->open
00086 (argv[0], ACE_Log_Msg::SYSLOG, ACE_TEXT (argv[0]));
00087 ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR);
00088
00090 Chan * chan1 = new Chan();
00091 Chan * chan2 = new Chan();
00092
00093 if (Chan::LocalConnector::connect (chan1, chan2) != SUCCESS)
00094 ACE_DEBUG ((LM_DEBUG, "(%t) failed to connect 2 local channels ...\n"));
00095
00097 My_Callback my_calbak(chan2);
00098 Chan::Source my_src(chan1);
00099
00101 my_src.publish_msg(TEST_STRING_MSG);
00102 my_calbak.subscribe_msg(TEST_STRING_MSG);
00103
00104 ACE_DEBUG ((LM_DEBUG, "(%t) local_chan_conn coming up ...\n"));
00105
00107
00108 for(;;) {
00109 ACE_DEBUG((LM_DEBUG, "--- Please enter one line msg: "));
00110 Test_String_Msg *tm = new Test_String_Msg();
00111 if (!gets (tm->data))
00112 break;
00113 tm->len = strlen(tm->data)+1;
00114 my_src.send_msg (TEST_STRING_MSG, tm);
00115 }
00116
00117 return 0;
00118 }