Show
Ignore:
Timestamp:
11/30/07 14:18:26 (15 years ago)
Author:
ppalmers
Message:

Code refactoring. Tries to simplify things and tries to put all code where it belongs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libieee1394/IsoHandlerManager.h

    r747 r750  
    3434#include <vector> 
    3535 
     36#define FFADO_MAX_ISO_HANDLERS_PER_PORT 16 
     37 
    3638#define USLEEP_AFTER_UPDATE_FAILURE 10 
    3739#define USLEEP_AFTER_UPDATE 100 
    3840#define MAX_UPDATE_TRIES 10 
     41class Ieee1394Service; 
    3942namespace Util { 
    4043    class PosixThread; 
    4144} 
    4245 
    43 namespace Streaming 
    44 { 
    4546class IsoHandler; 
    46 class StreamProcessor; 
     47namespace Streaming { 
     48    class StreamProcessor; 
     49    class StreamProcessorManager; 
     50    typedef std::vector<StreamProcessor *> StreamProcessorVector; 
     51    typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator; 
     52
    4753 
    4854typedef std::vector<IsoHandler *> IsoHandlerVector; 
    4955typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator; 
    50  
    51 typedef std::vector<StreamProcessor *> StreamProcessorVector; 
    52 typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator; 
    53  
    5456 
    5557/*! 
     
    5759 
    5860 This class manages the use of ISO handlers by ISO streams. 
    59  You can register an StreamProcessor with an IsoHandlerManager. This 
     61 You can register an Streaming::StreamProcessor with an IsoHandlerManager. This 
    6062 manager will assign an IsoHandler to the stream. If nescessary 
    6163 the manager allocates a new handler. If there is already a handler 
    62  that can handle the StreamProcessor (e.g. in case of multichannel receive), 
     64 that can handle the Streaming::StreamProcessor (e.g. in case of multichannel receive), 
    6365 it can be assigned. 
    6466 
    6567*/ 
    66  
    6768class IsoHandlerManager : public Util::RunnableInterface 
    6869{ 
    69     friend class StreamProcessorManager; 
     70    friend class Streaming::StreamProcessorManager; 
    7071 
    7172    public: 
    7273 
    73         IsoHandlerManager(); 
    74         IsoHandlerManager(bool run_rt, unsigned int rt_prio); 
    75         virtual ~IsoHandlerManager() {}; 
     74        IsoHandlerManager(Ieee1394Service& service); 
     75        IsoHandlerManager(Ieee1394Service& service, bool run_rt, unsigned int rt_prio); 
     76        virtual ~IsoHandlerManager(); 
     77 
     78        bool setThreadParameters(bool rt, int priority); 
    7679 
    7780        void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll() 
     
    8588        void dumpInfo(); ///< print some information about the manager to stdout/stderr 
    8689 
    87         bool registerStream(StreamProcessor *); ///< register an iso stream with the manager 
    88         bool unregisterStream(StreamProcessor *); ///< unregister an iso stream from the manager 
     90        bool registerStream(Streaming::StreamProcessor *); ///< register an iso stream with the manager 
     91        bool unregisterStream(Streaming::StreamProcessor *); ///< unregister an iso stream from the manager 
    8992 
    9093        bool startHandlers(); ///< start the managed ISO handlers 
     
    9396 
    9497        bool reset(); ///< reset the ISO manager and all streams 
    95  
    96         bool prepare(); ///< prepare the ISO manager and all streams 
    97  
    9898        bool init(); 
    9999 
    100         void disablePolling(StreamProcessor *); ///< disables polling on a stream 
    101         void enablePolling(StreamProcessor *); ///< enables polling on a stream 
     100        bool disable(IsoHandler *); ///< disables a handler 
     101        bool enable(IsoHandler *); ///< enables a handler 
     102        ///> disables the handler attached to the stream 
     103        bool stopHandlerForStream(Streaming::StreamProcessor *); 
     104        ///> starts the handler attached to the specific stream 
     105        bool startHandlerForStream(Streaming::StreamProcessor *); 
     106        ///> starts the handler attached to the specific stream on a specific cycle 
     107        bool startHandlerForStream(Streaming::StreamProcessor *, int cycle);  
    102108 
     109        /** 
     110         * returns the latency of a wake-up for this stream. 
     111         * The latency is the time it takes for a packet is delivered to the 
     112         * stream after it has been received (was on the wire). 
     113         * expressed in cycles 
     114         */ 
     115        int getPacketLatencyForStream(Streaming::StreamProcessor *); 
     116 
     117        void flushHandlerForStream(Streaming::StreamProcessor *stream); 
     118 
     119        Ieee1394Service& get1394Service() {return m_service;}; 
    103120    // RunnableInterface interface 
    104121    public: 
    105122        bool Execute(); // note that this is called in we while(running) loop 
    106123        bool Init(); 
    107         pthread_mutex_t m_debug_lock; 
     124         
     125        // protects the operations on the lists  
     126        // (FIXME: should be changed into a lock-free approach) 
     127        pthread_mutex_t m_list_lock; 
    108128 
    109129    // the state machine 
    110130    private: 
    111         enum EHandlerStates { 
     131        enum eHandlerStates { 
    112132            E_Created, 
    113133            E_Prepared, 
     
    116136        }; 
    117137 
    118         enum EHandlerStates m_State; 
    119  
     138        enum eHandlerStates m_State; 
     139        const char *eHSToString(enum eHandlerStates); 
    120140    private: 
    121141        /// iterate all child handlers 
     
    123143 
    124144    private: 
     145        Ieee1394Service&  m_service; 
    125146        // note: there is a disctinction between streams and handlers 
    126147        // because one handler can serve multiple streams (in case of 
     
    139160 
    140161        // the collection of streams 
    141         StreamProcessorVector m_StreamProcessors; 
     162        Streaming::StreamProcessorVector m_StreamProcessors; 
    142163 
    143164        // poll stuff 
    144165        int m_poll_timeout; 
    145         struct pollfd *m_poll_fds; 
    146         int m_poll_nfds; 
     166        // FD map sync requested 
     167        int32_t m_request_fdmap_update; 
     168        void updateShadowVars(); 
    147169 
    148         bool rebuildFdMap(); 
     170        // shadow variables 
     171        struct pollfd m_poll_fds_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT]; 
     172        IsoHandler *m_IsoHandler_map_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT]; 
     173        unsigned int m_poll_nfds_shadow; 
     174 
     175        void requestShadowUpdate(); 
    149176 
    150177        // threading 
     
    161188}; 
    162189 
    163 } 
    164  
    165190#endif /* __FFADO_ISOHANDLERMANAGER__  */ 
    166191