00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __ENKI_BLUETOOTHBASE_H
00035 #define __ENKI_BLUETOOTHBASE_H
00036
00037 #include "PhysicalEngine.h"
00038
00039 #include <valarray>
00040 #include <list>
00041 #include <queue>
00042
00043
00048 namespace Enki
00049 {
00050 class Bluetooth;
00051
00053
00054 class BluetoothBase
00055 {
00056 protected:
00058 struct BtClients
00059 {
00061 Bluetooth* owner;
00063 unsigned address;
00064 };
00065
00067 struct Connections
00068 {
00070 Bluetooth* source;
00072 unsigned destaddress;
00073 };
00074
00076 struct Transmissions
00077 {
00079 Bluetooth* source;
00081 unsigned address;
00083 char* data;
00085 unsigned size;
00086 };
00087
00089 std::list<BtClients> clients;
00091 std::queue<Connections> connectbuffer;
00093 std::queue<Connections> disconnectbuffer;
00095 std::queue<Transmissions> transmissions;
00096
00098 bool bbSendDataTo(Bluetooth* source, unsigned address, char* data, unsigned size);
00100 bool bbConnectTo(Bluetooth* source,unsigned address);
00102 bool bbCloseConnection(Bluetooth* source,unsigned address);
00103
00105 Bluetooth* getAddress(unsigned address);
00107 bool checkDistance(Bluetooth* source, Bluetooth* destination);
00108
00109 public:
00111 enum Errors
00112 {
00114 BT_NO_ERROR = 0,
00116 ADDRESS_UNKNOWN = 1,
00118 DISTANCE_EXCEEDED = 2,
00120 TOO_MANY_CONNECTIONS = 3,
00122 RECEPTION_BUFFER_FULL = 4
00123 };
00124
00125
00127 BluetoothBase();
00129 virtual ~BluetoothBase();
00130
00132 bool registerClient(Bluetooth* owner, unsigned address);
00134 bool removeClient(Bluetooth* owner);
00135
00137 void sendDataTo(Bluetooth* source, unsigned address, char* data, unsigned size);
00139 void connectTo(Bluetooth* source,unsigned address);
00141 void closeConnection(Bluetooth* source,unsigned address);
00142
00144 virtual void step(double dt, World *w);
00145 };
00146
00147 }
00148
00149 #endif