summaryrefslogtreecommitdiff
path: root/x11/ipc
authorzecke <zecke>2002-10-16 01:05:42 (UTC)
committer zecke <zecke>2002-10-16 01:05:42 (UTC)
commit3e973543b77631d053a9616b5540966dbe51ab47 (patch) (unidiff)
tree8b47c7015ec9706b2dc794ce0cf382d50f47b680 /x11/ipc
parent65ef0e86a879332cbf8b1575886d3c36c7d2d9bd (diff)
downloadopie-3e973543b77631d053a9616b5540966dbe51ab47.zip
opie-3e973543b77631d053a9616b5540966dbe51ab47.tar.gz
opie-3e973543b77631d053a9616b5540966dbe51ab47.tar.bz2
Make it link
Diffstat (limited to 'x11/ipc') (more/less context) (ignore whitespace changes)
-rw-r--r--x11/ipc/client/ocopclient.cpp18
-rw-r--r--x11/ipc/client/ocopclient.h2
2 files changed, 10 insertions, 10 deletions
diff --git a/x11/ipc/client/ocopclient.cpp b/x11/ipc/client/ocopclient.cpp
index 1c25271..43e426c 100644
--- a/x11/ipc/client/ocopclient.cpp
+++ b/x11/ipc/client/ocopclient.cpp
@@ -1,129 +1,129 @@
1#include <errno.h> 1#include <errno.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <sys/socket.h> 5#include <sys/socket.h>
6#include <sys/un.h> 6#include <sys/un.h>
7 7
8 8
9#include <qfile.h> 9#include <qfile.h>
10#include <qtimer.h> 10#include <qtimer.h>
11 11
12#include "../common/ocoppacket.h" 12#include "../common/ocoppacket.h"
13 13
14#include "ocopclient.h" 14#include "ocopclient.h"
15 15
16OCOPClient::OCOPClient( const QString& path, QObject* obj ) 16OCOPClient::OCOPClient( const QString& path, QObject* obj )
17 : QObject( obj ) 17 : QObject( obj )
18{ 18{
19 init(QFile::encodeName(path) ); 19 init(QFile::encodeName(path) );
20} 20}
21OCOPClient::~OCOPClient() { 21OCOPClient::~OCOPClient() {
22 close( m_socket ); 22 close( m_socket );
23} 23}
24void OCOPClient::init( const QCString& str ) { 24void OCOPClient::init( const QCString& ) {
25 struct sockaddr_un unix_adr; 25 struct sockaddr_un unix_adr;
26 if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) { 26 if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) {
27 qWarning("could not socket"); 27 qWarning("could not socket");
28 QTimer::singleShot(400, this,SLOT(init() ) ); 28 QTimer::singleShot(400, this,SLOT(init() ) );
29 return; 29 return;
30 } 30 }
31 memset(&unix_adr, 0, sizeof(unix_adr ) ); 31 memset(&unix_adr, 0, sizeof(unix_adr ) );
32 unix_adr.sun_family = AF_UNIX; 32 unix_adr.sun_family = AF_UNIX;
33 sprintf(unix_adr.sun_path,"%s/.opie.cop", getenv("HOME") ); 33 sprintf(unix_adr.sun_path,"%s/.opie.cop", getenv("HOME") );
34 int length = sizeof(unix_adr.sun_family) + strlen(unix_adr.sun_path); 34 int length = sizeof(unix_adr.sun_family) + strlen(unix_adr.sun_path);
35 35
36 if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) { 36 if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) {
37 qWarning("could not connect %d", errno ); 37 qWarning("could not connect %d", errno );
38 close( m_socket ); 38 close( m_socket );
39 QTimer::singleShot(400, this, SLOT(init() ) ); 39 QTimer::singleShot(400, this, SLOT(init() ) );
40 return; 40 return;
41 } 41 }
42 m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this ); 42 m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this );
43 connect( m_notify, SIGNAL(activated(int) ), 43 connect( m_notify, SIGNAL(activated(int) ),
44 this, SLOT(newData() ) ); 44 this, SLOT(newData() ) );
45} 45}
46/** 46/**
47 * new data 47 * new data
48 * read the header check magic number 48 * read the header check magic number
49 * and maybe read body 49 * and maybe read body
50 */ 50 */
51void OCOPClient::newData() { 51void OCOPClient::newData() {
52 OCOPPacket pack = packet(); 52 OCOPPacket pack = packet();
53 if ( pack.channel().isEmpty() ) 53 if ( pack.channel().isEmpty() )
54 return; 54 return;
55 55
56 switch( pack.type() ) { 56 switch( pack.type() ) {
57 case OCOPPacket::Register: 57 case OCOPPacket::Register:
58 case OCOPPacket::Unregister: 58 case OCOPPacket::Unregister:
59 case OCOPPacket::Method: 59 case OCOPPacket::Method:
60 case OCOPPacket::RegisterChannel: 60 case OCOPPacket::RegisterChannel:
61 case OCOPPacket::UnregisterChannel: 61 case OCOPPacket::UnregisterChannel:
62 case OCOPPacket::Return: 62 case OCOPPacket::Return:
63 case OCOPPacket::Signal: 63 case OCOPPacket::Signal:
64 /* is Registered should be handled sync */ 64 /* is Registered should be handled sync */
65 case OCOPPacket::isRegistered: 65 case OCOPPacket::IsRegistered:
66 break; 66 break;
67 /* emit the signal */ 67 /* emit the signal */
68 case OCOPPacket::Call: 68 case OCOPPacket::Call:
69 emit called( pack.channel(), pack.header(), pack.content() ); 69 emit called( pack.channel(), pack.header(), pack.content() );
70 break; 70 break;
71 } 71 }
72} 72}
73OCOPPacket OCOPClient::packet() { 73OCOPPacket OCOPClient::packet() const{
74 QCString chan; 74 QCString chan;
75 QCString func; 75 QCString func;
76 QByteArray ar; 76 QByteArray ar;
77 OCOPHead head; 77 OCOPHead head;
78 memset(&head, 0, sizeof(head) ); 78 memset(&head, 0, sizeof(head) );
79 read(m_socket, &head, sizeof(head) ); 79 read(m_socket, &head, sizeof(head) );
80 if ( head.magic == 47 ) { 80 if ( head.magic == 47 ) {
81 read(m_socket, chan.data(), head.chlen ); 81 read(m_socket, chan.data(), head.chlen );
82 read(m_socket, func.data(), head.funclen ); 82 read(m_socket, func.data(), head.funclen );
83 read(m_socket, ar.data(), head.datalen ); 83 read(m_socket, ar.data(), head.datalen );
84 } 84 }
85 OCOPPacket pack(head.type, chan, func, data ); 85 OCOPPacket pack(head.type, chan, func, ar );
86 return pack; 86 return pack;
87} 87}
88/* 88/*
89 * we've blocking IO here on these sockets 89 * we've blocking IO here on these sockets
90 * so we send and go on read 90 * so we send and go on read
91 * this will be blocked 91 * this will be blocked
92 */ 92 */
93bool OCOPClient::isRegistered( const QCString& chan ) { 93bool OCOPClient::isRegistered( const QCString& chan ) const{
94 /* should I disconnect the socket notfier? */ 94 /* should I disconnect the socket notfier? */
95 OCOPPacket packe(OCOPPacket::IsRegistered, chan ); 95 OCOPPacket packe(OCOPPacket::IsRegistered, chan );
96 OCOPHead head = packe.head(); 96 OCOPHead head = packe.head();
97 write(m_socket, &head, sizeof(head) ); 97 write(m_socket, &head, sizeof(head) );
98 98
99 /* block */ 99 /* block */
100 OCOPPacket pack = packet(); 100 OCOPPacket pack = packet();
101 101
102 /* connect here again */ 102 /* connect here again */
103 if ( pack.channel() == chan ) { 103 if ( pack.channel() == chan ) {
104 QCString func = pack.header(); 104 QCString func = pack.header();
105 if (func[0] == 1 ) 105 if (func[0] == 1 )
106 return; 106 return true;
107 } 107 }
108 108
109 return false; 109 return false;
110}; 110};
111void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) { 111void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) {
112 OCOPPacket pack(OCOPPacket::Call, chan, fu, arr ); 112 OCOPPacket pack(OCOPPacket::Call, chan, fu, arr );
113 call( pack ); 113 call( pack );
114} 114}
115void OCOPClient::addChannel(const QCString& channet) { 115void OCOPClient::addChannel(const QCString& channel) {
116 OCOPPacket pack(OCOPPacket::RegisterChannel, channel ); 116 OCOPPacket pack(OCOPPacket::RegisterChannel, channel );
117 call( pack ); 117 call( pack );
118} 118}
119void OCOPClient::delChannel(const QCString& chan ) { 119void OCOPClient::delChannel(const QCString& chan ) {
120 OCOPPacket pack(OCOPPacket::UnregisterChannel, channel ); 120 OCOPPacket pack(OCOPPacket::UnregisterChannel, chan );
121 call( pack ); 121 call( pack );
122} 122}
123void OCOPPacket::call( const OCOPPacket& pack ) { 123void OCOPClient::call( const OCOPPacket& pack ) {
124 OCOPHead head = pack.head(); 124 OCOPHead head = pack.head();
125 write(m_socket, &head, sizeof(head) ); 125 write(m_socket, &head, sizeof(head) );
126 write(m_socket, pack.channel().data(), pack.channel().size() ); 126 write(m_socket, pack.channel().data(), pack.channel().size() );
127 write(m_socket, pack.header().data(), pack.header().size() ); 127 write(m_socket, pack.header().data(), pack.header().size() );
128 write(m_socket, pack.content().data(), pack.content().size() ); 128 write(m_socket, pack.content().data(), pack.content().size() );
129} 129}
diff --git a/x11/ipc/client/ocopclient.h b/x11/ipc/client/ocopclient.h
index db04d37..e9544b9 100644
--- a/x11/ipc/client/ocopclient.h
+++ b/x11/ipc/client/ocopclient.h
@@ -1,59 +1,59 @@
1#ifndef OPIE_OCOP_CLIENT_H 1#ifndef OPIE_OCOP_CLIENT_H
2#define OPIE_OCOP_CLIENT_H 2#define OPIE_OCOP_CLIENT_H
3 3
4 4
5#include <qobject.h> 5#include <qobject.h>
6#include <qcstring.h> 6#include <qcstring.h>
7#include <qmap.h> 7#include <qmap.h>
8#include <qsignal.h> 8#include <qsignal.h>
9#include <qstring.h> 9#include <qstring.h>
10#include <qsocketnotifier.h> 10#include <qsocketnotifier.h>
11 11
12 12
13/** 13/**
14 * This is the OCOP client 14 * This is the OCOP client
15 * It currently only supports 15 * It currently only supports
16 * asking if a Channel is registered, 16 * asking if a Channel is registered,
17 * calling and receiving calls 17 * calling and receiving calls
18 */ 18 */
19class OCOPPacket; 19class OCOPPacket;
20class OCOPClient : public QObject{ 20class OCOPClient : public QObject{
21 Q_OBJECT 21 Q_OBJECT
22public: 22public:
23 23
24 /** 24 /**
25 * Occasionally I decide to start a Server from here 25 * Occasionally I decide to start a Server from here
26 */ 26 */
27 OCOPClient(const QString& pathToServer = QString::null, QObject* obj = 0l); 27 OCOPClient(const QString& pathToServer = QString::null, QObject* obj = 0l);
28 ~OCOPClient(); 28 ~OCOPClient();
29 29
30 bool isRegistered( const QCString& )const; 30 bool isRegistered( const QCString& )const;
31 void send( const QCString& chan, const QCString&, const QByteArray& msg ); 31 void send( const QCString& chan, const QCString&, const QByteArray& msg );
32 32
33 /** 33 /**
34 * add a channel and does connect to a signal 34 * add a channel and does connect to a signal
35 * callback is the object 35 * callback is the object
36 * slot is the SLOT() 36 * slot is the SLOT()
37 */ 37 */
38 void addChannel( const QCString& channel ); 38 void addChannel( const QCString& channel );
39 void delChannel( const QCString& channel ); 39 void delChannel( const QCString& channel );
40 40
41 /* make it singleton? */ 41 /* make it singleton? */
42 //static OCOPClient* self(); 42 //static OCOPClient* self();
43/* no direct signals due the design */ 43/* no direct signals due the design */
44signals: 44signals:
45 void called(const QCString&, const QCString&, const QByteArray& ); 45 void called(const QCString&, const QCString&, const QByteArray& );
46private slots: 46private slots:
47 void init(const QCString& pa); 47 void init(const QCString& pa);
48 void newData(); 48 void newData();
49private: 49private:
50 OCOPPacket packet(); 50 OCOPPacket packet()const;
51 void call( const OCOPPacket& ); 51 void call( const OCOPPacket& );
52 52
53 QSocketNotifier* m_notify; 53 QSocketNotifier* m_notify;
54 int m_socket; 54 int m_socket;
55private slots: 55private slots:
56 56
57}; 57};
58 58
59#endif 59#endif