25 #include <tqtextstream.h>
27 #include <tqstringlist.h>
36 static bool isIntType(
const TQString& t )
39 || (t ==
"signed int")
40 || (t ==
"unsigned int")
43 || (t ==
"signed short int")
44 || (t ==
"signed short")
47 || (t ==
"unsigned short int")
48 || (t ==
"unsigned short")
51 || (t ==
"signed long int")
53 || (t ==
"signed long")
54 || (t ==
"unsigned long int")
55 || (t ==
"unsigned long")
58 || (t ==
"signed char")
59 || (t ==
"unsigned char"));
65 void generateStubImpl(
const TQString& idl,
const TQString& header,
const TQString& ,
const TQString& filename, TQDomElement de )
67 TQFile impl( filename );
68 if ( !impl.open( IO_WriteOnly ) )
69 tqFatal(
"Could not write to %s", filename.latin1() );
71 TQTextStream str( &impl );
73 str <<
"/****************************************************************************" <<
endl;
75 str <<
"** DCOP Stub Implementation created by dcopidl2cpp from " << idl <<
endl;
77 str <<
"** WARNING! All changes made in this file will be lost!" <<
endl;
79 str <<
"*****************************************************************************/" <<
endl;
82 str <<
"#include \"" << header <<
"\"" <<
endl;
83 str <<
"#include <dcopclient.h>" <<
endl <<
endl;
84 str <<
"#include <kdatastream.h>" <<
endl;
86 TQDomElement e = de.firstChild().toElement();
87 for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
88 if ( e.tagName() !=
"CLASS" )
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";
95 TQString classNameFull = className_stub;
97 int namespace_count = 0;
98 TQString namespace_tmp = className_stub;
101 int pos = namespace_tmp.find(
"::" );
103 className_stub = namespace_tmp;
106 str <<
"namespace " << namespace_tmp.left( pos ) <<
" {" <<
endl;
108 namespace_tmp = namespace_tmp.mid( pos + 2 );
114 str << className_stub <<
"::" << className_stub <<
"( const TQCString& app, const TQCString& obj )" <<
endl;
119 str <<
"DCOPStub( app, obj )" <<
endl;
124 str << className_stub <<
"::" << className_stub <<
"( DCOPClient* client, const TQCString& app, const TQCString& obj )" <<
endl;
127 str <<
"DCOPStub( client, app, obj )" <<
endl;
132 str << className_stub <<
"::" << className_stub <<
"( const DCOPRef& ref )" <<
endl;
135 str <<
"DCOPStub( ref )" <<
endl;
141 TQDomElement s = e.firstChild().toElement();
142 for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
143 if (s.tagName() !=
"FUNC")
145 TQDomElement r = s.firstChild().toElement();
146 Q_ASSERT( r.tagName() ==
"TYPE" );
147 TQString result = r.firstChild().toText().data();
148 bool async = result ==
"ASYNC";
151 str << result <<
" ";
153 result = writeType( str, r );
155 r = r.nextSibling().toElement();
156 Q_ASSERT ( r.tagName() ==
"NAME" );
157 TQString funcName = r.firstChild().toText().data();
158 str << className_stub <<
"::" << funcName <<
"(";
161 TQStringList argtypes;
163 r = r.nextSibling().toElement();
164 for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
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() ) ) ;
191 for( TQStringList::Iterator it = argtypes.begin(); it != argtypes.end(); ++it ){
201 str <<
" if ( !dcopClient() ) {"<<
endl;
202 str <<
"\tsetStatus( CallFailed );" <<
endl;
203 str <<
"\treturn;" <<
endl;
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;
214 str <<
" dcopClient()->send( app(), obj(), \"" << funcName <<
"\", data );" <<
endl;
215 str <<
" setStatus( CallSucceeded );" <<
endl;
219 if ( result !=
"void" ) {
220 str <<
" " << result <<
" result";
221 if (isIntType( result ))
223 else if (result ==
"float" || result ==
"double")
225 else if ( result ==
"bool" )
231 str <<
" if ( !dcopClient() ) {"<<
endl;
232 str <<
"\tsetStatus( CallFailed );" <<
endl;
233 if ( result !=
"void" )
234 str <<
"\treturn result;" <<
endl;
236 str <<
"\treturn;" <<
endl;
239 str <<
" TQByteArray data, replyData;" <<
endl;
240 str <<
" TQCString replyType;" <<
endl;
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;
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;
259 str <<
"\tsetStatus( CallSucceeded );" <<
endl;
261 str <<
" } else { " <<
endl;
262 str <<
"\tcallFailed();" <<
endl;
264 if ( result !=
"void" )
265 str <<
" return result;" <<
endl;
270 for(; namespace_count > 0; --namespace_count )
271 str <<
"} // namespace" <<
endl;
kndbgstream & endl(kndbgstream &s)