UbisenseModule.cxx
Go to the documentation of this file.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
00035
00042
00043
00044
00045 #include "../tool/disable4786.h"
00046
00047 #include "UbisenseModule.h"
00048 #include "UbisenseSource.h"
00049 #include <iostream>
00050
00051 #ifdef USE_UBISENSE
00052
00053
00054 #include "UClientAPI/name_client.h"
00055 #include "UClientAPI/location_client.h"
00056
00057 #ifdef WIN32
00058 #pragma comment(lib,"UClientAPI.lib")
00059 #endif
00060
00061 namespace ot {
00062
00063 UbisenseModule::UbisenseModule(): Module(),NodeFactory(),locationClient(),dataClient(pSources),cells(locationClient.get_all_cells())
00064
00065 {
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 }
00088
00089 UbisenseModule::~UbisenseModule()
00090 {
00091 for (NodeVector::iterator it = pSources.begin();it != pSources.end();it ++)
00092 delete *it;
00093 pSources.clear();
00094 }
00095
00096 Node* UbisenseModule::createNode(const std::string &name,StringTable &attributes)
00097 {
00098 if (name.compare("UbisenseSource") == 0)
00099 {
00100 NameClient nameClient;
00101 Object object;
00102 const char* objectString = attributes.get("object").c_str();
00103 UClientAPI::String str(objectString);
00104 if (nameClient.get_named_object(objectString,object))
00105 {
00106 UbisenseSource* pSource = new UbisenseSource(object,locationClient,dataClient);
00107 pSources.push_back(pSource);
00108 return pSource;
00109 }
00110 }
00111 return NULL;
00112 }
00113
00114 void UbisenseModule::start()
00115 {
00116 for (UClientAPI::Set<String>::const_iterator i = cells.begin();i != cells.end();++ i)
00117 locationClient.load_cell(*i);
00118
00119
00120
00121
00122 }
00123
00124 void UbisenseModule::close()
00125 {
00126 locationClient.unload_all_cells();
00127 }
00128
00129 void UbisenseModule::pushEvent()
00130 {
00131 for (NodeVector::iterator it = pSources.begin();it != pSources.end();it ++)
00132 {
00133 UbisenseSource* pSource = reinterpret_cast<UbisenseSource*>(*it);
00134 if (pSource->calcEvent())
00135 pSource->updateObservers(pSource->getEvent());
00136 }
00137 }
00138
00139 void UbisenseModule::init(StringTable &attributes,ConfigNode* pLocalTree)
00140 {
00141 NameClient nameClient;
00142 Object object;
00143
00144 cells.clear();
00145 for (unsigned int i = 0;i < pLocalTree->countChildren();i ++)
00146 {
00147 ConfigNode* pNode = reinterpret_cast<ConfigNode*>(pLocalTree->getChild(i));
00148 if (! pNode->getType().compare("UbisenseCell"))
00149 {
00150 ot::StringTable& attributes = pNode->getAttributes();
00151 std::string str = attributes.get("name");
00152
00153 cells.insert(str.c_str());
00154
00155
00156 std::cout << "ot location cell: ";
00157 for (UClientAPI::Set<String>::const_iterator i = cells.begin(); i != cells.end(); ++i)
00158
00159 { std::cout << " " << *i << std::endl;
00160 }
00161 if (cells.empty())
00162 { std::cout << "No available cells" << std::endl;
00163 }
00164
00165
00166
00167 std::cout << " ";
00168
00169 }
00170 }
00171 }
00172
00173
00174 UbisenseModule::WrappedDataClient::WrappedDataClient(NodeVector &pSources): DataClient(),pSources(pSources)
00175 {
00176 }
00177
00178 void UbisenseModule::WrappedDataClient::on_button(const Object &tag,UbitagButton button,double time)
00179 {
00180 Object owner;
00181 get_tag_owner(tag,owner);
00182 for (NodeVector::iterator it = pSources.begin();it != pSources.end();it ++)
00183 {
00184 UbisenseSource* pSource = reinterpret_cast<UbisenseSource*>(*it);
00185 const Object &object = pSource->getObject();
00186 if (tag == object || owner == object)
00187 pSource->setButtonEvent(button == Orange ? 0x0001: button == Blue ? 0x0002: 0x0000,time);
00188 }
00189 }
00190
00191 }
00192
00193
00194 #else
00195 #pragma message(">>> no Ubisense support")
00196 #endif // USE_UBISENSE
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212