TOBI Interface A  0.1
/home/breidi/Dropbox/libtia/src/tia/newtia/tia_datapacket_parser.cpp
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 
00034 #include <string>
00035 #include <iostream>
00036 
00037 #include "tia-private/newtia/tia_datapacket_parser.h"
00038 #include "tia/defines.h"
00039 
00040 
00041 using std::string;
00042 
00043 namespace tia
00044 {
00045 
00046 static const int MINIMAL_DATA_PACKET_SIZE = 32;  
00047 
00048 //-----------------------------------------------------------------------------
00049 
00050 TiADataPacketParser::TiADataPacketParser(InputStream& input_stream)
00051   :input_stream_(input_stream)
00052 {
00053   buffer_ = new char[BUFFER_SIZE];
00054 }
00055 
00056 //-----------------------------------------------------------------------------
00057 
00058 TiADataPacketParser::~TiADataPacketParser()
00059 {
00060   if(buffer_)
00061     delete[] buffer_;
00062 }
00063 
00064 //-----------------------------------------------------------------------------
00065 
00066 void TiADataPacketParser::parseDataPacket (DataPacket& packet)
00067 {
00068   size_t received = input_stream_.readBytes(buffer_,MINIMAL_DATA_PACKET_SIZE);
00069 
00070   size_t needed = packet.getRequiredRawMemorySize(buffer_,received);
00071 
00072   while(received < needed)
00073     received += input_stream_.readBytes(buffer_+received, needed - received);
00074 
00075   packet.reset(buffer_);
00076 }
00077 
00078 //-----------------------------------------------------------------------------
00079 
00080 //DataPacketImpl TiADataPacketParser::parseFustyDataPacketFromStream (InputStream& input_stream, bool& run)
00081 //{
00082 //    DataPacketImpl packet;
00083 //    char buffer[10000];
00084 //    unsigned available = 0;
00085 //    for (; (available < 32) && run; ++available)
00086 //        buffer[available] = input_stream.readCharacter ();
00087 
00088 //    unsigned bytes_needed = packet.getRequiredRawMemorySize (reinterpret_cast<void*>(buffer), available);
00089 //    while ((bytes_needed != available) && run)
00090 //    {
00091 //        buffer[available] = input_stream.readCharacter ();
00092 //        available++;
00093 //        bytes_needed = packet.getRequiredRawMemorySize (reinterpret_cast<void*>(buffer), available);
00094 //    }
00095 //    if (!run)
00096 //        return packet;
00097 //    return DataPacketImpl (reinterpret_cast<void*>(buffer));
00098 //}
00099 
00100 //-----------------------------------------------------------------------------
00101 //DataPacket3Impl TiADataPacketParser::parseFustyDataPacket3FromStream (InputStream& /*input_stream*/)
00102 //{
00103 //    return DataPacket3Impl ();
00104 //}
00105 
00106 }
00107 
 All Data Structures Files Functions Variables Typedefs Enumerations