summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/startpanconnection.cpp
blob: 29b95e9f2cd9ef503afc29ea9bb89ec601dddde6 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <opie2/odebug.h>
#include "startpanconnection.h"

using namespace OpieTooth;


using namespace Opie::Core;
using namespace Opie::Core;
StartPanConnection::StartPanConnection() {
    m_panConnect = 0l;
    setConnectionType();
}

StartPanConnection::~StartPanConnection() {
    delete m_panConnect;
}

StartPanConnection::StartPanConnection( QString mac )  {
    m_panConnect = 0l;
    m_mac = mac;
    setConnectionType();
}

void StartPanConnection::setName( QString name ) {
    m_name = name;
}

QString StartPanConnection::name()  {
    return m_name;
}

void StartPanConnection::setConnectionType() {
    m_connectionType = Pan;
}

StartConnection::ConnectionType StartPanConnection::type() {
    return m_connectionType;
}

void StartPanConnection::start()  {
    m_panConnect = new OProcess();
    odebug << "IM START " + m_mac << oendl; 
    *m_panConnect << "pand" << "--connect" << m_mac;

    connect( m_panConnect, SIGNAL( processExited(Opie::Core::OProcess*) ) ,
             this, SLOT( slotExited(Opie::Core::OProcess*) ) );
    connect( m_panConnect, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
             this, SLOT( slotStdOut(Opie::Core::OProcess*,char*,int) ) );
    if (!m_panConnect->start( OProcess::NotifyOnExit, OProcess::AllOutput) ) {
        owarn << "could not start" << oendl; 
        delete m_panConnect;
    }
}


void StartPanConnection::slotExited( OProcess* proc ) {
    delete m_panConnect;
    m_panConnect = 0l;
}

void StartPanConnection::slotStdOut(OProcess* proc, char* chars, int len)
{}


void StartPanConnection::stop()  {
    if ( m_panConnect )  {
        delete m_panConnect;
        m_panConnect = 0l;
    }
    m_panConnect = new OProcess();
    odebug << "IM STOP " + m_mac << oendl; 

    *m_panConnect << "pand" << "--kill" << m_mac;

    connect( m_panConnect, SIGNAL( processExited(Opie::Core::OProcess*) ) ,
             this, SLOT( slotExited(Opie::Core::OProcess*) ) );
    connect( m_panConnect, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
             this, SLOT( slotStdOut(Opie::Core::OProcess*,char*,int) ) );
    if (!m_panConnect->start( OProcess::NotifyOnExit, OProcess::AllOutput) ) {
        owarn << "could not stop" << oendl; 
        delete m_panConnect;
    }
}