ACQ2XX_API
DirfileFrameHandler.cpp
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file DirfileFrameHandler.cpp                                              */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2009 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006 
00007  This program is free software; you can redistribute it and/or modify
00008  it under the terms of Version 2 of the GNU General Public License
00009  as published by the Free Software Foundation;
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program; if not, write to the Free Software
00018  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00019 /* ------------------------------------------------------------------------- */
00020 
00021 /** @file DirfileFrameHandler.cpp - adapter connects stream data to Dirfile output.
00022  *
00023 <pre>
00024   opts:
00025 </pre>
00026  */
00027 #include "local.h"
00028 #include "acq2xx_api.h"
00029 #include "acq_transport.h"
00030 #include "AcqType.h"
00031 #include "Frame.h"
00032 #include "AcqDataModel.h"
00033 
00034 #include "DataStreamer.h"
00035 #include "DirfileFrameHandler.h"
00036 
00037 template <class T>
00038 class ConcreteDirfileFrameHandler: public DirfileFrameHandler {
00039         AcqDataModel * model;
00040         const string root;
00041 
00042 public:
00043         ConcreteDirfileFrameHandler(AcqDataModel* _model, string _root):
00044                 model(_model), root(_root)
00045         {
00046                 model->dumpFormat(root);
00047         }
00048         virtual void onFrame(
00049                         Acq2xx& _card, const AcqType& _acqType,
00050                         const Frame* frame)
00051         {
00052                 const ConcreteFrame<T> *cf = 
00053                         dynamic_cast<const ConcreteFrame<T> *>(frame);
00054 
00055                 model->clear(FRAME_SAMPLES);
00056 
00057                 for (int ch = 1; ch <= _acqType.getNumChannels(); ++ch){
00058                         model->processCooked(
00059                                 cf->getChannel(ch), ch, FRAME_SAMPLES);
00060                 }
00061 
00062                 model->dump(root);
00063         }
00064 };
00065 
00066 FrameHandler* DirfileFrameHandler::create(
00067         const AcqType& acqType, string outbase)
00068 {
00069         AcqDataModel *model = AcqDataModel::create(acqType);
00070 
00071         if (acqType.getWordSize() == sizeof(short)){
00072                 return new ConcreteDirfileFrameHandler<short>(model, outbase);
00073         }else{
00074                 return new ConcreteDirfileFrameHandler<int>(model, outbase);
00075         }       
00076 }