• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • dcop
 

dcop

  • dcop
  • dcopidl2cpp
stubimpl.cpp
1/*****************************************************************
2Copyright (c) 1999 Torben Weis <weis@kde.org>
3Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22******************************************************************/
23#include <tqdom.h>
24#include <tqfile.h>
25#include <tqtextstream.h>
26#include <tqstring.h>
27#include <tqstringlist.h>
28
29#include <string.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <unistd.h>
33#include "main.h"
34#include "type.h"
35
36static bool isIntType( const TQString& t )
37{
38 return ((t == "int")
39 || (t == "signed int")
40 || (t == "unsigned int")
41 || (t == "uint")
42 || (t == "unsigned")
43 || (t == "signed short int")
44 || (t == "signed short")
45 || (t == "short int")
46 || (t == "short")
47 || (t == "unsigned short int")
48 || (t == "unsigned short")
49 || (t == "ushort")
50 || (t == "long int")
51 || (t == "signed long int")
52 || (t == "long")
53 || (t == "signed long")
54 || (t == "unsigned long int")
55 || (t == "unsigned long")
56 || (t == "ulong")
57 || (t == "char")
58 || (t == "signed char")
59 || (t == "unsigned char"));
60}
61
62/*
63 * Writes the stub implementation
64 */
65void generateStubImpl( const TQString& idl, const TQString& header, const TQString& /*headerBase*/, const TQString& filename, TQDomElement de )
66{
67 TQFile impl( filename );
68 if ( !impl.open( IO_WriteOnly ) )
69 tqFatal("Could not write to %s", filename.latin1() );
70
71 TQTextStream str( &impl );
72
73 str << "/****************************************************************************" << endl;
74 str << "**" << endl;
75 str << "** DCOP Stub Implementation created by dcopidl2cpp from " << idl << endl;
76 str << "**" << endl;
77 str << "** WARNING! All changes made in this file will be lost!" << endl;
78 str << "**" << endl;
79 str << "*****************************************************************************/" << endl;
80 str << endl;
81
82 str << "#include \"" << header << "\"" << endl;
83 str << "#include <dcopclient.h>" << endl << endl;
84 str << "#include <kdatastream.h>" << endl;
85
86 TQDomElement e = de.firstChild().toElement();
87 for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
88 if ( e.tagName() != "CLASS" )
89 continue;
90 TQDomElement n = e.firstChild().toElement();
91 Q_ASSERT( n.tagName() == "NAME" );
92 TQString classNameBase = n.firstChild().toText().data();
93 TQString className_stub = classNameBase + "_stub";
94
95 TQString classNameFull = className_stub; // class name with possible namespaces prepended
96 // namespaces will be removed from className now
97 int namespace_count = 0;
98 TQString namespace_tmp = className_stub;
99 str << endl;
100 for(;;) {
101 int pos = namespace_tmp.find( "::" );
102 if( pos < 0 ) {
103 className_stub = namespace_tmp;
104 break;
105 }
106 str << "namespace " << namespace_tmp.left( pos ) << " {" << endl;
107 ++namespace_count;
108 namespace_tmp = namespace_tmp.mid( pos + 2 );
109 }
110
111 str << endl;
112
113 // Write constructors
114 str << className_stub << "::" << className_stub << "( const TQCString& app, const TQCString& obj )" << endl;
115 str << " : ";
116
117 // Always explicitly call DCOPStub constructor, because it's virtual base class.
118 // Calling other ones doesn't matter, as they don't do anything important.
119 str << "DCOPStub( app, obj )" << endl;
120
121 str << "{" << endl;
122 str << "}" << endl << endl;
123
124 str << className_stub << "::" << className_stub << "( DCOPClient* client, const TQCString& app, const TQCString& obj )" << endl;
125 str << " : ";
126
127 str << "DCOPStub( client, app, obj )" << endl;
128
129 str << "{" << endl;
130 str << "}" << endl << endl;
131
132 str << className_stub << "::" << className_stub << "( const DCOPRef& ref )" << endl;
133 str << " : ";
134
135 str << "DCOPStub( ref )" << endl;
136
137 str << "{" << endl;
138 str << "}" << endl << endl;
139
140 // Write marshalling code
141 TQDomElement s = e.firstChild().toElement();
142 for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
143 if (s.tagName() != "FUNC")
144 continue;
145 TQDomElement r = s.firstChild().toElement();
146 Q_ASSERT( r.tagName() == "TYPE" );
147 TQString result = r.firstChild().toText().data();
148 bool async = result == "ASYNC";
149 if ( async) {
150 result = "void";
151 str << result << " ";
152 } else
153 result = writeType( str, r );
154
155 r = r.nextSibling().toElement();
156 Q_ASSERT ( r.tagName() == "NAME" );
157 TQString funcName = r.firstChild().toText().data();
158 str << className_stub << "::" << funcName << "(";
159
160 TQStringList args;
161 TQStringList argtypes;
162 bool first = true;
163 r = r.nextSibling().toElement();
164 for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
165 if ( !first )
166 str << ", ";
167 else
168 str << " ";
169 first = false;
170 Q_ASSERT( r.tagName() == "ARG" );
171 TQDomElement a = r.firstChild().toElement();
172 TQString type = writeType( str, a );
173 argtypes.append( type );
174 args.append( TQString("arg" ) + TQString::number( args.count() ) ) ;
175 str << args.last();
176 }
177 if ( !first )
178 str << " ";
179 str << ")";
180
181 //const methods in a stub can't compile, they need to call setStatus()
182 //if ( s.hasAttribute("qual") )
183 // str << " " << s.attribute("qual");
184 str << endl;
185
186 str << "{" << endl ;
187
188
189 funcName += "(";
190 first = true;
191 for( TQStringList::Iterator it = argtypes.begin(); it != argtypes.end(); ++it ){
192 if ( !first )
193 funcName += ",";
194 first = false;
195 funcName += *it;
196 }
197 funcName += ")";
198
199 if ( async ) {
200
201 str << " if ( !dcopClient() ) {"<< endl;
202 str << "\tsetStatus( CallFailed );" << endl;
203 str << "\treturn;" << endl;
204 str << " }" << endl;
205
206 str << " TQByteArray data;" << endl;
207 if ( !args.isEmpty() ) {
208 str << " TQDataStream arg( data, IO_WriteOnly );" << endl;
209 for( TQStringList::Iterator args_count = args.begin(); args_count != args.end(); ++args_count ){
210 str << " arg << " << *args_count << ";" << endl;
211 }
212 }
213
214 str << " dcopClient()->send( app(), obj(), \"" << funcName << "\", data );" << endl;
215 str << " setStatus( CallSucceeded );" << endl;
216
217 } else {
218
219 if ( result != "void" ) {
220 str << " " << result << " result";
221 if (isIntType( result ))
222 str << " = 0";
223 else if (result == "float" || result == "double")
224 str << " = 0.0";
225 else if ( result == "bool" )
226 str << " = false";
227
228 str << ";" << endl;
229 }
230
231 str << " if ( !dcopClient() ) {"<< endl;
232 str << "\tsetStatus( CallFailed );" << endl;
233 if ( result != "void" )
234 str << "\treturn result;" << endl;
235 else
236 str << "\treturn;" << endl;
237 str << " }" << endl;
238
239 str << " TQByteArray data, replyData;" << endl;
240 str << " TQCString replyType;" << endl;
241
242 if ( !args.isEmpty() ) {
243 str << " TQDataStream arg( data, IO_WriteOnly );" << endl;
244 for( TQStringList::Iterator args_count = args.begin(); args_count != args.end(); ++args_count ){
245 str << " arg << " << *args_count << ";" << endl;
246 }
247 }
248 str << " if ( dcopClient()->call( app(), obj(), \"" << funcName << "\",";
249 str << " data, replyType, replyData ) ) {" << endl;
250 if ( result != "void" ) {
251 str << "\tif ( replyType == \"" << result << "\" ) {" << endl;
252 str << "\t TQDataStream _reply_stream( replyData, IO_ReadOnly );" << endl;
253 str << "\t _reply_stream >> result;" << endl;
254 str << "\t setStatus( CallSucceeded );" << endl;
255 str << "\t} else {" << endl;
256 str << "\t callFailed();" << endl;
257 str << "\t}" << endl;
258 } else {
259 str << "\tsetStatus( CallSucceeded );" << endl;
260 }
261 str << " } else { " << endl;
262 str << "\tcallFailed();" << endl;
263 str << " }" << endl;
264 if ( result != "void" )
265 str << " return result;" << endl;
266 }
267 str << "}" << endl << endl;
268 }
269
270 for(; namespace_count > 0; --namespace_count )
271 str << "} // namespace" << endl;
272 str << endl;
273 }
274 impl.close();
275}
276
277// :set expandtab!<RETURN>:set ts=8<RETURN>:set sts=4<RETURN>:set sw=4<RETURN>
endl
kndbgstream & endl(kndbgstream &s)

dcop

Skip menu "dcop"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

dcop

Skip menu "dcop"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for dcop by doxygen 1.9.4
This website is maintained by Timothy Pearson.