Initial Import
[profile/ivi/hfdialer.git] / src / pacontrol.h
1 /*
2  * hfdialer - Hands Free Voice Call Manager
3  * Copyright (c) 2012, Intel Corporation.
4  *
5  * This program is licensed under the terms and conditions of the
6  * Apache License, version 2.0.  The full text of the Apache License is at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  */
10
11 #ifndef PACONTROL_H
12 #define PACONTROL_H
13 #include <pulse/context.h>
14 #include <pulse/pulseaudio.h>
15 #include <pulse/glib-mainloop.h>
16 #include <QObject>
17
18 class PADevice {
19 public:
20     QString name;
21     int index;
22     QString description;
23 };
24
25 class PAModule {
26 public:
27     QString name;
28     int index;
29     QString argument;
30 };
31
32 enum PAStatus {
33     SUCCESS = 0,
34     ERROR = 1,
35 };
36
37 class PAControl : public QObject
38 {
39     Q_OBJECT;
40 public:
41     PAControl(QObject *parent = 0);
42     ~PAControl();
43
44     static PAControl* instance();
45
46     void reconnect();
47     PADevice* findBluezSource();
48     PADevice* findBluezSink();
49     PADevice* findAlsaSource(QString alsasource);
50     PADevice* findAlsaSink(QString alsasink);
51     PAModule* findModule(QString name, QString pattern);
52     QList<PAModule*> getAllModules();
53     void routeSourceWithSink(PADevice *source, PADevice *sink);
54
55     void unloadModule(PAModule* module);
56     void toggleMuteSource(PADevice *source, bool isMute);
57
58     PAStatus getStatus();
59     void setErrorMsg(QString msg);
60     QString getErrorMsg();
61
62     void setState(bool state);
63     void addRef();
64     void release();
65
66     void addSource(PADevice* device);
67     void addSink(PADevice* device);
68     void addModule(PAModule* module);
69
70     QList<PADevice*> sourceList;
71     QList<PADevice*> sinkList;
72     QList<PAModule*> moduleList;
73
74 public Q_SLOTS:
75     void routeAudio();
76     void unrouteAudio();
77
78 Q_SIGNALS:
79     void sourceAppeared(PADevice* device);
80     void sinkAppeared(PADevice* device);
81     void moduleAppeared(PAModule* device);
82     void paFailed();
83
84 private Q_SLOTS:
85     void onSourceAppeared(PADevice* device);
86     void onSinkAppeared(PADevice* device);
87     void onCallsChanged();
88
89 private:
90     pa_operation *pa_op;
91     pa_context *pa_ctx;
92     PAStatus status;
93     QString errorMsg;
94
95     void paInit();
96     void paCleanup();
97
98
99     bool m_paState;
100     int  m_refCounter;
101     bool m_connected;
102     bool m_audioRouted;
103     bool m_btSourceReady;
104     bool m_btSinkReady;
105 };
106
107 #endif // PACONTROL_H
108
109 /* Local Variables:      */
110 /* mode:c++              */
111 /* c-basic-offset:4      */
112 /* indent-tabs-mode: nil */
113 /* End:                  */