blackboard

  
Blackboard.h
class BBItem
    {
      private:
        friend class Blackboard;
        cPolymorphic *_item;
        std::string _label;
        SubscriberVector subscribers;
      public:
        /** Return the label of this data item*/
        const char *label() {return _label.c_str();}
        /** Return the data item*/
        cPolymorphic *data() {return _item;}
    };
  typedef std::vector<BlackboardAccess *> SubscriberVector;
    typedef std::map<std::string, BBItem*> ContentsMap;
BBItemRef Blackboard::publish(const char *label, cPolymorphic *item)
{
    Enter_Method("publish(/"%s/", %s *ptr)", label, item->className());
    // check uniqueness of label
    ContentsMap::iterator k = contents.find(std::string(label));
    if (k!=contents.end())
        error("publish(): blackboard already contains an item with label `%s'", label);
    // add to BB contents
    BBItem *bbitem = new BBItem();
    bbitem->_item = item;
    bbitem->_label = label;
    contents[bbitem->_label] = bbitem;
    coreEV <<"pulish "<<label<<" on bb/n";
    coreEV <<"bbItem->label: "<<bbitem->label()<<endl; 
    // notify
    SubscriberVector& vec = registeredClients;
    for (SubscriberVector::iterator i=vec.begin(); i!=vec.end(); ++i){
        (*i)->blackboardItemPublished(bbitem);
    }
    return bbitem;
}
     class BlackboardAccess
{
protected:
       Blackboard *bb;
public:
       BlackboardAccess() {bb=NULL;}
      /** Returns a pointer to the Blackboard*/
       Blackboard *blackboard();
 
     /** @name Callbacks invoked by the blackboard */
       //@{
       /** Called whenever an already published item changes*/
       virtual bool blackboardItemChanged(BBItemRef item) = 0;
       /** Called whenever a new item is published on the Blackboard*/
       virtual bool blackboardItemPublished(BBItemRef item) = 0;
       /** Called whenever an item is removed from the Blackboard*/
       virtual bool blackboardItemWithdrawn(BBItemRef item) = 0;
       //@}
};
class BlackboardAccess
{
protected:
 Blackboard *bb;
public:
 BlackboardAccess() {bb=NULL;}
 /** Returns a pointer to the Blackboard*/
 Blackboard *blackboard();
 
 /** @name Callbacks invoked by the blackboard */
 //@{
 /** Called whenever an already published item changes*/
 virtual bool blackboardItemChanged(BBItemRef item) = 0;
 /** Called whenever a new item is published on the Blackboard*/
 virtual bool blackboardItemPublished(BBItemRef item) = 0;
 /** Called whenever an item is removed from the Blackboard*/
 virtual bool blackboardItemWithdrawn(BBItemRef item) = 0;
 //@}
};
BlackModule 是从 BlackboardAccess 类继承而来的,它提供一个函数 blackboard(), 返回一个 Blackboard 指针,通过它来调用函数,用来 subscribe to and  read information published on the Blackboard. 因为 BasicModule 是所有模块的基类,所以所有的模块也能够使用 Blackboard.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值