00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include <qdom.h>
00024
#include <qfile.h>
00025
#include <qtextstream.h>
00026
#include <qstring.h>
00027
#include <qstringlist.h>
00028
00029
#include <string.h>
00030
#include <stdlib.h>
00031
#include <stdio.h>
00032
#include <unistd.h>
00033
#include "main.h"
00034
#include "type.h"
00035
00036
00037
00038
00039
void generateStub(
const QString& idl,
const QString& filename,
QDomElement de)
00040 {
00041
QFile stub( filename );
00042
if ( !stub.open( IO_WriteOnly ) )
00043 qFatal(
"Could not write to %s", filename.local8Bit().data() );
00044
00045
QTextStream str( &stub );
00046
00047 str <<
"/****************************************************************************" <<
endl;
00048 str <<
"**" <<
endl;
00049 str <<
"** DCOP Stub Definition created by dcopidl2cpp from " << idl <<
endl;
00050 str <<
"**" <<
endl;
00051 str <<
"** WARNING! All changes made in this file will be lost!" <<
endl;
00052 str <<
"**" <<
endl;
00053 str <<
"*****************************************************************************/" <<
endl;
00054 str <<
endl;
00055
00056
QString ifdefstring = idl.upper();
00057
int pos = idl.findRev(
'.' );
00058
if ( pos != -1 )
00059 ifdefstring = ifdefstring.left( pos );
00060
00061
QString ifdefsuffix =
"_STUB__";
00062 str <<
"#ifndef __" << ifdefstring << ifdefsuffix <<
endl;
00063 str <<
"#define __" << ifdefstring << ifdefsuffix <<
endl <<
endl;
00064
00065 str <<
"#include <dcopstub.h>" <<
endl;
00066
00067
QStringList includeslist, all_includes;
00068
QDomElement e = de.firstChild().toElement();
00069
for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
00070
if ( e.tagName() ==
"INCLUDE" ) {
00071
00072
00073 includeslist.prepend( e.firstChild().toText().data());
00074
continue;
00075 }
00076
if( !includeslist.empty()) {
00077
for( QStringList::ConstIterator it = includeslist.begin();
00078 it != includeslist.end();
00079 ++it ) {
00080 str <<
"#include <" << ( *it ) <<
">" <<
endl;
00081 all_includes.append( *it );
00082 }
00083 includeslist.clear();
00084 }
00085
if ( e.tagName() !=
"CLASS" )
00086
continue;
00087
00088 str <<
endl;
00089
00090
QDomElement n = e.firstChild().toElement();
00091 Q_ASSERT( n.tagName() ==
"NAME" );
00092
QString className = n.firstChild().toText().data() + (
"_stub" );
00093
00094
00095
QString DCOPParent;
00096
QDomElement s = n.nextSibling().toElement();
00097
for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
00098
if ( s.tagName() ==
"SUPER" )
00099 DCOPParent = s.firstChild().toText().data();
00100 }
00101
00102
if( DCOPParent !=
"DCOPObject" ) {
00103
if( all_includes.contains( DCOPParent +
".h" ))
00104 str <<
"#include <" << DCOPParent <<
"_stub.h>" <<
endl;
00105
else if( all_includes.contains( DCOPParent.lower() +
".h" ))
00106 str <<
"#include <" << DCOPParent.lower() <<
"_stub.h>" <<
endl;
00107
else {
00108
QString stub_h = all_includes.last();
00109
unsigned int pos = stub_h.find(
".h" );
00110
if( pos > 0 ) {
00111 stub_h = stub_h.remove( pos, 100000 );
00112 str <<
"#include <" << stub_h <<
"_stub.h>" <<
endl;
00113 }
00114
else
00115 str <<
"#include <" << stub_h <<
">" <<
endl;
00116 }
00117 }
00118
00119
QString classNameFull = className;
00120
00121
int namespace_count = 0;
00122
QString namespace_tmp = className;
00123
for(;;) {
00124
int pos = namespace_tmp.find(
"::" );
00125
if( pos < 0 ) {
00126 className = namespace_tmp;
00127
break;
00128 }
00129 str <<
"namespace " << namespace_tmp.left( pos ) <<
" {" <<
endl;
00130 ++namespace_count;
00131 namespace_tmp = namespace_tmp.mid( pos + 2 );
00132 }
00133
00134 str <<
endl;
00135
00136
00137 str <<
"class " << className;
00138
00139
00140
if ( !DCOPParent.isEmpty() && DCOPParent !=
"DCOPObject" ) {
00141 str <<
" : ";
00142 str <<
"virtual public " << DCOPParent <<
"_stub";
00143 }
else {
00144 str <<
" : virtual public DCOPStub";
00145 }
00146
00147 str <<
endl;
00148 str <<
"{" <<
endl;
00149 str <<
"public:" <<
endl;
00150
00151
00152 str <<
" " << className <<
"( const QCString& app, const QCString& id );" <<
endl;
00153 str <<
" " << className <<
"( DCOPClient* client, const QCString& app, const QCString& id );" <<
endl;
00154 str <<
" explicit " << className <<
"( const DCOPRef& ref );" <<
endl;
00155
00156 s = e.firstChild().toElement();
00157
for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
00158
if (s.tagName() !=
"FUNC")
00159
continue;
00160
QDomElement r = s.firstChild().toElement();
00161 str <<
" virtual ";
00162 writeType( str, r );
00163
00164 r = r.nextSibling().toElement();
00165 Q_ASSERT ( r.tagName() ==
"NAME" );
00166 str << r.firstChild().toText().data() <<
"(";
00167
00168
bool first =
true;
00169 r = r.nextSibling().toElement();
00170
for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
00171
if ( !first )
00172 str <<
", ";
00173
else
00174 str <<
" ";
00175 first =
false;
00176 Q_ASSERT( r.tagName() ==
"ARG" );
00177
QDomElement a = r.firstChild().toElement();
00178 writeType( str, a );
00179 a = a.nextSibling().toElement();
00180
if ( a.tagName() ==
"NAME" )
00181 str << a.firstChild().toText().data();
00182 }
00183
if ( !first )
00184 str <<
" ";
00185 str <<
")";
00186
00187
00188
00189
00190 str <<
";" <<
endl;
00191 }
00192
00193
00194 str <<
"protected:" <<
endl;
00195 str <<
" " << className <<
"() : DCOPStub( never_use ) {};" <<
endl;
00196
00197 str <<
"};" <<
endl;
00198 str <<
endl;
00199
00200
for(; namespace_count > 0; --namespace_count )
00201 str <<
"} // namespace" <<
endl;
00202 str <<
endl;
00203 }
00204
00205 str <<
"#endif" <<
endl;
00206 stub.close();
00207 }
00208
00209