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 
00112     static const size_t undefinedLength;
00113 };
00114 
00115 
00119 class DLLIMPORT InputInterface : public DataInterface
00120 {
00121   public:
00122 
00127     InputInterface(Device* const dev, int ID);
00128 
00129     virtual ~InputInterface();
00130 
00134     virtual void reset() = 0;
00135 
00143     virtual void acceptNewData(size_t newElements) = 0;
00144 
00156     virtual size_t sequenceLength() const = 0;
00157 
00160     virtual void setSequenceLength(size_t newLen) = 0;
00161 
00166     virtual bool isFilled() const = 0;
00167 
00169     bool isConnected() const {return isConnected_;}
00170 
00174     virtual void acceptConnection();
00175 
00185     virtual void flushProcessedSequence() = 0;
00186 
00194     virtual void releaseProcessedSequence() = 0;
00195 
00200     virtual void processFinished() = 0;
00201 
00205     //virtual size_t currentBufferSize() const = 0;
00206   private:
00207 
00208     bool isConnected_;
00209 
00210 
00211 
00212 };
00213 
00214 
00223 template<class T>
00224 class DLLIMPORT InputInterfaceT : public InputInterface
00225 {
00226 
00227   public:
00230     InputInterfaceT(Device* const dev, int ID,
00231                     size_t sequenceLength = undefinedLength,
00232                     const typename T::value_type&
00233                     default_val = typename T::value_type() );
00234 
00237     InputInterfaceT(Device* const dev, int ID,
00238                     const typename T::value_type& default_val);
00239 
00242     virtual ~InputInterfaceT();
00243 
00262     T* externSequence(size_t size, size_t capacity);
00263 
00276     T* internSequence();
00277 
00281     virtual void reset();
00282 
00288     virtual void acceptNewData(size_t size);
00289 
00301     virtual size_t sequenceLength() const;
00302 
00305     virtual void setSequenceLength(size_t newLen);
00306 
00311     virtual bool isFilled() const;
00312 
00323     virtual void flushProcessedSequence();
00324 
00332     virtual void releaseProcessedSequence();
00333 
00338     virtual void processFinished();
00339 
00340   protected:
00341     void incrementRefCount();
00342     void decrementRefCount();
00343 
00344     size_t storedElements() const {return storedElements_;}
00345     //size_t currentBufferSize() const {return seqBuffer->size();}
00346 
00347   private:
00350     typedef typename T::storage_type buffer_type;
00354     typedef typename T::access_type access_type;
00355 
00356     // Note: This IS different from the external input/output sequence
00357     // type.  In fact, this is the actual buffer which holds a
00358     // container with data. On the contrary, the external input/output
00359     // sequences are shallow copies/pointers to this very
00360     // buffer. Since February 27, 2003, both are actually different
00361     // types.
00362 
00365     buffer_type* seqBuffer;
00366 
00367 
00368 
00369     /* Attributes of the signal class. -- now to be found in the
00370        seqBuffer sequence.
00371     */
00372     //typename T::attributes_type attributes;
00373 
00377     access_type* inputSubSeq;
00378 
00382     access_type* outputSubSeq;
00383 
00388     size_t storedElements_;
00389 
00400     size_t sequenceLength_;
00401 
00404     size_t refCount;
00405 
00406     bool waitingForProcess;
00407 
00408     void invariante() const;
00409 
00410 };
00411 
00412 
00413 
00414 
00433 class OutputInterface : public DataInterface
00434 {
00435 
00436   public:
00437     OutputInterface(Device* const dev, int ID)
00438         : DataInterface(dev,ID) {};
00439 
00440     virtual ~OutputInterface() {};
00441 
00442     virtual void connect(InputInterface* interfacePtr) = 0;
00443 
00447     virtual void reset() = 0;
00448 
00452     virtual size_t sequenceCapacity() const = 0;
00453 
00456     virtual size_t sequenceLength() const = 0;
00457 
00461     virtual void setSequenceCapacity(size_t size) = 0;
00464     virtual void setSequenceLength(size_t size) = 0;
00465 
00468     virtual bool isConnected() const = 0;
00469 
00474     virtual void flushProcessedSequences() = 0;
00475 
00479     virtual void processFinished() = 0;
00480 
00481   protected:
00489     static std::string wrongConnectionMsg(const std::type_info& output_if,
00490                                           const std::type_info& input_if);
00491 
00492 };
00493 
00502 template<class T>
00503 class OutputInterfaceT : public OutputInterface
00504 {
00505   private:
00506 
00507     size_t sequenceCapacity_;
00508     size_t sequenceLength_;
00509 
00510     typedef InputInterfaceT<T> interf_type;
00511 
00512     interf_type* connectedInterface;
00513     T* currentOutputSequence;
00514 
00515     std::vector<interf_type*> multipleConnectedInterfaces;
00516 
00517     bool isMultipleConnected_;
00518   protected:
00522     bool isMultipleConnected() const {return isMultipleConnected_;}
00523   public:
00524 
00525     OutputInterfaceT(Device* const dev, int ID);
00526 
00527     virtual size_t sequenceCapacity() const {return sequenceCapacity_;}
00528     virtual size_t sequenceLength() const {return sequenceLength_;}
00529 
00530     virtual void setSequenceCapacity(size_t size);
00531     virtual void setSequenceLength(size_t size);
00532 
00533     T* const internSequence();
00534 
00535     virtual void connect(InputInterface* interfacePtr);
00536 
00537     virtual void reset();
00538 
00539     /*Returns true if the input interface is connected with another device*/
00540     virtual bool isConnected() const {return connectedInterface != NULL;}
00541 
00542     virtual void flushProcessedSequences();
00543 
00544     virtual void processFinished();
00545 
00546 };
00547 
00548 } // namespace
00549 
00550 
00551 #endif
00552 
00553 

Generated on Mon Apr 24 21:19:19 2006 for simthetic by  doxygen 1.4.1