Show SwDevice.h syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* Copyright (c) 2001 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgement:
* This product includes software developed by Networked &
* Embedded Systems Lab at UCLA
* 4. Neither the name of the University nor that of the Laboratory
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Author: Simon Han (simonhan@ee.ucla.edu)
*/
#ifndef SW_DEVICE_H
#define SW_DEVICE_H
#include "sensorware.h"
#include "SwMailbox.h"
#include "SwErrMsg.h"
#include "SwInterest.h"
typedef struct SwDeviceOp_{
// *interest will be called when mobile agent calls interest command
// to express its interest to particular device.
// device should verify such interest is valid
// Tcl syntax: interest <device name> <interest name> {parameter}*
// device should parse the parameters and saves for later activation
// activation will be made when the <interest name> is
// being waited by wait command
// when activated, device should check if any matching event exists.
// If so, send message to mobile agent with <interest name>
// being the first word
// Device will receive argv[0] as tag and argv[1] as paramter one and so on
// Device should return a value that will be used to activate this event
// during wait command. The device should put device specifc data to dataPtr
int (*interest)(Tcl_Interp *interp, int argc, char *argv[], void **dataPtr);
// *act will be called when mobile agent calls act command
// device should start action on background and return immediately
// Tcl syntax: act <device name> {parameter}*
int (*act)(Tcl_Interp *interp, int argc, char *argv[]);
// *query will be called when mobile agent calls query to
// get device specific data such as sensor value, node location
// the return values should be the values that are cached in
// the driver. Any event driven query should put into interest/wait
// interface
int (*query)(Tcl_Interp *interp, int argc, char *argv[]);
// *ps will be called when mobile agent needs to know
// activated interests in the device
// Tcl syntax: ps {device name} {device specific parameters}
int (*ps)(Tcl_Interp *interp, int argc, char *argv[]);
// *ls will be called when script needs to discover device
// and device attributes
// typically, device attributes includes
// device loads and device available resource, etc.
// Tcl syntax: ls {device name} {device specific parameters}
int (*ls)(Tcl_Interp *interp, int argc, char *argv[]);
// internal service function
// *activate will be called when mobile agent is waiting on
// specific <interest>
// Device should activate the process saved during *interest interface
// It should return 0 for success, negative (man errno for possible value)
int (*activate)(SwInterest *interest);
// *deactivate will be called when activated interest needs to be canceled
// It should return 0 for success, negative (man errno for possible value)
int (*deactivate)(SwInterest *interest);
// *dispose will be called when the interest will be disposed
// device will be given their own pointer that was returned from
// from interest interface
// It should return 0 for success, negative (man errno for possible value)
int (*dispose)(void *param);
// per device thread
void* (*thread)(void *arg);
} SwDeviceOp;
int swDeviceInit();
int swDeviceRegister(char *name, SwDeviceOp *op);
int swDeviceParseSensorArg(int argc, char *argv[],
int *p, int *b, int *w, int *t);
#endif
See more files for this project here