-rw-r--r-- | x11/ipc/client/ocopclient.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/x11/ipc/client/ocopclient.cpp b/x11/ipc/client/ocopclient.cpp index 6085481..91827e7 100644 --- a/x11/ipc/client/ocopclient.cpp +++ b/x11/ipc/client/ocopclient.cpp | |||
@@ -54,106 +54,114 @@ void OCOPClient::init( const QCString& ) { | |||
54 | int length = sizeof(unix_adr.sun_family) + strlen(unix_adr.sun_path); | 54 | int length = sizeof(unix_adr.sun_family) + strlen(unix_adr.sun_path); |
55 | 55 | ||
56 | if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) { | 56 | if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) { |
57 | qWarning("could not connect %d", errno ); | 57 | qWarning("could not connect %d", errno ); |
58 | close( m_socket ); | 58 | close( m_socket ); |
59 | if ( m_tries < 8 ) | 59 | if ( m_tries < 8 ) |
60 | QTimer::singleShot(400, this, SLOT(init() ) ); | 60 | QTimer::singleShot(400, this, SLOT(init() ) ); |
61 | return; | 61 | return; |
62 | } | 62 | } |
63 | m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this ); | 63 | m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this ); |
64 | connect( m_notify, SIGNAL(activated(int) ), | 64 | connect( m_notify, SIGNAL(activated(int) ), |
65 | this, SLOT(newData() ) ); | 65 | this, SLOT(newData() ) ); |
66 | } | 66 | } |
67 | /** | 67 | /** |
68 | * new data | 68 | * new data |
69 | * read the header check magic number | 69 | * read the header check magic number |
70 | * and maybe read body | 70 | * and maybe read body |
71 | */ | 71 | */ |
72 | void OCOPClient::newData() { | 72 | void OCOPClient::newData() { |
73 | OCOPPacket pack = packet(); | 73 | OCOPPacket pack = packet(); |
74 | if ( pack.channel().isEmpty() ) | 74 | if ( pack.channel().isEmpty() ) |
75 | return; | 75 | return; |
76 | 76 | ||
77 | switch( pack.type() ) { | 77 | switch( pack.type() ) { |
78 | case OCOPPacket::Register: | 78 | case OCOPPacket::Register: |
79 | case OCOPPacket::Unregister: | 79 | case OCOPPacket::Unregister: |
80 | case OCOPPacket::Method: | 80 | case OCOPPacket::Method: |
81 | case OCOPPacket::RegisterChannel: | 81 | case OCOPPacket::RegisterChannel: |
82 | case OCOPPacket::UnregisterChannel: | 82 | case OCOPPacket::UnregisterChannel: |
83 | case OCOPPacket::Return: | 83 | case OCOPPacket::Return: |
84 | case OCOPPacket::Signal: | 84 | case OCOPPacket::Signal: |
85 | /* is Registered should be handled sync */ | 85 | /* is Registered should be handled sync */ |
86 | case OCOPPacket::IsRegistered: | 86 | case OCOPPacket::IsRegistered: |
87 | break; | 87 | break; |
88 | /* emit the signal */ | 88 | /* emit the signal */ |
89 | case OCOPPacket::Call: | 89 | case OCOPPacket::Call: |
90 | emit called( pack.channel(), pack.header(), pack.content() ); | 90 | emit called( pack.channel(), pack.header(), pack.content() ); |
91 | break; | 91 | break; |
92 | } | 92 | } |
93 | } | 93 | } |
94 | OCOPPacket OCOPClient::packet() const{ | 94 | OCOPPacket OCOPClient::packet() const{ |
95 | QCString chan; | 95 | QCString chan; |
96 | QCString func; | 96 | QCString func; |
97 | QByteArray ar; | 97 | QByteArray ar; |
98 | OCOPHead head; | 98 | OCOPHead head; |
99 | memset(&head, 0, sizeof(head) ); | 99 | memset(&head, 0, sizeof(head) ); |
100 | read(m_socket, &head, sizeof(head) ); | 100 | read(m_socket, &head, sizeof(head) ); |
101 | if ( head.magic == 47 ) { | 101 | if ( head.magic == 47 ) { |
102 | qWarning("Client:Magic Match"); | ||
103 | chan = QCString( head.chlen+1); | ||
104 | func = QCString( head.funclen+1 ); | ||
105 | ar = QByteArray( head.datalen); | ||
102 | read(m_socket, chan.data(), head.chlen ); | 106 | read(m_socket, chan.data(), head.chlen ); |
103 | read(m_socket, func.data(), head.funclen ); | 107 | read(m_socket, func.data(), head.funclen ); |
104 | read(m_socket, ar.data(), head.datalen ); | 108 | read(m_socket, ar.data(), head.datalen ); |
109 | qWarning("Client:%d %s",head.chlen,chan.data() ); | ||
105 | } | 110 | } |
106 | OCOPPacket pack(head.type, chan, func, ar ); | 111 | OCOPPacket pack(head.type, chan, func, ar ); |
107 | return pack; | 112 | return pack; |
108 | } | 113 | } |
109 | /* | 114 | /* |
110 | * we've blocking IO here on these sockets | 115 | * we've blocking IO here on these sockets |
111 | * so we send and go on read | 116 | * so we send and go on read |
112 | * this will be blocked | 117 | * this will be blocked |
113 | */ | 118 | */ |
114 | bool OCOPClient::isRegistered( const QCString& chan ) const{ | 119 | bool OCOPClient::isRegistered( const QCString& chan ) const{ |
120 | qWarning("OCopClient::isRegistered %s", chan.data() ); | ||
115 | /* should I disconnect the socket notfier? */ | 121 | /* should I disconnect the socket notfier? */ |
116 | OCOPPacket packe(OCOPPacket::IsRegistered, chan ); | 122 | OCOPPacket packe(OCOPPacket::IsRegistered, chan ); |
117 | OCOPHead head = packe.head(); | 123 | OCOPHead head = packe.head(); |
118 | write(m_socket, &head, sizeof(head) ); | 124 | write(m_socket, &head, sizeof(head) ); |
119 | write(m_socket, chan.data(), chan.size() ); | 125 | write(m_socket, chan.data(), chan.size() ); |
120 | /* block */ | 126 | /* block */ |
121 | OCOPPacket pack = packet(); | 127 | OCOPPacket pack = packet(); |
128 | qWarning("unblock %s %s", pack.channel().data(), chan.data() ); | ||
122 | 129 | ||
123 | /* connect here again */ | 130 | /* connect here again */ |
124 | if ( pack.channel() == chan ) { | 131 | if ( pack.channel() == chan ) { |
125 | QCString func = pack.header(); | 132 | QCString func = pack.header(); |
126 | if (func[0] == 1 ) | 133 | if (func[0] == 1 ) |
127 | return true; | 134 | return true; |
128 | } | 135 | } |
129 | 136 | ||
130 | return false; | 137 | return false; |
131 | }; | 138 | }; |
132 | void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) { | 139 | void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) { |
140 | qWarning("ClientSending %s %s", chan.data(), fu.data() ); | ||
133 | OCOPPacket pack(OCOPPacket::Call, chan, fu, arr ); | 141 | OCOPPacket pack(OCOPPacket::Call, chan, fu, arr ); |
134 | call( pack ); | 142 | call( pack ); |
135 | } | 143 | } |
136 | void OCOPClient::addChannel(const QCString& channel) { | 144 | void OCOPClient::addChannel(const QCString& channel) { |
137 | OCOPPacket pack(OCOPPacket::RegisterChannel, channel ); | 145 | OCOPPacket pack(OCOPPacket::RegisterChannel, channel ); |
138 | call( pack ); | 146 | call( pack ); |
139 | } | 147 | } |
140 | void OCOPClient::delChannel(const QCString& chan ) { | 148 | void OCOPClient::delChannel(const QCString& chan ) { |
141 | OCOPPacket pack(OCOPPacket::UnregisterChannel, chan ); | 149 | OCOPPacket pack(OCOPPacket::UnregisterChannel, chan ); |
142 | call( pack ); | 150 | call( pack ); |
143 | } | 151 | } |
144 | void OCOPClient::call( const OCOPPacket& pack ) { | 152 | void OCOPClient::call( const OCOPPacket& pack ) { |
145 | OCOPHead head = pack.head(); | 153 | OCOPHead head = pack.head(); |
146 | write(m_socket, &head, sizeof(head) ); | 154 | write(m_socket, &head, sizeof(head) ); |
147 | write(m_socket, pack.channel().data(), pack.channel().size() ); | 155 | write(m_socket, pack.channel().data(), pack.channel().size() ); |
148 | write(m_socket, pack.header().data(), pack.header().size() ); | 156 | write(m_socket, pack.header().data(), pack.header().size() ); |
149 | write(m_socket, pack.content().data(), pack.content().size() ); | 157 | write(m_socket, pack.content().data(), pack.content().size() ); |
150 | } | 158 | } |
151 | void OCOPClient::startUP() { | 159 | void OCOPClient::startUP() { |
152 | qWarning("Start me up"); | 160 | qWarning("Start me up"); |
153 | pid_t pi = fork(); | 161 | pid_t pi = fork(); |
154 | if ( pi == 0 ) { | 162 | if ( pi == 0 ) { |
155 | setsid(); | 163 | setsid(); |
156 | execlp("ocopserver", "ocopserver", NULL ); | 164 | execlp("ocopserver", "ocopserver", NULL ); |
157 | _exit(1); | 165 | _exit(1); |
158 | } | 166 | } |
159 | } | 167 | } |