Wiselib
wiselib.stable/external_interface/shawn/shawn_radio.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 #ifndef CONNECTOR_SHAWN_RADIOMODEL_H
00020 #define CONNECTOR_SHAWN_RADIOMODEL_H
00021 
00022 #include "external_interface/shawn/shawn_types.h"
00023 
00024 namespace wiselib
00025 {
00026 
00035    template<typename OsModel_P>
00036    class ShawnRadioModel
00037    {
00038    public:
00039       typedef OsModel_P OsModel;
00040 
00041       typedef ShawnRadioModel<OsModel> self_type;
00042       typedef self_type* self_pointer_t;
00043 
00044       typedef ExtIfaceProcessor::node_id_t node_id_t;
00045       typedef ExtIfaceProcessor::block_data_t block_data_t;
00046       typedef ExtIfaceProcessor::size_t size_t;
00047       typedef ExtIfaceProcessor::message_id_t message_id_t;
00048 
00049       typedef delegate3<void, int, long, unsigned char*> radio_delegate_t;
00050       // --------------------------------------------------------------------
00051       enum ErrorCodes
00052       {
00053          SUCCESS = OsModel::SUCCESS,
00054          ERR_UNSPEC = OsModel::ERR_UNSPEC,
00055          ERR_NOTIMPL = OsModel::ERR_NOTIMPL
00056       };
00057       // --------------------------------------------------------------------
00058       enum SpecialNodeIds {
00059          BROADCAST_ADDRESS = 0xffff, 
00060          NULL_NODE_ID      = -1      
00061       };
00062       // --------------------------------------------------------------------
00063       enum Restrictions {
00064          MAX_MESSAGE_LENGTH = 0xff   
00065       };
00066       // --------------------------------------------------------------------
00067       ShawnRadioModel( ShawnOs& os )
00068          : os_(os)
00069       {}
00070       // --------------------------------------------------------------------
00071       int send( node_id_t id, size_t len, block_data_t *data )
00072       {
00073          os().proc->send_wiselib_message( id, len, data );
00074          return SUCCESS;
00075       };
00076       // --------------------------------------------------------------------
00077       int enable_radio()
00078       { return SUCCESS; }
00079       // --------------------------------------------------------------------
00080       int disable_radio()
00081       { return SUCCESS; }
00082       // --------------------------------------------------------------------
00083       node_id_t id()
00084       {
00085          return os().proc->id();
00086       }
00087       // --------------------------------------------------------------------
00088       template<class T, void (T::*TMethod)(node_id_t, size_t, block_data_t*)>
00089       int reg_recv_callback( T *obj_pnt )
00090       {
00091          if (os().proc->template reg_recv_callback<T, TMethod>( obj_pnt ))
00092             return SUCCESS;
00093 
00094          return ERR_UNSPEC;
00095       }
00096       // --------------------------------------------------------------------
00097       int unreg_recv_callback( int idx )
00098       { return ERR_NOTIMPL; }
00099 
00100    private:
00101       ShawnOs& os()
00102       { return os_; }
00103       // --------------------------------------------------------------------
00104       ShawnOs& os_;
00105    };
00106 }
00107 
00108 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines