Diffstat (limited to 'x11/ipc/client/ocopclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | x11/ipc/client/ocopclient.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/x11/ipc/client/ocopclient.cpp b/x11/ipc/client/ocopclient.cpp index ac6e4a3..c1def73 100644 --- a/x11/ipc/client/ocopclient.cpp +++ b/x11/ipc/client/ocopclient.cpp | |||
@@ -14,137 +14,137 @@ | |||
14 | 14 | ||
15 | #include "ocopclient.h" | 15 | #include "ocopclient.h" |
16 | 16 | ||
17 | OCOPClient::OCOPClient( const QString& path, QObject* obj ) | 17 | OCOPClient::OCOPClient( const QString& path, QObject* obj ) |
18 | : QObject( obj ) | 18 | : QObject( obj ) |
19 | { | 19 | { |
20 | m_tries = 0; | 20 | m_tries = 0; |
21 | init(QFile::encodeName(path) ); | 21 | init(QFile::encodeName(path) ); |
22 | } | 22 | } |
23 | OCOPClient::~OCOPClient() { | 23 | OCOPClient::~OCOPClient() { |
24 | delete m_notify; | 24 | delete m_notify; |
25 | close( m_socket ); | 25 | close( m_socket ); |
26 | } | 26 | } |
27 | void OCOPClient::init() { | 27 | void OCOPClient::init() { |
28 | // failed start ther server NOW!!! | 28 | // failed start ther server NOW!!! |
29 | startUP(); | 29 | startUP(); |
30 | QCString str; | 30 | QCString str; |
31 | init(str ); | 31 | init(str ); |
32 | } | 32 | } |
33 | void OCOPClient::init( const QCString& ) { | 33 | void OCOPClient::init( const QCString& ) { |
34 | m_tries++; | 34 | m_tries++; |
35 | struct sockaddr_un unix_adr; | 35 | struct sockaddr_un unix_adr; |
36 | if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) { | 36 | if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) { |
37 | qWarning("could not socket"); | 37 | qWarning("could not socket"); |
38 | if ( m_tries < 8 ) | 38 | if ( m_tries < 8 ) |
39 | QTimer::singleShot(400, this,SLOT(init() ) ); | 39 | QTimer::singleShot(400, this,SLOT(init() ) ); |
40 | return; | 40 | return; |
41 | } | 41 | } |
42 | memset(&unix_adr, 0, sizeof(unix_adr ) ); | 42 | memset(&unix_adr, 0, sizeof(unix_adr ) ); |
43 | unix_adr.sun_family = AF_UNIX; | 43 | unix_adr.sun_family = AF_UNIX; |
44 | sprintf(unix_adr.sun_path,"%s/.opie.cop", getenv("HOME") ); | 44 | sprintf(unix_adr.sun_path,"%s/.opie.cop", getenv("HOME") ); |
45 | int length = sizeof(unix_adr.sun_family) + strlen(unix_adr.sun_path); | 45 | int length = sizeof(unix_adr.sun_family) + strlen(unix_adr.sun_path); |
46 | 46 | ||
47 | if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) { | 47 | if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) { |
48 | qWarning("could not connect %d", errno ); | 48 | qWarning("could not connect %d", errno ); |
49 | close( m_socket ); | 49 | close( m_socket ); |
50 | if ( m_tries < 8 ) | 50 | if ( m_tries < 8 ) |
51 | QTimer::singleShot(400, this, SLOT(init() ) ); | 51 | QTimer::singleShot(400, this, SLOT(init() ) ); |
52 | return; | 52 | return; |
53 | } | 53 | } |
54 | m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this ); | 54 | m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this ); |
55 | connect( m_notify, SIGNAL(activated(int) ), | 55 | connect( m_notify, SIGNAL(activated(int) ), |
56 | this, SLOT(newData() ) ); | 56 | this, SLOT(newData() ) ); |
57 | } | 57 | } |
58 | /** | 58 | /** |
59 | * new data | 59 | * new data |
60 | * read the header check magic number | 60 | * read the header check magic number |
61 | * and maybe read body | 61 | * and maybe read body |
62 | */ | 62 | */ |
63 | void OCOPClient::newData() { | 63 | void OCOPClient::newData() { |
64 | OCOPPacket pack = packet(); | 64 | OCOPPacket pack = packet(); |
65 | if ( pack.channel().isEmpty() ) | 65 | if ( pack.channel().isEmpty() ) |
66 | return; | 66 | return; |
67 | 67 | ||
68 | switch( pack.type() ) { | 68 | switch( pack.type() ) { |
69 | case OCOPPacket::Register: | 69 | case OCOPPacket::Register: |
70 | case OCOPPacket::Unregister: | 70 | case OCOPPacket::Unregister: |
71 | case OCOPPacket::Method: | 71 | case OCOPPacket::Method: |
72 | case OCOPPacket::RegisterChannel: | 72 | case OCOPPacket::RegisterChannel: |
73 | case OCOPPacket::UnregisterChannel: | 73 | case OCOPPacket::UnregisterChannel: |
74 | case OCOPPacket::Return: | 74 | case OCOPPacket::Return: |
75 | case OCOPPacket::Signal: | 75 | case OCOPPacket::Signal: |
76 | /* is Registered should be handled sync */ | 76 | /* is Registered should be handled sync */ |
77 | case OCOPPacket::IsRegistered: | 77 | case OCOPPacket::IsRegistered: |
78 | break; | 78 | break; |
79 | /* emit the signal */ | 79 | /* emit the signal */ |
80 | case OCOPPacket::Call: | 80 | case OCOPPacket::Call: |
81 | emit called( pack.channel(), pack.header(), pack.content() ); | 81 | emit called( pack.channel(), pack.header(), pack.content() ); |
82 | break; | 82 | break; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | OCOPPacket OCOPClient::packet() const{ | 85 | OCOPPacket OCOPClient::packet() const{ |
86 | QCString chan; | 86 | QCString chan; |
87 | QCString func; | 87 | QCString func; |
88 | QByteArray ar; | 88 | QByteArray ar; |
89 | OCOPHead head; | 89 | OCOPHead head; |
90 | memset(&head, 0, sizeof(head) ); | 90 | memset(&head, 0, sizeof(head) ); |
91 | read(m_socket, &head, sizeof(head) ); | 91 | read(m_socket, &head, sizeof(head) ); |
92 | if ( head.magic == 47 ) { | 92 | if ( head.magic == 47 ) { |
93 | read(m_socket, chan.data(), head.chlen ); | 93 | read(m_socket, chan.data(), head.chlen ); |
94 | read(m_socket, func.data(), head.funclen ); | 94 | read(m_socket, func.data(), head.funclen ); |
95 | read(m_socket, ar.data(), head.datalen ); | 95 | read(m_socket, ar.data(), head.datalen ); |
96 | } | 96 | } |
97 | OCOPPacket pack(head.type, chan, func, ar ); | 97 | OCOPPacket pack(head.type, chan, func, ar ); |
98 | return pack; | 98 | return pack; |
99 | } | 99 | } |
100 | /* | 100 | /* |
101 | * we've blocking IO here on these sockets | 101 | * we've blocking IO here on these sockets |
102 | * so we send and go on read | 102 | * so we send and go on read |
103 | * this will be blocked | 103 | * this will be blocked |
104 | */ | 104 | */ |
105 | bool OCOPClient::isRegistered( const QCString& chan ) const{ | 105 | bool OCOPClient::isRegistered( const QCString& chan ) const{ |
106 | /* should I disconnect the socket notfier? */ | 106 | /* should I disconnect the socket notfier? */ |
107 | OCOPPacket packe(OCOPPacket::IsRegistered, chan ); | 107 | OCOPPacket packe(OCOPPacket::IsRegistered, chan ); |
108 | OCOPHead head = packe.head(); | 108 | OCOPHead head = packe.head(); |
109 | write(m_socket, &head, sizeof(head) ); | 109 | write(m_socket, &head, sizeof(head) ); |
110 | 110 | write(m_socket, chan.data(), chan.size() ); | |
111 | /* block */ | 111 | /* block */ |
112 | OCOPPacket pack = packet(); | 112 | OCOPPacket pack = packet(); |
113 | 113 | ||
114 | /* connect here again */ | 114 | /* connect here again */ |
115 | if ( pack.channel() == chan ) { | 115 | if ( pack.channel() == chan ) { |
116 | QCString func = pack.header(); | 116 | QCString func = pack.header(); |
117 | if (func[0] == 1 ) | 117 | if (func[0] == 1 ) |
118 | return true; | 118 | return true; |
119 | } | 119 | } |
120 | 120 | ||
121 | return false; | 121 | return false; |
122 | }; | 122 | }; |
123 | void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) { | 123 | void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) { |
124 | OCOPPacket pack(OCOPPacket::Call, chan, fu, arr ); | 124 | OCOPPacket pack(OCOPPacket::Call, chan, fu, arr ); |
125 | call( pack ); | 125 | call( pack ); |
126 | } | 126 | } |
127 | void OCOPClient::addChannel(const QCString& channel) { | 127 | void OCOPClient::addChannel(const QCString& channel) { |
128 | OCOPPacket pack(OCOPPacket::RegisterChannel, channel ); | 128 | OCOPPacket pack(OCOPPacket::RegisterChannel, channel ); |
129 | call( pack ); | 129 | call( pack ); |
130 | } | 130 | } |
131 | void OCOPClient::delChannel(const QCString& chan ) { | 131 | void OCOPClient::delChannel(const QCString& chan ) { |
132 | OCOPPacket pack(OCOPPacket::UnregisterChannel, chan ); | 132 | OCOPPacket pack(OCOPPacket::UnregisterChannel, chan ); |
133 | call( pack ); | 133 | call( pack ); |
134 | } | 134 | } |
135 | void OCOPClient::call( const OCOPPacket& pack ) { | 135 | void OCOPClient::call( const OCOPPacket& pack ) { |
136 | OCOPHead head = pack.head(); | 136 | OCOPHead head = pack.head(); |
137 | write(m_socket, &head, sizeof(head) ); | 137 | write(m_socket, &head, sizeof(head) ); |
138 | write(m_socket, pack.channel().data(), pack.channel().size() ); | 138 | write(m_socket, pack.channel().data(), pack.channel().size() ); |
139 | write(m_socket, pack.header().data(), pack.header().size() ); | 139 | write(m_socket, pack.header().data(), pack.header().size() ); |
140 | write(m_socket, pack.content().data(), pack.content().size() ); | 140 | write(m_socket, pack.content().data(), pack.content().size() ); |
141 | } | 141 | } |
142 | void OCOPClient::startUP() { | 142 | void OCOPClient::startUP() { |
143 | qWarning("Start me up"); | 143 | qWarning("Start me up"); |
144 | pid_t pi = fork(); | 144 | pid_t pi = fork(); |
145 | if ( pi == 0 ) { | 145 | if ( pi == 0 ) { |
146 | setsid(); | 146 | setsid(); |
147 | execlp("opie-ipc", "opie-ipc", NULL ); | 147 | execlp("ocopserver", "ocopserver", NULL ); |
148 | _exit(1); | 148 | _exit(1); |
149 | } | 149 | } |
150 | } | 150 | } |