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

Modified Files:
        Makefile.am playerc.h 
Added Files:
        dev_blackboard.c 
Log Message:
Commit of Ben Morellis 'Blackboard' driver and interface

Index: Makefile.am
===================================================================
RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/Makefile.am,v
retrieving revision 1.99
retrieving revision 1.100
diff -C2 -d -r1.99 -r1.100
*** Makefile.am 21 Aug 2007 23:16:23 -0000      1.99
--- Makefile.am 20 Sep 2007 02:50:47 -0000      1.100
***************
*** 27,30 ****
--- 27,31 ----
                          dev_aio.c \
                          dev_audio.c \
+                         dev_blackboard.c \
                          dev_bumper.c \
                          dev_blobfinder.c \

Index: playerc.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/playerc.h,v
retrieving revision 1.231
retrieving revision 1.232
diff -C2 -d -r1.231 -r1.232
*** playerc.h   17 Sep 2007 02:18:51 -0000      1.231
--- playerc.h   20 Sep 2007 02:50:47 -0000      1.232
***************
*** 1091,1095 ****
--- 1091,1134 ----
  /**************************************************************************/
  
+ /** @ingroup playerc_proxies
+  * @defgroup playerc_proxy_blackboard blackboard
+ 
+ The blackboard proxy provides an interface to a simple data-store in a 
similar fashion to a hash-map.
+ Data is set and retrieved by using a label. Any player message structure can 
be stored in the blackboard.
+ At this time it is up to the user to pack and unpack the entry data. The xdr 
functions can be used to do
+ this.
+ @{ */
+ 
+ /** @brief BlackBoard proxy. */
+ typedef struct
+ {
+   /** Device info; must be at the start of all device structures. */
+   playerc_device_t info;
+   /** Function to be called when a key is updated. */
+   void (*on_blackboard_event)(player_blackboard_entry_t);
+ } playerc_blackboard_t;
+ 
+ /** @brief Create a blackboard proxy. */
+ playerc_blackboard_t *playerc_blackboard_create(playerc_client_t *client, int 
index);
  
+ /** @brief Destroy a blackboard proxy. */
+ void playerc_blackboard_destroy(playerc_blackboard_t *device);
+ 
+ /** @brief Subscribe to the blackboard device. */
+ int playerc_blackboard_subscribe(playerc_blackboard_t *device, int access);
+ 
+ /** @brief Un-subscribe from the blackboard device. */
+ int playerc_blackboard_unsubscribe(playerc_blackboard_t *device);
+ 
+ /** @brief Subscribe to a key. */
+ int playerc_blackboard_subscribe_to_key(playerc_blackboard_t *device, const 
char* key, player_blackboard_entry_t* entry);
+ 
+ /** @brief Unsubscribe from a key. */
+ int playerc_blackboard_unsubscribe_from_key(playerc_blackboard_t *device, 
const char* key);
+ 
+ /** @brief Set an entry value. */
+ int playerc_blackboard_set_entry(playerc_blackboard_t *device, 
player_blackboard_entry_t* entry);
+ 
+ /** @} */
  
  /***************************************************************************/

--- NEW FILE: dev_blackboard.c ---
/* 
 *  libplayerc : a Player client library
 *  Copyright (C) Andrew Howard 2002-2003
 *
 *  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.
 *
 */
/*
 *  Player - One Hell of a Robot Server
 *  Copyright (C) Andrew Howard 2003
 *                      
 *
 *  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
 */
/***************************************************************************
 * Desc: Blackboard device proxy
 * Author: Benjamin Morelli
 * Date: September 2007
 * CVS: $Id: dev_blackboard.c,v 1.1 2007/09/20 02:50:47 thjc Exp $
 **************************************************************************/

#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include "playerc.h"
#include "error.h"
#include <libplayerxdr/playerxdr.h>

void playerc_blackboard_putmsg(playerc_blackboard_t *device,
                               player_msghdr_t *header,
                               player_blackboard_entry_t *data, size_t len);

// Create a new blackboard proxy
playerc_blackboard_t *playerc_blackboard_create(playerc_client_t *client, int 
index)
{
        playerc_blackboard_t *device= NULL;
        device = malloc(sizeof(playerc_blackboard_t));
        memset(device, 0, sizeof(playerc_blackboard_t));

        playerc_device_init(&device->info, client, PLAYER_BLACKBOARD_CODE, 
index, (playerc_putmsg_fn_t)playerc_blackboard_putmsg);

        return device;
}

// Destroy a blackboard proxy
void playerc_blackboard_destroy(playerc_blackboard_t *device)
{
        playerc_device_term(&device->info);
        //playerc_blackboard_cleanup(device);
        free(device);
}

// Subscribe to the blackboard device
int playerc_blackboard_subscribe(playerc_blackboard_t *device, int access)
{
        return playerc_device_subscribe(&device->info, access);
}

// Un-subscribe from the blackboard device
int playerc_blackboard_unsubscribe(playerc_blackboard_t *device)
{
        return playerc_device_unsubscribe(&device->info);
}

// Subscribe to a blackboard key
int playerc_blackboard_subscribe_to_key(playerc_blackboard_t* device, const 
char* key,
                player_blackboard_entry_t* entry_out)
{
        player_blackboard_entry_t req;
        memset(&req, 0, sizeof(req));
        req.key = strdup(key);
        req.key_count = strlen(key) + 1;
        size_t entry_size = sizeof(req) + req.key_count;

        if (playerc_client_request(
                device->info.client,
                &device->info,
                PLAYER_BLACKBOARD_REQ_SUBSCRIBE_TO_KEY,
                &req,
                entry_out,
                entry_size) < 0)
        {
                PLAYERC_ERR("failed to subscribe to blackboard key");
                return -1;
        }

        free(req.key);
        return 0;
}

// Unsubscribe from a blackboard key
int playerc_blackboard_unsubscribe_from_key(playerc_blackboard_t* device, const 
char* key)
{
        player_blackboard_entry_t req;
        memset(&req, 0, sizeof(req));
        req.key = strdup(key);
        req.key_count = strlen(key) + 1;
        size_t entry_size = sizeof(req) + req.key_count;

        if (playerc_client_request(
                device->info.client,
                &device->info,
                PLAYER_BLACKBOARD_REQ_UNSUBSCRIBE_FROM_KEY,
                &req,
                NULL,
                entry_size) < 0)
        {
                PLAYERC_ERR("failed to unsubscribe to blackboard key");
                return -1;
        }

        free(req.key);
        return 0;

}

// Set a key
int playerc_blackboard_set_entry(playerc_blackboard_t *device, 
player_blackboard_entry_t* entry)
{
        size_t entry_size = sizeof(entry) + entry->key_count + 
entry->data_count;
        player_blackboard_entry_t *reply;

        if (playerc_client_request(
                device->info.client,
                &device->info,
                PLAYER_BLACKBOARD_REQ_SET_ENTRY,
                entry,
                &reply,
                entry_size) < 0)
        {
                PLAYERC_ERR("failed to set blackboard key");
                return -1;
        }

        return 0;
}

void playerc_blackboard_putmsg(playerc_blackboard_t *device,
                               player_msghdr_t *header,
                               player_blackboard_entry_t *data, size_t len)
{
        if (device->on_blackboard_event != NULL)
        {
                device->on_blackboard_event(*data);
        }
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to