TOBI SignalServer
0.1
|
00001 /* 00002 This file is part of the TOBI SignalServer. 00003 00004 Commercial Usage 00005 Licensees holding valid Graz University of Technology Commercial 00006 licenses may use this file in accordance with the Graz University 00007 of Technology Commercial License Agreement provided with the 00008 Software or, alternatively, in accordance with the terms contained in 00009 a written agreement between you and Graz University of Technology. 00010 00011 -------------------------------------------------- 00012 00013 GNU General Public License Usage 00014 Alternatively, this file may be used under the terms of the GNU 00015 General Public License version 3.0 as published by the Free Software 00016 Foundation and appearing in the file gpl.txt included in the 00017 packaging of this file. Please review the following information to 00018 ensure the GNU General Public License version 3.0 requirements will be 00019 met: http://www.gnu.org/copyleft/gpl.html. 00020 00021 In case of GNU General Public License Usage ,the TOBI SignalServer 00022 is distributed in the hope that it will be useful, 00023 but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 GNU General Public License for more details. 00026 00027 You should have received a copy of the GNU General Public License 00028 along with the TOBI SignalServer. If not, see <http://www.gnu.org/licenses/>. 00029 00030 Copyright 2010 Graz University of Technology 00031 Contact: SignalServer@tobi-project.org 00032 */ 00033 00038 #ifndef HW_THREAD_BUILDER_H 00039 #define HW_THREAD_BUILDER_H 00040 00041 #include "hw_thread.h" 00042 #include "hw_thread_factory.h" 00043 00044 namespace tobiss 00045 { 00046 00047 //----------------------------------------------------------------------------- 00056 class HWThreadBuilder 00057 { 00058 public: 00059 virtual HWThread* createInstance (boost::asio::io_service& io, ticpp::Iterator<ticpp::Element> hw) const = 0; 00060 protected: 00061 HWThreadBuilder () {} 00062 }; 00063 00064 00065 //----------------------------------------------------------------------------- 00075 template<typename T> 00076 class HWThreadBuilderTemplateRegistrator : public HWThreadBuilder 00077 { 00078 public: 00083 HWThreadBuilderTemplateRegistrator (std::string key) 00084 { 00085 registerKey (key); 00086 } 00087 00088 HWThreadBuilderTemplateRegistrator (std::string key_1, std::string key_2) 00089 { 00090 registerKey (key_1); 00091 registerKey (key_2); 00092 } 00093 HWThreadBuilderTemplateRegistrator (std::string key_1, std::string key_2, std::string key_3) 00094 { 00095 registerKey (key_1); 00096 registerKey (key_2); 00097 registerKey (key_3); 00098 } 00099 HWThreadBuilderTemplateRegistrator (std::string key_1, std::string key_2, std::string key_3, std::string key_4) 00100 { 00101 registerKey (key_1); 00102 registerKey (key_2); 00103 registerKey (key_3); 00104 registerKey (key_4); 00105 } 00106 HWThreadBuilderTemplateRegistrator (std::string key_1, std::string key_2, std::string key_3, std::string key_4, std::string key_5) 00107 { 00108 registerKey (key_1); 00109 registerKey (key_2); 00110 registerKey (key_3); 00111 registerKey (key_4); 00112 registerKey (key_5); 00113 } 00114 HWThreadBuilderTemplateRegistrator (std::string key_1, std::string key_2, std::string key_3, std::string key_4, std::string key_5, std::string key_6) 00115 { 00116 registerKey (key_1); 00117 registerKey (key_2); 00118 registerKey (key_3); 00119 registerKey (key_4); 00120 registerKey (key_5); 00121 registerKey (key_6); 00122 } 00123 00124 virtual HWThread* createInstance (boost::asio::io_service& io, ticpp::Iterator<ticpp::Element> hw) const 00125 { 00126 return new T (io, hw); 00127 } 00128 00129 private: 00130 HWThreadBuilderTemplateRegistrator () {} 00131 00132 void registerKey (std::string const& key) 00133 { 00134 HWThreadFactory::instance().registerBuilder (key, new HWThreadBuilderTemplateRegistrator<T>); 00135 } 00136 }; 00137 00138 //----------------------------------------------------------------------------- 00148 template<typename T> 00149 class HWThreadBuilderTemplateRegistratorWithoutIOService : public HWThreadBuilder 00150 { 00151 public: 00156 HWThreadBuilderTemplateRegistratorWithoutIOService (std::string key) 00157 { 00158 registerKey (key); 00159 } 00160 00161 HWThreadBuilderTemplateRegistratorWithoutIOService (std::string key_1, std::string key_2) 00162 { 00163 registerKey (key_1); 00164 registerKey (key_2); 00165 } 00166 HWThreadBuilderTemplateRegistratorWithoutIOService (std::string key_1, std::string key_2, std::string key_3) 00167 { 00168 registerKey (key_1); 00169 registerKey (key_2); 00170 registerKey (key_3); 00171 } 00172 HWThreadBuilderTemplateRegistratorWithoutIOService (std::string key_1, std::string key_2, std::string key_3, std::string key_4) 00173 { 00174 registerKey (key_1); 00175 registerKey (key_2); 00176 registerKey (key_3); 00177 registerKey (key_4); 00178 } 00179 HWThreadBuilderTemplateRegistratorWithoutIOService (std::string key_1, std::string key_2, std::string key_3, std::string key_4, std::string key_5) 00180 { 00181 registerKey (key_1); 00182 registerKey (key_2); 00183 registerKey (key_3); 00184 registerKey (key_4); 00185 registerKey (key_5); 00186 } 00187 HWThreadBuilderTemplateRegistratorWithoutIOService (std::string key_1, std::string key_2, std::string key_3, std::string key_4, std::string key_5, std::string key_6) 00188 { 00189 registerKey (key_1); 00190 registerKey (key_2); 00191 registerKey (key_3); 00192 registerKey (key_4); 00193 registerKey (key_5); 00194 registerKey (key_6); 00195 } 00196 00197 virtual HWThread* createInstance (boost::asio::io_service&, ticpp::Iterator<ticpp::Element> hw) const 00198 { 00199 // boost::shared_ptr<HWThread> shrd_ptr = boost::shared_ptr<HWThread>(new T (hw)); 00200 // return ( shrd_ptr.get() ); 00201 return ( new T (hw) ); 00202 } 00203 00204 private: 00205 HWThreadBuilderTemplateRegistratorWithoutIOService () {} 00206 00207 void registerKey (std::string const& key) 00208 { 00209 HWThreadFactory::instance().registerBuilder (key, new HWThreadBuilderTemplateRegistratorWithoutIOService<T>); 00210 } 00211 }; 00212 00213 00214 00215 } // namespace tobiss 00216 00217 #endif // HW_THREAD_BUILDER_H