summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/rfcommhelper.h
blob: 545998c05ebcdef30c8532f1e62b38740db1c6e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

#ifndef OPIETOOTH_RFCOMM_HELPER_H
#define OPIETOOTH_RFCOMM_HELPER_H

#include <sys/types.h>

#include <qcstring.h>
#include <qstring.h>

namespace OpieTooth {
    /**
     * RfCommHelper helps to attach to a remote
     * channel of a bt device.
     * It uses the commandline tool rfcomm fo the job
     * it tries to attach to afree node and either succeeds
     * or fails.
     * Later RfCommHelper can be used to detach the device
     * from the remote device
     */
    class RfCommHelper {
    public:
        /**
         * c'tor
         */
        RfCommHelper();

        /**
         * d'tor removes the device
         */
        ~RfCommHelper(); // kills the process

        /**
         * gives the device name of the attached device
         */
        QCString attachedDevice() const;

        /**
         * detach a device
         * kills the rfcomm process
         */
        void detach();

        /**
         * tries to connect to a remote device
         * @param bd_addr the bluetooth address
         * @param port The port of the remote device
         */
        bool attach(const QString& bd_addr, int port );

        /**
         * If the original user of the bond exists
         * it may regroup the rfcomm process
         */
        void regroup();
    private:
        bool connect( int dev, const QString& bdaddr, int port );
        static void signal_handler(int);
        void setupComChild();
        bool m_connected:1;
        static pid_t m_pid;
        QCString m_device;
        int m_fd[2];
        int m_in2out[2];
        int m_out2in[2];
        static bool terminate ;
    };
};

#endif