00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _LOCAL_CONNECTOR_H_
00013 #define _LOCAL_CONNECTOR_H_
00014
00015 #include <BaseDef.h>
00016
00017 #include "ace/Log_Msg.h"
00018 #include <vector>
00019 #include <algorithm>
00020
00021 namespace channel {
00022
00023 template <class> class Interface;
00024 template <class> class LocalInterface;
00025 template <class, class> class Binder;
00026
00031 template <class Channel>
00032 class LocalConnector {
00033 public:
00034 typedef LocalInterface<Channel> LocalInterface;
00035 typedef Interface<Channel> Interface;
00036 typedef Binder<typename Channel::IdType, typename Channel::IdTrait> Binder;
00037
00038 typedef typename Channel::IdType IdType;
00039 typedef typename Channel::Msg Msg;
00040 typedef typename Channel::Channel_Info_Msg Channel_Info_Msg;
00041
00042 static Status connect (Channel *ch1, Channel *ch2, Binder *binder1 = NULL, Binder *binder2 = NULL)
00043 {
00044 ACE_DEBUG((LM_DEBUG, "LocalConnector::connect enter\n"));
00045
00046 LocalInterface *intf1 = new LocalInterface(ch1, binder1);
00047 LocalInterface *intf2 = new LocalInterface(ch2, binder2);
00048 intf1->peer_interface_ = intf2;
00049 intf2->peer_interface_ = intf1;
00050
00051
00052
00053 Channel_Info_Msg *chInfo = new Channel_Info_Msg();
00054 chInfo->is_local = true;
00055 chInfo->intf = intf1;
00056 Msg *m = new Msg(Channel::CHANNEL_CONN_MSG, chInfo);
00057 intf1->send_msg (m);
00058 chInfo = new Channel_Info_Msg();
00059 chInfo->is_local = true;
00060 chInfo->intf = intf2;
00061 m = new Msg(Channel::CHANNEL_CONN_MSG, chInfo);
00062 intf2->send_msg (m);
00063
00064
00065
00066 std::vector<IdType> ch1_pub_msgs;
00067 ch1->published_global_msgs (ch1_pub_msgs);
00068 std::vector<IdType> ch2_sub_msgs;
00069 ch2->subscribed_global_msgs(ch2_sub_msgs);
00070 for(typename std::vector<IdType>::iterator iter = ch1_pub_msgs.begin();
00071 iter != ch1_pub_msgs.end(); iter++) {
00072 if (intf1->filter_ != NULL && intf1->filter_->block_outward(*iter))
00073 continue;
00074 if (find (ch2_sub_msgs.begin(), ch2_sub_msgs.end(), (*iter)) !=
00075 ch2_sub_msgs.end()) {
00076 intf2->publish_msg((*iter), SCOPE_LOCAL);
00077 intf1->subscribe_msg((*iter), SCOPE_LOCAL);
00078 }
00079 }
00080
00081 std::vector<IdType> ch2_pub_msgs;
00082 ch2->published_global_msgs (ch2_pub_msgs);
00083 std::vector<IdType> ch1_sub_msgs;
00084 ch1->subscribed_global_msgs(ch1_sub_msgs);
00085 for(typename std::vector<IdType>::iterator iter = ch2_pub_msgs.begin();
00086 iter != ch2_pub_msgs.end(); iter++) {
00087 if (intf2->filter_ != NULL && intf2->filter_->block_outward(*iter))
00088 continue;
00089 if (find (ch1_sub_msgs.begin(), ch1_sub_msgs.end(), (*iter)) !=
00090 ch1_sub_msgs.end()) {
00091 intf1->publish_msg((*iter), SCOPE_LOCAL);
00092 intf2->subscribe_msg((*iter), SCOPE_LOCAL);
00093 }
00094 }
00095 return SUCCESS;
00096 }
00097 };
00098
00099 };
00100
00101 #endif
00102