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

dcop

  • dcop
  • dcopidl2cpp
stub.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
36/*
37 * Writes the stubs header
38 */
39void generateStub( const TQString& idl, const TQString& filename, TQDomElement de)
40{
41 TQFile stub( filename );
42 if ( !stub.open( IO_WriteOnly ) )
43 tqFatal("Could not write to %s", filename.local8Bit().data() );
44
45 TQTextStream str( &stub );
46
47 str << "/****************************************************************************" << endl;
48 str << "**" << endl;
49 str << "** DCOP Stub Definition created by dcopidl2cpp from " << idl << endl;
50 str << "**" << endl;
51 str << "** WARNING! All changes made in this file will be lost!" << endl;
52 str << "**" << endl;
53 str << "*****************************************************************************/" << endl;
54 str << endl;
55
56 TQString ifdefstring = idl.upper();
57 int pos = idl.findRev( '.' );
58 if ( pos != -1 )
59 ifdefstring = ifdefstring.left( pos );
60
61 TQString ifdefsuffix = "_STUB__";
62 str << "#ifndef __" << ifdefstring << ifdefsuffix << endl;
63 str << "#define __" << ifdefstring << ifdefsuffix << endl << endl;
64
65 str << "#include <dcopstub.h>" << endl;
66
67 TQStringList includeslist, all_includes;
68 TQDomElement e = de.firstChild().toElement();
69 for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
70 if ( e.tagName() == "INCLUDE" ) {
71 // dcopidl lists the includes in reversed order because of the used yacc/bison gramatic
72 // so let's reverse it back, as the order may be important
73 includeslist.prepend( e.firstChild().toText().data());
74 continue;
75 }
76 if( !includeslist.empty()) {
77 for( TQStringList::ConstIterator it = includeslist.begin();
78 it != includeslist.end();
79 ++it ) {
80 str << "#include <" << ( *it ) << ">" << endl;
81 all_includes.append( *it );
82 }
83 includeslist.clear();
84 }
85 if ( e.tagName() != "CLASS" )
86 continue;
87
88 str << endl;
89
90 TQDomElement n = e.firstChild().toElement();
91 Q_ASSERT( n.tagName() == "NAME" );
92 TQString className = n.firstChild().toText().data() + ( "_stub" );
93
94 //add link scope, if available
95 n = n.nextSibling().toElement();
96 TQString linkScope;
97 if (n.tagName()=="LINK_SCOPE") {
98 linkScope = n.firstChild().toText().data() + " ";
99 n = n.nextSibling().toElement();
100 }
101
102 // find dcop parent ( rightmost super class )
103 TQString DCOPParent;
104 for( ; !n.isNull(); n = n.nextSibling().toElement() ) {
105 if ( n.tagName() == "SUPER" )
106 DCOPParent = n.firstChild().toText().data();
107 }
108
109 if( DCOPParent != "DCOPObject" ) { // we need to include the .h file for the base stub
110 if( all_includes.contains( DCOPParent + ".h" ))
111 str << "#include <" << DCOPParent << "_stub.h>" << endl;
112 else if( all_includes.contains( DCOPParent.lower() + ".h" ))
113 str << "#include <" << DCOPParent.lower() << "_stub.h>" << endl;
114 else {// damn ... let's assume it's the last include
115 TQString stub_h = all_includes.last();
116 unsigned int pos = stub_h.find( ".h" );
117 if( pos > 0 ) {
118 stub_h = stub_h.remove( pos, 100000 );
119 str << "#include <" << stub_h << "_stub.h>" << endl;
120 }
121 else
122 str << "#include <" << stub_h << ">" << endl;
123 }
124 }
125
126 TQString classNameFull = className; // class name with possible namespaces prepended
127 // namespaces will be removed from className now
128 int namespace_count = 0;
129 TQString namespace_tmp = className;
130 for(;;) {
131 int pos = namespace_tmp.find( "::" );
132 if( pos < 0 ) {
133 className = namespace_tmp;
134 break;
135 }
136 str << "namespace " << namespace_tmp.left( pos ) << " {" << endl;
137 ++namespace_count;
138 namespace_tmp = namespace_tmp.mid( pos + 2 );
139 }
140
141 str << endl;
142
143 // Stub class definition
144 str << "class " << linkScope << className;
145
146 // Parent : inherited interface stub or dcopstub
147 if ( !DCOPParent.isEmpty() && DCOPParent != "DCOPObject" ) {
148 str << " : ";
149 str << "virtual public " << DCOPParent << "_stub";
150 } else {
151 str << " : virtual public DCOPStub";
152 }
153
154 str << endl;
155 str << "{" << endl;
156 str << "public:" << endl;
157
158 // Constructors
159 str << " " << className << "( const TQCString& app, const TQCString& id );" << endl;
160 str << " " << className << "( DCOPClient* client, const TQCString& app, const TQCString& id );" << endl;
161 str << " explicit " << className << "( const DCOPRef& ref );" << endl;
162
163 n = e.firstChild().toElement();
164 for( ; !n.isNull(); n = n.nextSibling().toElement() ) {
165 if (n.tagName() != "FUNC")
166 continue;
167 TQDomElement r = n.firstChild().toElement();
168 str << " virtual "; // KDE4 - I really don't think these need to be virtual
169 writeType( str, r );
170
171 r = r.nextSibling().toElement();
172 Q_ASSERT ( r.tagName() == "NAME" );
173 str << r.firstChild().toText().data() << "(";
174
175 bool first = true;
176 r = r.nextSibling().toElement();
177 for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
178 if ( !first )
179 str << ", ";
180 else
181 str << " ";
182 first = false;
183 Q_ASSERT( r.tagName() == "ARG" );
184 TQDomElement a = r.firstChild().toElement();
185 writeType( str, a );
186 a = a.nextSibling().toElement();
187 if ( a.tagName() == "NAME" )
188 str << a.firstChild().toText().data();
189 }
190 if ( !first )
191 str << " ";
192 str << ")";
193
194 //const methods stubs can't compile, they need to call setStatus().
195 //if ( n.hasAttribute("qual") )
196 // str << " " << n.attribute("qual");
197 str << ";" << endl;
198 }
199
200 // needed for inherited stubs
201 str << "protected:" << endl;
202 str << " " << className << "() : DCOPStub( never_use ) {}" << endl;
203
204 str << "};" << endl;
205 str << endl;
206
207 for(; namespace_count > 0; --namespace_count )
208 str << "} // namespace" << endl;
209 str << endl;
210 }
211
212 str << "#endif" << endl;
213 stub.close();
214}
215
216// :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.