[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: [PATCH] (Please review) k_dcop_signals patch
From: Alexander Kellett <kelletta () eidetica ! com>
Date: 2001-10-30 15:16:54
[Download RAW message or body]
On Tue, Oct 30, 2001 at 01:46:58PM +0100, Alexander Kellett wrote:
> Here's a cleaned up (removed the excluseSelf stuff) patch to add a
> easier way to call dcop signals.
Doh. One file in the diff is an old version.
Here's a re-diff.
mvg,
Alex
--
Eidetica kelletta@eidetica.com
Kruislaan 400 tel +31 20 888 4090 fax 4001
NL 1098 SM Amsterdam Home machine: myp.ath.cx
http://www.eidetica.com/ Alexander Kellett (Lypanov)
vim: tw=70 cindent!
["k_dcop_signals.patch" (text/plain)]
Index: dcopobject.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopobject.h,v
retrieving revision 1.37
diff -u -r1.37 dcopobject.h
--- dcopobject.h 2001/10/26 23:31:11 1.37
+++ dcopobject.h 2001/10/30 15:11:36
@@ -42,6 +42,7 @@
QCStringList interfaces(); \
private:
+#define k_dcop_signals public
#define k_dcop public
#define ASYNC void
Index: dcopsignals.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopsignals.cpp,v
retrieving revision 1.7
diff -u -r1.7 dcopsignals.cpp
--- dcopsignals.cpp 2001/09/12 14:13:18 1.7
+++ dcopsignals.cpp 2001/10/30 15:11:36
@@ -32,7 +32,7 @@
/**
* Client "conn" emits the signal "fun" with "data" as arguments.
*
- * If "excludeSelf" is true, signal is never send to "conn" itself.
+ * If "excludeSelf" is true, signal is never sent to "conn" itself.
*/
void
DCOPSignals::emitSignal( DCOPConnection *conn, const QCString &_fun, const \
QByteArray &data, bool excludeSelf)
Index: dcopidl/dcopidl_test.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl/dcopidl_test.h,v
retrieving revision 1.12
diff -u -r1.12 dcopidl_test.h
--- dcopidl/dcopidl_test.h 2001/10/23 08:55:54 1.12
+++ dcopidl/dcopidl_test.h 2001/10/30 15:11:36
@@ -45,7 +45,11 @@
virtual int getNumPages();
virtual DCOPRef getPage( int num );
int getPageOfObj( int obj );
+ void setCell( const int& point = QString::null );
void setCell( const int& point = 3 );
+
+k_dcop_signals:
+ static void blah_signal();
QValueList<DCOPRef> getWindows();
private:
Index: dcopidl/scanner.ll
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl/scanner.ll,v
retrieving revision 1.26
diff -u -r1.26 scanner.ll
--- dcopidl/scanner.ll 2001/10/04 12:27:16 1.26
+++ dcopidl/scanner.ll 2001/10/30 15:11:37
@@ -231,6 +231,7 @@
TRUE return T_TRUE;
FALSE return T_FALSE;
"k_dcop" return T_DCOP_AREA;
+"k_dcop_signals" return T_DCOP_SIGNAL_AREA;
typedef return T_TYPEDEF;
K_DCOP return T_DCOP;
Q_OBJECT ;
Index: dcopidl/yacc.yy
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl/yacc.yy,v
retrieving revision 1.44
diff -u -r1.44 yacc.yy
--- dcopidl/yacc.yy 2001/10/28 18:09:39 1.44
+++ dcopidl/yacc.yy 2001/10/30 15:11:37
@@ -39,6 +39,7 @@
extern int function_mode;
static int dcop_area = 0;
+static int dcop_signal_area = 0;
static QString in_namespace( "" );
@@ -116,6 +117,7 @@
%token T_CHAR
%token T_DCOP
%token T_DCOP_AREA
+%token T_DCOP_SIGNAL_AREA
%token T_SIGNED
%token T_UNSIGNED
%token T_LONG
@@ -243,10 +245,12 @@
: nodcop_area sigslot T_COLON
{
dcop_area = 0;
+ dcop_signal_area = 0;
}
| sigslot T_COLON
{
dcop_area = 0;
+ dcop_signal_area = 0;
}
dcop_area_begin
@@ -255,6 +259,12 @@
dcop_area = 1;
}
+dcop_signal_area_begin
+ : T_DCOP_SIGNAL_AREA T_COLON
+ {
+ dcop_signal_area = 1;
+ }
+
Identifier
: T_IDENTIFIER {
$$ = $1;
@@ -333,6 +343,10 @@
{
$$ = new QString( *($1) + *($2) );
}
+ | dcop_signal_area_begin body
+ {
+ $$ = $2;
+ }
| enum body
{
$$ = $2;
@@ -624,25 +638,31 @@
function_header
: type Identifier T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS const_qualifier
{
- if (dcop_area) {
+ if (dcop_area || dcop_signal_area) {
QString* tmp = 0;
- if ( $6 )
- tmp = new QString(
- " <FUNC qual=\"const\">\n"
- " %2\n"
- " <NAME>%1</NAME>"
- "%3\n"
- " </FUNC>\n");
- else
- tmp = new QString(
- " <FUNC>\n"
- " %2\n"
- " <NAME>%1</NAME>"
- "%3\n"
- " </FUNC>\n");
+ tmp = new QString(
+ " <%4>\n"
+ " %2\n"
+ " <NAME>%1</NAME>"
+ "%3\n"
+ " </%5>\n");
*tmp = tmp->arg( *($2) );
*tmp = tmp->arg( *($1) );
- *tmp = tmp->arg( *($4) );
+ if ($6) {
+ *tmp = tmp->arg( *($4) + " qual=\"const\">" );
+ } else {
+ *tmp = tmp->arg( *($4) );
+ }
+
+ QString tagname = "";
+ QString attr = "";
+ if (dcop_signal_area) {
+ tagname = "SIGNAL";
+ } else {
+ tagname = "FUNC";
+ }
+ *tmp = tmp->arg( QString("%1%2").arg(tagname).arg(attr) );
+ *tmp = tmp->arg( QString("%1").arg(tagname) );
$$ = tmp;
} else
$$ = new QString("");
@@ -703,10 +723,15 @@
}
| T_STATIC function_header function_body
{
- if (dcop_area)
- yyerror("static is not allowed in dcop area!");
- $$ = new QString();
- }
+ if (dcop_area) {
+ if (dcop_signal_area)
+ $$ = $2;
+ else
+ yyerror("static is not allowed in dcop area!");
+ } else {
+ $$ = new QString();
+ }
+ }
function_begin : T_LEFT_CURLY_BRACKET
{
Index: dcopidl2cpp/main.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/main.cpp,v
retrieving revision 1.17
diff -u -r1.17 main.cpp
--- dcopidl2cpp/main.cpp 2001/08/31 07:16:18 1.17
+++ dcopidl2cpp/main.cpp 2001/10/30 15:11:37
@@ -106,12 +106,14 @@
generateSkel( idl, base + "_skel." + suffix, de );
if ( generate_stub ) {
- QString header = base + "_stub.h";
- generateStub( idl, header, de );
+ QString header = base;
+ generateStub( idl, header + "_stub.h", de, false );
+ generateStub( idl, header + "_signals.h", de, true );
pos = header.findRev('/');
if ( pos != -1 )
header = header.mid( pos+1 );
- generateStubImpl( idl, header, base + "_stub." + suffix, de );
+ generateStubImpl( idl, header + "_stub.h", base+".h", base + "_stub." + suffix, de, \
false ); + generateStubImpl( idl, header + "_signals.h", base+".h", base + \
"_signals." + suffix, de, true ); }
return 0;
Index: dcopidl2cpp/main.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/main.h,v
retrieving revision 1.2
diff -u -r1.2 main.h
--- dcopidl2cpp/main.h 2000/07/16 01:43:48 1.2
+++ dcopidl2cpp/main.h 2001/10/30 15:11:37
@@ -31,10 +31,10 @@
/**
* Writes the stubs header
*/
-void generateStub( const QString& idl, const QString& filename, QDomElement de );
+void generateStub( const QString& idl, const QString& filename, QDomElement de, bool \
signals );
/**
* Writes the stub implementation
*/
-void generateStubImpl( const QString& idl, const QString& header, const QString& \
filename, QDomElement de ); +void generateStubImpl( const QString& idl, const \
QString& header, const QString& headerBase, const QString& filename, QDomElement de, \
bool signals );
Index: dcopidl2cpp/stub.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/stub.cpp,v
retrieving revision 1.6
diff -u -r1.6 stub.cpp
--- dcopidl2cpp/stub.cpp 2001/10/10 21:27:42 1.6
+++ dcopidl2cpp/stub.cpp 2001/10/30 15:11:37
@@ -36,7 +36,7 @@
/**
* Writes the stubs header
*/
-void generateStub( const QString& idl, const QString& filename, QDomElement de )
+void generateStub( const QString& idl, const QString& filename, QDomElement de, bool \
signals ) {
QFile stub( filename );
if ( !stub.open( IO_WriteOnly ) )
@@ -58,8 +58,9 @@
if ( pos != -1 )
ifdefstring = ifdefstring.left( pos );
- str << "#ifndef __" << ifdefstring << "_STUB__" << endl;
- str << "#define __" << ifdefstring << "_STUB__" << endl << endl;
+ QString ifdefsuffix = signals ? "_SIGNALS__" : "_STUB__";
+ str << "#ifndef __" << ifdefstring << ifdefsuffix << endl;
+ str << "#define __" << ifdefstring << ifdefsuffix << endl << endl;
str << "#include <dcopstub.h>" << endl;
@@ -84,7 +85,8 @@
QDomElement n = e.firstChild().toElement();
Q_ASSERT( n.tagName() == "NAME" );
- QString className = n.firstChild().toText().data() + "_stub";
+ QString className = n.firstChild().toText().data()
+ + ( signals ? "_signals" : "_stub" );
// find dcop parent ( rightmost super class )
QString DCOPParent;
@@ -116,27 +118,32 @@
str << "class " << className;
// Parent : inherited interface stub or dcopstub
- if ( !DCOPParent.isEmpty() && DCOPParent != "DCOPObject" ) {
- str << " : ";
- str << "virtual public " << DCOPParent << "_stub";
- } else {
- str << " : virtual public DCOPStub";
- }
+ if (!signals) {
+ if ( !DCOPParent.isEmpty() && DCOPParent != "DCOPObject" ) {
+ str << " : ";
+ str << "virtual public " << DCOPParent << "_stub";
+ } else {
+ str << " : virtual public DCOPStub";
+ }
+ }
str << endl;
str << "{" << endl;
str << "public:" << endl;
- // Constructors
- str << " " << className << "( const QCString& app, const QCString& id );" << \
endl;
- str << " " << className << "( DCOPClient* client, const QCString& app, const \
QCString& id );" << endl; + if (!signals) {
+ // Constructors
+ str << " " << className << "( const QCString& app, const QCString& \
id );" << endl; + str << " " << className << "( DCOPClient* client, \
const QCString& app, const QCString& id );" << endl; + }
s = e.firstChild().toElement();
for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
- if ( s.tagName() == "FUNC" ) {
+ if ( (!signals && s.tagName() == "FUNC")
+ || (signals && s.tagName() == "SIGNAL") ) {
QDomElement r = s.firstChild().toElement();
Q_ASSERT( r.tagName() == "TYPE" );
- str << " virtual ";
+ str << (signals ? " static " : " virtual ");
if ( r.hasAttribute( "qleft" ) )
str << r.attribute("qleft") << " ";
str << r.firstChild().toText().data();
Index: dcopidl2cpp/stubimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/stubimpl.cpp,v
retrieving revision 1.13
diff -u -r1.13 stubimpl.cpp
--- dcopidl2cpp/stubimpl.cpp 2001/08/31 07:16:18 1.13
+++ dcopidl2cpp/stubimpl.cpp 2001/10/30 15:11:37
@@ -56,7 +56,7 @@
/**
* Writes the stub implementation
*/
-void generateStubImpl( const QString& idl, const QString& header, const QString& \
filename, QDomElement de ) +void generateStubImpl( const QString& idl, const QString& \
header, const QString& headerBase, const QString& filename, QDomElement de, bool \
signals ) {
QFile impl( filename );
if ( !impl.open( IO_WriteOnly ) )
@@ -73,16 +73,22 @@
str << "*****************************************************************************/" \
<< endl; str << endl;
- str << "#include \"" << header << "\"" << endl;
+ str << "#include \"" << header << "\"" << endl;
str << "#include <dcopclient.h>" << endl << endl;
- str << "#include <kdatastream.h>" << endl << endl;
+ str << "#include <kdatastream.h>" << endl;
+ if (signals) {
+ str << "#include <kapp.h>" << endl << endl;
+ }
+
QDomElement e = de.firstChild().toElement();
for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
if ( e.tagName() == "CLASS" ) {
QDomElement n = e.firstChild().toElement();
Q_ASSERT( n.tagName() == "NAME" );
- QString className = n.firstChild().toText().data() + "_stub";
+ QString classNameBase = n.firstChild().toText().data();
+ QString className_stub = classNameBase + "_stub";
+ QString className_signals = classNameBase + "_signals";
// find dcop parent ( rightmost super class )
QString DCOPParent;
@@ -92,16 +98,16 @@
DCOPParent = s.firstChild().toText().data();
}
- QString classNameFull = className; // class name with possible \
namespaces prepended + QString classNameFull = className_stub; // class \
name with possible namespaces prepended
// namespaces will be removed from \
className now int namespace_count = 0;
- QString namespace_tmp = className;
+ QString namespace_tmp = className_stub;
str << endl;
for(;;) {
int pos = namespace_tmp.find( "::" );
if( pos < 0 )
{
- className = namespace_tmp;
+ className_stub = namespace_tmp;
break;
}
str << "namespace " << namespace_tmp.left( pos ) << " {" << endl;
@@ -110,33 +116,37 @@
}
str << endl;
-
- // Write constructors
- str << className << "::" << className << "( const QCString& app, const \
QCString& obj )" << endl;
- str << " : ";
-
- if ( DCOPParent.isEmpty() || DCOPParent == "DCOPObject" )
- str << "DCOPStub( app, obj )" << endl;
- else
- str << DCOPParent << "( app, obj )" << endl;
- str << "{" << endl;
- str << "}" << endl << endl;
+ if (!signals) {
+ // Write constructors
+ str << className_stub << "::" << className_stub << "( const QCString& \
app, const QCString& obj )" << endl; + str << " : ";
+
+ if ( DCOPParent.isEmpty() || DCOPParent == "DCOPObject" )
+ str << "DCOPStub( app, obj )" << endl;
+ else
+ str << DCOPParent << "( app, obj )" << endl;
+
+ str << "{" << endl;
+ str << "}" << endl << endl;
+
+ str << className_stub << "::" << className_stub << "( DCOPClient* \
client, const QCString& app, const QCString& obj )" << endl; + str << " \
: "; +
+ if ( DCOPParent.isEmpty() || DCOPParent == "DCOPObject" )
+ str << "DCOPStub( client, app, obj )" << endl;
+ else
+ str << DCOPParent << "( client, app, obj )" << endl;
- str << className << "::" << className << "( DCOPClient* client, const QCString& \
app, const QCString& obj )" << endl;
- str << " : ";
-
- if ( DCOPParent.isEmpty() || DCOPParent == "DCOPObject" )
- str << "DCOPStub( client, app, obj )" << endl;
- else
- str << DCOPParent << "( client, app, obj )" << endl;
+ str << "{" << endl;
+ str << "}" << endl << endl;
+ }
- str << "{" << endl;
- str << "}" << endl << endl;
// Write marshalling code
s = e.firstChild().toElement();
for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
- if ( s.tagName() == "FUNC" ) {
+ if ( (!signals && s.tagName() == "FUNC")
+ || (signals && s.tagName() == "SIGNAL") ) {
QDomElement r = s.firstChild().toElement();
Q_ASSERT( r.tagName() == "TYPE" );
QString result = r.firstChild().toText().data();
@@ -154,7 +164,7 @@
r = r.nextSibling().toElement();
Q_ASSERT ( r.tagName() == "NAME" );
QString funcName = r.firstChild().toText().data();
- str << className << "::" << funcName << "(";
+ str << ( signals ? className_signals : className_stub ) << "::" << funcName << \
"(";
QStringList args;
QStringList argtypes;
@@ -201,11 +211,17 @@
}
funcName += ")";
- if ( async ) {
- str << " if ( !dcopClient() ) {"<< endl;
- str << "\tsetStatus( CallFailed );" << endl;
- str << "\treturn;" << endl;
- str << " }" << endl;
+ if ( async || signals ) {
+
+ if ( signals && (result != "void") )
+ qFatal("Sorry DCOP signals can not return values.");
+
+ if (!signals) {
+ str << " if ( !dcopClient() ) {"<< endl;
+ str << "\tsetStatus( CallFailed );" << endl;
+ str << "\treturn;" << endl;
+ str << " }" << endl;
+ }
str << " QByteArray data;" << endl;
if ( !args.isEmpty() ) {
@@ -214,10 +230,16 @@
str << " arg << " << *args_count << ";" << endl;
}
}
- str << " dcopClient()->send( app(), obj(), \"" << funcName << "\", data );" << \
endl;
- str << " setStatus( CallSucceeded );" << endl;
+
+ if (signals) {
+ str << " kapp->dcopClient()->emitDCOPSignal( \"" << \
funcName << "\", data, " << " );" << endl; + } else {
+ str << " dcopClient()->send( app(), obj(), \"" << \
funcName << "\", data );" << endl; + str << " \
setStatus( CallSucceeded );" << endl; + }
+
} else {
-
+
if ( result != "void" ) {
str << " " << result << " result";
if (isIntType( result ))
@@ -255,9 +277,9 @@
} else {
str << "\tsetStatus( CallSucceeded );" << endl;
}
- str << " } else { " << endl;
- str << "\tcallFailed();" << endl;
- str << " }" << endl;
+ str << " } else { " << endl;
+ str << "\tcallFailed();" << endl;
+ str << " }" << endl;
if ( result != "void" )
str << " return result;" << endl;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic