Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

interfaces.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           interfaces.h  -  description
00003                              -------------------
00004     begin                : Wed May 8 2002
00005     copyright            : (C) 2002 by Peter Haase
00006     email                : mail@p-haase.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00038 #ifndef SIMTHETIC_INTERFACES_HEADER
00039 #define SIMTHETIC_INTERFACES_HEADER
00040 
00041 #include <iostream>
00042 #include <string>
00043 #include <algorithm>
00044 #include <typeinfo>
00045 
00046 #include <simthetic/exceptions.h>
00047 #include <simthetic/misc.h>
00048 #include <simthetic/signals.h>
00049 
00050 
00051 // Needed for windows DLLs
00052 #ifndef DLLIMPORT
00053 #  ifdef __declspec
00054 #    if BUILDING_SIMTHETICBASE_DLL
00055 #      define DLLIMPORT __declspec (dllexport)
00056 #    else     /* Not BUILDING_LAPACK_DLL */
00057 #      define DLLIMPORT __declspec (dllimport)
00058 #    endif    /* Not BUILDING_SIMTHETICBASE_DLL */
00059 #  else
00060 #    define DLLIMPORT
00061 #  endif    /* __declspec */
00062 #endif  /* DLLIMPORT */
00063 
00064 
00065 namespace simth
00066 {
00067 
00068 
00069 class Device;
00070 
00071 
00082 class DLLIMPORT DataInterface
00083 {
00084     Device* const device_;
00085     int ID_;
00086   protected:
00087 
00091     int ID() const {return ID_;}
00095     Device* const device() const {return device_;}
00096 
00097   public:
00098 
00103     DataInterface(Device* const device, int ID)
00104         : device_(device), ID_(ID) {};
00105 
00106     virtual ~DataInterface() {};
00107 
00110     virtual void reset() = 0;
00111 
00116     static const size_t undefinedLength;
00117 };
00118 
00119 
00123 class DLLIMPORT InputInterface : public DataInterface
00124 {
00125   public:
00126 
00131     InputInterface(Device* const dev, int ID);
00132 
00133     virtual ~InputInterface();
00134 
00138     virtual void reset() = 0;
00139 
00147     virtual void acceptNewData(size_t newElements) = 0;
00148 
00160     virtual size_t sequenceLength() const = 0;
00161 
00164     virtual void setSequenceLength(size_t newLen) = 0;
00165 
00170     virtual bool isFilled() const = 0;
00171 
00173     bool isConnected() const {return isConnected_;}
00174 
00178     virtual void acceptConnection();
00179 
00189     virtual void flushProcessedSequence() = 0;
00190 
00198     virtual void releaseProcessedSequence() = 0;
00199 
00204     virtual void processFinished() = 0;
00205 
00209     //virtual size_t currentBufferSize() const = 0;
00210   private:
00211 
00212     bool isConnected_;
00213 
00214 
00215 
00216 };
00217 
00218 
00227 template<class T>
00228 class DLLIMPORT InputInterfaceT : public InputInterface
00229 {
00230 
00231   public:
00234     InputInterfaceT(Device* const dev, int ID,
00235                     size_t sequenceLength = undefinedLength,
00236                     const typename T::value_type&
00237                     default_val = typename T::value_type() );
00238 
00241     InputInterfaceT(Device* const dev, int ID,
00242                     const typename T::value_type& default_val);
00243 
00246     virtual ~InputInterfaceT();
00247 
00266     T* externSequence(size_t size, size_t capacity);
00267 
00280     T* internSequence();
00281 
00285     virtual void reset();
00286 
00292     virtual void acceptNewData(size_t size);
00293 
00307     virtual size_t sequenceLength() const;
00308 
00311     virtual void setSequenceLength(size_t newLen);
00312 
00317     virtual bool isFilled() const;
00318 
00329     virtual void flushProcessedSequence();
00330 
00338     virtual void releaseProcessedSequence();
00339 
00344     virtual void processFinished();
00345 
00346   protected:
00347     void addRefCount();
00348     void subRefCount();
00349 
00350     size_t storedElements() const {return storedElements_;}
00351     //size_t currentBufferSize() const {return seqBuffer->size();}
00352 
00353   private:
00356     typedef typename T::storage_type buffer_type;
00360     typedef typename T::access_type access_type;
00361 
00362     // Note: This IS different from the external input/output sequence
00363     // type.  In fact, this is the actual buffer which holds a
00364     // container with data. On the contrary, the external input/output
00365     // sequences are shallow copies/pointers to this very
00366     // buffer. Since February 27, 2003, both are actually different
00367     // types.
00368 
00371     buffer_type* seqBuffer;
00372 
00373 
00374 
00375     /* Attributes of the signal class. -- now to be found in the
00376        seqBuffer sequence.
00377     */
00378     //typename T::attributes_type attributes;
00379 
00383     access_type* inputSubSeq;
00384 
00388     access_type* outputSubSeq;
00389 
00394     size_t storedElements_;
00395 
00406     size_t sequenceLength_;
00407 
00410     size_t refCount;
00411 
00412     bool waitingForProcess;
00413 
00414     void invariante() const;
00415 
00416 };
00417 
00418 
00419 
00420 
00439 class OutputInterface : public DataInterface
00440 {
00441 
00442   public:
00443     OutputInterface(Device* const dev, int ID)
00444         : DataInterface(dev,ID) {};
00445 
00446     virtual ~OutputInterface() {};
00447 
00448     virtual void  connect(InputInterface* interfacePtr) = 0;
00449 
00450     virtual void reset() = 0;
00451 
00455     virtual size_t sequenceCapacity() const = 0;
00456 
00459     virtual size_t sequenceLength() const = 0;
00460 
00464     virtual void setSequenceCapacity(size_t size) = 0;
00467     virtual void setSequenceLength(size_t size) = 0;
00468 
00471     virtual bool isConnected() const = 0;
00472 
00477     virtual void flushProcessedSequences() = 0;
00478 
00482     virtual void processFinished() = 0;
00483 
00484   protected:
00492     static std::string wrongConnectionMsg(const std::type_info& output_if,
00493                                           const std::type_info& input_if);
00494 
00495 };
00496 
00505 template<class T>
00506 class OutputInterfaceT : public OutputInterface
00507 {
00508   private:
00509 
00510     size_t sequenceCapacity_;
00511     size_t sequenceLength_;
00512 
00513     typedef InputInterfaceT<T> interf_type;
00514 
00515     interf_type* connectedInterface;
00516     T* currentOutputSequence;
00517 
00518     std::vector<interf_type*> multipleConnectedInterfaces;
00519 
00520     bool isMultipleConnected_;
00521   protected:
00525     bool isMultipleConnected() const {return isMultipleConnected_;}
00526   public:
00527 
00528     OutputInterfaceT(Device* const dev, int ID);
00529 
00530     virtual size_t sequenceCapacity() const {return sequenceCapacity_;}
00531     virtual size_t sequenceLength() const {return sequenceLength_;}
00532 
00533     virtual void setSequenceCapacity(size_t size);
00534     virtual void setSequenceLength(size_t size);
00535 
00536     T* const internSequence();
00537 
00538     virtual void connect(InputInterface* interfacePtr);
00539 
00540     virtual void reset();
00541 
00542     /*Returns true if the input interface is connected with another device*/
00543     virtual bool isConnected() const {return connectedInterface != NULL;}
00544 
00545     virtual void flushProcessedSequences();
00546 
00547     virtual void processFinished();
00548 
00549 };
00550 
00551 } // namespace
00552 
00553 
00554 #endif
00555 
00556 

Generated on Mon Aug 15 13:54:26 2005 for simthetic by  doxygen 1.4.1