Update of /cvsroot/playerstage/code/player/client_libs/libplayerc++
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29188/libplayerc++

Modified Files:
        Makefile.am playerc++.h 
Added Files:
        blackboardproxy.cc 
Log Message:
work on the blackboard proxies, added c++, updates for c


Index: playerc++.h
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/client_libs/libplayerc++/playerc++.h,v
retrieving revision 1.101
retrieving revision 1.102
diff -C2 -d -r1.101 -r1.102
*** playerc++.h 24 Oct 2007 22:32:02 -0000      1.101
--- playerc++.h 31 Oct 2007 01:18:42 -0000      1.102
***************
*** 321,324 ****
--- 321,355 ----
  };
  
+ /**
+  * The BlackBoardProxy class is used to subscribe to a blackboard device.
+  * A blackboard is a data-store which sends updates when an entry is changed.
+  * It also returns the current value of an entry when a proxy first subcribes
+  * to that entries key.
+  * If an entry does not exist, the default value of that entry is returned.
+  */
+ class BlackBoardProxy : public ClientProxy
+ {
+   private:
+     void Subscribe(uint aIndex);
+     void Unsubscribe();
+ 
+     // libplayerc data structure
+     playerc_blackboard_t *mDevice;
+ 
+   public:
+         /** Constructor */
+       BlackBoardProxy(PlayerClient *aPc, uint aIndex=0);
+       /** Destructor */
+       ~BlackBoardProxy();
+       /** Subscribe to a key. If the key does not exist the default value is 
returned. The user must free the entry. */
+       player_blackboard_entry_t *SubscribeToKey(const char *key);
+       /** Stop receiving updates about this key. */
+       void UnsubscribeFromKey(const char *key);
+       /** Set a key value */
+       void SetEntry(const player_blackboard_entry_t &entry);
+       /** Set the function pointer which will be called when an entry is 
updated. */
+       void SetEventHandler(void 
(*on_blackboard_event)(player_blackboard_entry_t));
+ };
+ 
  // /**
  // The @p BlinkenlightProxy class is used to enable and disable

Index: Makefile.am
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/client_libs/libplayerc++/Makefile.am,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** Makefile.am 25 Sep 2007 20:25:14 -0000      1.50
--- Makefile.am 31 Oct 2007 01:18:42 -0000      1.51
***************
*** 33,36 ****
--- 33,37 ----
                                aioproxy.cc \
                                audioproxy.cc \
+                               blackboardproxy.cc \
                                blobfinderproxy.cc \
                                bumperproxy.cc \

--- NEW FILE: blackboardproxy.cc ---
/*
 *  Player - One Hell of a Robot Server
 *  Copyright (C) 2000-2003
 *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
/********************************************************************
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 ********************************************************************/

/*
 * $Id: blackboardproxy.cc,v 1.1 2007/10/31 01:18:42 thjc Exp $
 */


#include "playerc++.h"
#include "string.h"

using namespace std;
using namespace PlayerCc;

// Constructor
BlackBoardProxy::BlackBoardProxy(PlayerClient *aPc, uint aIndex) : 
ClientProxy(aPc, aIndex),
                               mDevice(NULL)
{
  Subscribe(aIndex);
  mInfo = &(mDevice->info);
}

// Destructor
BlackBoardProxy::~BlackBoardProxy()
{
  Unsubscribe();
}

// Subscribe
void BlackBoardProxy::Subscribe(uint aIndex)
{
  scoped_lock_t lock(mPc->mMutex);
  mDevice = playerc_blackboard_create(mClient, aIndex);
  if (NULL==mDevice)
  {
    throw PlayerError("BlackBoardProxy::Subscribe(uint aIndex)", "could not 
create");
  }

  if (0 != playerc_blackboard_subscribe(mDevice, PLAYER_OPEN_MODE))
  {
    throw PlayerError("BlackBoardProxy::Subscribe(uint aIndex)", "could not 
subscribe");
  }
  
  mDevice->on_blackboard_event = NULL;
}

// Unsubscribe
void BlackBoardProxy::Unsubscribe()
{
  assert(NULL!=mDevice);
  scoped_lock_t lock(mPc->mMutex);
  playerc_blackboard_unsubscribe(mDevice);
  playerc_blackboard_destroy(mDevice);
  mDevice = NULL;
}

player_blackboard_entry_t *BlackBoardProxy::SubscribeToKey(const char *key)
{
  scoped_lock_t lock(mPc->mMutex);
  player_blackboard_entry_t **t;
  *t = new player_blackboard_entry_t;
  memset(*t, 0, sizeof(player_blackboard_entry_t));
  if (0 != playerc_blackboard_subscribe_to_key(mDevice, key, t))
  {
        delete *t;
        throw PlayerError("BlackBoardProxy::SubscribeToKey(const string& key)", 
"could not subscribe to key");
  }
  return *t;
}

void BlackBoardProxy::UnsubscribeFromKey(const char *key)
{
        scoped_lock_t lock(mPc->mMutex);
        if (0 != playerc_blackboard_unsubscribe_from_key(mDevice, key))
        {
                throw PlayerError("BlackBoardProxy::UnsubscribeFromKey(const 
string& key)", "could not unsubscribe from key");
        }
}

void BlackBoardProxy::SetEntry(const player_blackboard_entry_t &entry)
{
        scoped_lock_t lock(mPc->mMutex);
        player_blackboard_entry_t *copy = new player_blackboard_entry_t;
        // shallow copy
        memcpy(copy, &entry, sizeof(player_blackboard_entry_t));
        
        if (0 != playerc_blackboard_set_entry(mDevice, copy))
        {
                throw PlayerError("BlackBoardProxy::SetEntry(const 
player_blackboard_entry_t &entry)", "could not set entry");
        }

        delete copy;
}

void BlackBoardProxy::SetEventHandler(void 
(*on_blackboard_event)(player_blackboard_entry_t))
{
        mDevice->on_blackboard_event = on_blackboard_event;
}



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to