00001 00012 /* 00013 00014 Copyright (c) 2007, Tim Burrell 00015 Licensed under the Apache License, Version 2.0 (the "License"); 00016 you may not use this file except in compliance with the License. 00017 You may obtain a copy of the License at 00018 00019 http://www.apache.org/licenses/LICENSE-2.0 00020 00021 Unless required by applicable law or agreed to in writing, software 00022 distributed under the License is distributed on an "AS IS" BASIS, 00023 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00024 See the License for the specific language governing permissions and 00025 limitations under the License. 00026 00027 */ 00028 00029 #include "GizmoClient.hpp" 00030 #include "../libH/Debug.hpp" 00031 #include "../libH/Exception.hpp" 00032 #include <boost/lexical_cast.hpp> 00033 #include <boost/archive/text_iarchive.hpp> 00034 #include <boost/archive/text_oarchive.hpp> 00035 #include <boost/serialization/base_object.hpp> 00036 #include <boost/serialization/utility.hpp> 00037 #include <boost/serialization/list.hpp> 00038 #include <sstream> 00039 00040 using namespace std; 00041 using namespace boost; 00042 using namespace H; 00043 using namespace Gizmod; 00044 00046 // Type Defs 00048 00050 // Construction 00052 00056 GizmoClient::GizmoClient() { 00057 } 00058 00062 GizmoClient::~GizmoClient() { 00063 } 00064 00066 // Class Body 00068 00074 void GizmoClient::sendEventATIX10(GizmoEventATIX10 const & Event, GizmoATIX10 const & Gizmo) { 00075 // process the remote event 00076 if (!isClientConnected()) 00077 return; 00078 00079 // serialize 00080 stringstream OutStreamEvent; 00081 archive::text_oarchive OutArchiveEvent(OutStreamEvent); 00082 OutArchiveEvent << Event; 00083 00084 stringstream OutStreamDevice; 00085 archive::text_oarchive OutArchiveDevice(OutStreamDevice); 00086 OutArchiveDevice << Gizmo; 00087 00088 // might raise an exception, catch elsewhere! 00089 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_ATIX10) + "|" + OutStreamEvent.str() + "|" + OutStreamDevice.str()); 00090 } 00091 00096 void GizmoClient::sendEventCPUUsage(GizmoEventCPUUsage const & Event) { 00097 // process the remote event 00098 if (!isClientConnected()) 00099 return; 00100 00101 // serialize 00102 stringstream OutStream; 00103 archive::text_oarchive OutArchive(OutStream); 00104 OutArchive << Event; 00105 00106 // can raise exception 00107 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_CPUUSAGE) + "|" + OutStream.str()); 00108 } 00109 00115 void GizmoClient::sendEventLIRC(GizmoEventLIRC const & Event, GizmoLIRC const & Gizmo) { 00116 // process the remote event 00117 if (!isClientConnected()) 00118 return; 00119 00120 // serialize 00121 stringstream OutStreamEvent; 00122 archive::text_oarchive OutArchiveEvent(OutStreamEvent); 00123 OutArchiveEvent << Event; 00124 00125 stringstream OutStreamDevice; 00126 archive::text_oarchive OutArchiveDevice(OutStreamDevice); 00127 OutArchiveDevice << Gizmo; 00128 00129 // might raise an exception, catch elsewhere! 00130 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_LIRC) + "|" + OutStreamEvent.str() + "|" + OutStreamDevice.str()); 00131 } 00132 00138 void GizmoClient::sendEventPowermate(GizmoEventPowermate const & Event, GizmoPowermate const & Gizmo) { 00139 // process the remote event 00140 if (!isClientConnected()) 00141 return; 00142 00143 // serialize 00144 stringstream OutStreamEvent; 00145 archive::text_oarchive OutArchiveEvent(OutStreamEvent); 00146 OutArchiveEvent << Event; 00147 00148 stringstream OutStreamDevice; 00149 archive::text_oarchive OutArchiveDevice(OutStreamDevice); 00150 OutArchiveDevice << Gizmo; 00151 00152 // might raise an exception, catch elsewhere! 00153 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_POWERMATE) + "|" + OutStreamEvent.str() + "|" + OutStreamDevice.str()); 00154 } 00155 00160 void GizmoClient::sendEventSoundCard(GizmoEventSoundCard const & Event) { 00161 // process the remote event 00162 if (!isClientConnected()) 00163 return; 00164 00165 // serialize 00166 stringstream OutStream; 00167 archive::text_oarchive OutArchive(OutStream); 00168 OutArchive << Event; 00169 00170 // can raise exception 00171 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_SOUNDCARD) + "|" + OutStream.str()); 00172 } 00173 00178 void GizmoClient::sendEventSoundVisualization(GizmoEventSoundVisualization const & Event) { 00179 // process the remote event 00180 if (!isClientConnected()) 00181 return; 00182 00183 // serialize 00184 stringstream OutStream; 00185 archive::text_oarchive OutArchive(OutStream); 00186 OutArchive << Event; 00187 00188 // can raise exception 00189 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_SOUNDVISUALIZATION) + "|" + OutStream.str()); 00190 } 00191 00197 void GizmoClient::sendEventStandard(GizmoEventStandard const & Event, GizmoStandard const & Gizmo) { 00198 // process the remote event 00199 if (!isClientConnected()) 00200 return; 00201 00202 // serialize 00203 stringstream OutStreamEvent; 00204 archive::text_oarchive OutArchiveEvent(OutStreamEvent); 00205 OutArchiveEvent << Event; 00206 00207 stringstream OutStreamDevice; 00208 archive::text_oarchive OutArchiveDevice(OutStreamDevice); 00209 OutArchiveDevice << Gizmo; 00210 00211 // might raise an exception, catch elsewhere! 00212 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_STANDARD) + "|" + OutStreamEvent.str() + "|" + OutStreamDevice.str()); 00213 } 00214 00219 void GizmoClient::sendEventWindowFocus(GizmoEventWindowFocus const & Event) { 00220 // process the remote event 00221 if (!isClientConnected()) 00222 return; 00223 00224 // serialize 00225 stringstream OutStream; 00226 archive::text_oarchive OutArchive(OutStream); 00227 OutArchive << Event; 00228 00229 // can raise exception 00230 sendToServer(lexical_cast<string>(GIZMO_EVENTCLASS_WINDOWFOCUS) + "|" + OutStream.str()); 00231 }