Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > by-pkgid > 1f8d0d1e253a3f5aed78d2096c2df11f > files > 11

audiere-debug-1.9.4-7mdv2009.0.i586.rpm

#ifndef DEVICE_H
#define DEVICE_H


#include <queue>
#include "audiere.h"
#include "threads.h"


namespace audiere {
  
  /// Basic StopEvent implementation.
  class StopEventImpl : public RefImplementation<StopEvent> {
  public:
    StopEventImpl(OutputStream* os, Reason reason) {
      m_stream = os;
      m_reason = reason;
    }

    OutputStream* ADR_CALL getOutputStream() {
      return m_stream.get();
    }

    Reason ADR_CALL getReason() {
      return m_reason;
    }

  private:
    OutputStreamPtr m_stream;
    Reason m_reason;
  };


  /// Contains default implementation of functionality common to all devices.
  class AbstractDevice : public RefImplementation<AudioDevice> {
  protected:
    AbstractDevice();
    ~AbstractDevice();

  public:
    void ADR_CALL registerCallback(Callback* callback);
    void ADR_CALL unregisterCallback(Callback* callback);
    void ADR_CALL clearCallbacks();

  protected:
    void fireStopEvent(OutputStream* stream, StopEvent::Reason reason);
    void fireStopEvent(const StopEventPtr& event);

  private:
    static void eventThread(void* arg);
    void eventThread();
    void processEvent(Event* event);

    volatile bool m_thread_exists;
    volatile bool m_thread_should_die;

    Mutex m_event_mutex;
    CondVar m_events_available;
    typedef std::queue<EventPtr> EventQueue;
    EventQueue m_events;

    std::vector<CallbackPtr> m_callbacks;
  };

}


#endif