TOBI Interface A  0.1
/home/breidi/Dropbox/libtia/include/tia/tia_server.h
Go to the documentation of this file.
00001 /*
00002     This file is part of the TOBI Interface A (TiA) library.
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 Lesser General Public License Usage
00014     Alternatively, this file may be used under the terms of the GNU Lesser
00015     General Public License version 3.0 as published by the Free Software
00016     Foundation and appearing in the file lgpl.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/lgpl.html.
00020 
00021     In case of GNU Lesser General Public License Usage ,the TiA library
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 Lesser General Public License
00028     along with the TiA library. If not, see <http://www.gnu.org/licenses/>.
00029 
00030     Copyright 2010 Graz University of Technology
00031     Contact: TiA@tobi-project.org
00032 */
00033 
00039 #ifndef TIA_SERVER_H
00040 #define TIA_SERVER_H
00041 
00042 // STL
00043 #include <map>
00044 
00045 #ifdef WIN32
00046   #include  <conio.h>
00047   #include  <stdio.h>
00048 #endif
00049 
00050 // Boost
00051 #include <boost/asio.hpp>
00052 #include <boost/cstdint.hpp>
00053 #include <boost/utility.hpp>
00054 #include <boost/shared_ptr.hpp>
00055 
00056 // local
00057 #include "tia/constants.h"
00058 #include "tia/ss_meta_info.h"
00059 
00060 
00061 // forward declarations
00062 
00063 namespace tia
00064 {
00065 
00066   class ControlConnectionServer;
00067   class TCPDataServer;
00068   class UDPDataServer;
00069 
00070   class TiAServerStateServer;
00071   class ControlConnectionServer2;
00072   class DataServer;
00073   class HardwareInterface;
00074   class DataPacket;
00075   class DataPacketImpl;
00076   class DataPacket3Impl;
00077 
00078 //-----------------------------------------------------------------------------
00079 
00096 class TiAServer : boost::noncopyable
00097 {
00108   friend class ControlConnectionServer;
00109 
00110     // Methods
00111     //-----------------------------------
00112   public:
00117     TiAServer(boost::asio::io_service& io_service, bool new_tia = false);
00118 
00123     virtual ~TiAServer();
00124 
00136     void initialize(std::map<std::string,std::string>& subject_info,
00137                     std::map<std::string,std::string>& server_settings);
00138 
00139 
00143     DataPacket* getEmptyDataPacket();
00144 
00150     void sendDataPacket();
00151 
00156     void setMasterSamplingRate(boost::uint32_t value) { master_samplingrate_ = value; }
00157 
00162     void setMasterBlocksize(boost::uint32_t value) { master_blocksize_ = value; }
00163 
00168     void setAcquiredSignalTypes(const std::vector<boost::uint32_t>& sig_types)
00169       { sig_types_ = sig_types; }
00170 
00175     void setBlockSizesPerSignalType(const std::vector<boost::uint16_t>& blocksizes)
00176       { blocksizes_ = blocksizes; }
00177 
00182     void setSamplingRatePerSignalType(const std::vector<boost::uint32_t>& fs_per_sig_type)
00183       { fs_per_sig_type_ = fs_per_sig_type; }
00184 
00192     void setChannelNames(const std::map<boost::uint32_t, std::vector<std::string> >& channels_per_sig_type)
00193       { channels_per_sig_type_ = channels_per_sig_type; }
00194 
00195   private:
00199     void createSubjectInfo(std::map<std::string,std::string> subject_info_map);
00200 
00204     void createSignalInfo();
00205 
00206     DataPacketImpl  makeDataPacketCopy(DataPacketImpl& packet);
00207     DataPacket3Impl makeDataPacketCopy(DataPacket3Impl& packet);
00208 
00209   private:
00210     boost::asio::io_service&            io_service_; 
00211     std::map<std::string, std::string>  server_settings_; 
00212     TCPDataServer*                      tcp_data_server_; 
00213     UDPDataServer*                      udp_data_server_; 
00214     ControlConnectionServer*            control_connection_server_; 
00215 
00216 
00217     tia::TiAServerStateServer*          server_state_server_;
00218     bool const new_tia_;
00219     tia::ControlConnectionServer2*            control_connection_server_2_; 
00220     tia::DataServer*                          data_server_;
00221     tia::HardwareInterface*                   hardware_interface_;
00222 
00223     boost::uint32_t                                       master_blocksize_; 
00224     boost::uint32_t                                       master_samplingrate_; 
00225     std::vector<boost::uint32_t>                          sig_types_; 
00226     std::vector<boost::uint16_t>                          blocksizes_; 
00227     std::vector<boost::uint32_t>                          fs_per_sig_type_; 
00228     std::map<boost::uint32_t, std::vector<std::string> >  channels_per_sig_type_; 
00229 
00230     SubjectInfo                         subject_info_;
00231     SignalInfo                          signal_info_;
00232 
00233     DataPacket*       data_packet_;
00234 
00235     boost::shared_ptr<DataPacketImpl>                     data_packet_impl_;
00236     boost::shared_ptr<DataPacket3Impl>                    data_packet_3_impl_;
00237 
00238     DataPacket*       work_data_packet_;
00239     DataPacketImpl*                     work_data_packet_impl_;
00240     DataPacket3Impl*                    work_data_packet_3_impl_;
00241 
00242     Constants                           cst_; 
00243 
00244 
00245 #ifdef TIMING_TEST
00246     boost::posix_time::ptime timestamp_;
00247     boost::posix_time::time_duration diff_;
00248     boost::posix_time::time_duration t_mean_;
00249     boost::posix_time::time_duration t_min_total_;
00250     boost::posix_time::time_duration t_max_total_;
00251     boost::posix_time::time_duration t_min_last_;
00252     boost::posix_time::time_duration t_max_last_;
00253     std::vector<boost::posix_time::time_duration> t_diffs_;
00254     boost::int64_t t_var_;
00255     boost::uint64_t counter_;
00256 
00257     bool  lpt_flag_;
00258 
00259 #endif
00260 };
00261 
00262 } // Namespace tobiss
00263 
00264 //-----------------------------------------------------------------------------
00265 
00266 #endif // TIA_SERVER_H
All Data Structures Files Functions Variables Enumerations