[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [patch] k_dcop_signals
From:       Alexander Kellett <kelletta () eidetica ! com>
Date:       2001-09-27 23:00:52
[Download RAW message or body]

For all who can guess what its for it'll be useful.

   k_dcop_signals:
      static blah();

Any criticisms on the use of static (+public) ?

   #include <myserver.h>

   main() {
      emit MyServer::mySignal()
   }

Does seem awfully nice it me, but malte had "some"
hestitations about it, which just confused me more
unfortunately. Maybe someone could extend this to
be in the form it would be better in?

ciao,
Alex

<faure>
this is to ease the kbookmarklistener stuff that you
suggested. its all "finished" now but i want to clean up 
the patch before sending it.
</faure>

<todo>
clean up dcopobject.h - remove the #define k_dcop_signals
   as its probably only needed in dcopclient.h.
add an "automatic" connectDCOPSignal generator of sorts?
</todo>

-- 
Eidetica                                           kelletta@eidetica.com
Kruislaan 400                               tel +31 20 888 4090 fax 4001
NL 1098 SM Amsterdam
http://www.eidetica.com/                               Alexander Kellett

vim: tw=70 cindent!

["k_dcop_signal.patch" (text/plain)]

Index: dcopclient.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopclient.h,v
retrieving revision 1.59
diff -u -3 -p -r1.59 dcopclient.h
--- dcopclient.h	2001/07/17 21:06:15	1.59
+++ dcopclient.h	2001/09/27 22:54:41
@@ -28,6 +28,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 #include <qvaluelist.h>
 #include <qstring.h>
 
+#define k_dcop_signal public
+
 class DCOPObjectProxy;
 class DCOPClientPrivate;
 class DCOPClientTransaction;
Index: dcopobject.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopobject.h,v
retrieving revision 1.32
diff -u -3 -p -r1.32 dcopobject.h
--- dcopobject.h	2001/01/28 23:37:30	1.32
+++ dcopobject.h	2001/09/27 22:54:41
@@ -42,6 +42,7 @@ public:        \
 private:
 
 #define k_dcop public
+#define k_dcop_signal public
 #define ASYNC void
 
 /**
Index: dcopidl/dcopidl_test.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl/dcopidl_test.h,v
retrieving revision 1.10
diff -u -3 -p -r1.10 dcopidl_test.h
--- dcopidl/dcopidl_test.h	2001/04/11 18:35:17	1.10
+++ dcopidl/dcopidl_test.h	2001/09/27 22:54:41
@@ -44,7 +44,11 @@ k_dcop:
     virtual DCOPRef getPage( int num );
     int getPageOfObj( int obj );
     void setCell( const int& point = 3 );
+    void setCell( const int& point = QString::null );
     QValueList<DCOPRef> getWindows();
+
+k_dcop_signal:
+    static int blah_signal();
 
 private:
     Test3 *doc();
Index: dcopidl/scanner.ll
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl/scanner.ll,v
retrieving revision 1.25
diff -u -3 -p -r1.25 scanner.ll
--- dcopidl/scanner.ll	2001/04/25 18:24:02	1.25
+++ dcopidl/scanner.ll	2001/09/27 22:54:41
@@ -230,6 +230,7 @@ false			return T_FALSE;
 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.40
diff -u -3 -p -r1.40 yacc.yy
--- dcopidl/yacc.yy	2001/05/03 11:59:46	1.40
+++ dcopidl/yacc.yy	2001/09/27 22:54:41
@@ -39,6 +39,7 @@ extern int idl_line_no;
 extern int function_mode;
 
 static int dcop_area = 0;
+static int dcop_signal_area = 0;
 
 static QString in_namespace( "" );
 
@@ -116,6 +117,7 @@ void yyerror( const char *s )
 %token T_CHAR
 %token T_DCOP
 %token T_DCOP_AREA
+%token T_DCOP_SIGNAL_AREA
 %token T_SIGNED
 %token T_UNSIGNED
 %token T_LONG
@@ -242,10 +244,12 @@ nodcop_area_begin
 	: 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
@@ -254,6 +258,12 @@ dcop_area_begin
 	  dcop_area = 1;
 	}
 
+dcop_signal_area_begin
+	: T_DCOP_SIGNAL_AREA T_COLON
+	{
+	  dcop_signal_area = 1;
+	}
+
 Identifier
 	: T_IDENTIFIER {
 	  $$ = $1;
@@ -330,6 +340,10 @@ body
 	  {
 		$$ = $2;
 	  }
+	| dcop_signal_area_begin body
+	  {
+		$$ = $2;
+	  }
 	| dcop_area_begin body
 	  {
 		$$ = $2;
@@ -616,25 +630,32 @@ operator
 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"
+				"    <%4 qual=\"const\">\n"
 				"        %2\n"
 				"        <NAME>%1</NAME>"
 				"%3\n"
-				"     </FUNC>\n");
+				"     </%5>\n");
 		else
 			tmp = new QString(
-				"    <FUNC>\n"
+				"    <%4>\n"
 				"        %2\n"
 				"        <NAME>%1</NAME>"
 				"%3\n"
-				"     </FUNC>\n");
+				"     </%5>\n");
 		*tmp = tmp->arg( *($2) );
 		*tmp = tmp->arg( *($1) );
 		*tmp = tmp->arg( *($4) );
+                if (dcop_signal_area) {
+                   *tmp = tmp->arg( "SIGNAL" );
+                   *tmp = tmp->arg( "SIGNAL" );
+                } else {
+                   *tmp = tmp->arg( "FUNC" );
+                   *tmp = tmp->arg( "FUNC" );
+                }
 		$$ = tmp;
    	     } else
 	        $$ = new QString("");
@@ -665,39 +686,56 @@ init_list
 function
 	: function_header function_body
  	  {
+                if (dcop_signal_area)
+                   yyerror("functions in k_dcop_signal sections must be static.");
 	        $$ = $1;
 	  }
 	| T_VIRTUAL function_header T_EQUAL T_NULL function_body
 	  {
+                if (dcop_signal_area)
+                   yyerror("functions in k_dcop_signal sections must be static.");
 		$$ = $2;
 	  }
 	| T_VIRTUAL function_header function_body
 	  {
+                if (dcop_signal_area)
+                   yyerror("functions in k_dcop_signal sections must be static.");
 		$$ = $2;
 	  }
 	| Identifier T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS function_body
 	  {
+              if (dcop_signal_area)
+                 yyerror("functions in k_dcop_signal sections must be static.");
 	      /* The constructor */
 	      assert(!dcop_area);
               $$ = new QString("");
 	  }
 	| Identifier T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS T_COLON init_list \
function_body  {
+              if (dcop_signal_area)
+                 yyerror("functions in k_dcop_signal sections must be static.");
 	      /* The constructor */
 	      assert(!dcop_area);
               $$ = new QString("");
 	  }
 	| virtual_qualifier T_TILDE Identifier T_LEFT_PARANTHESIS T_RIGHT_PARANTHESIS \
function_body  {
+              if (dcop_signal_area)
+                 yyerror("functions in k_dcop_signal sections must be static.");
 	      /* The destructor */
   	      assert(!dcop_area);
               $$ = new QString("");
 	  }
 	| 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) {
+                    yyerror("static is not allowed in dcop area!");
+                    $$ = new QString();
+                  } else {
+                    $$ = $2;
+                  }
+                }
 	  }
 
 function_begin : T_LEFT_CURLY_BRACKET
Index: dcopidl2cpp/main.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/main.cpp,v
retrieving revision 1.16
diff -u -3 -p -r1.16 main.cpp
--- dcopidl2cpp/main.cpp	2000/07/20 17:06:28	1.16
+++ dcopidl2cpp/main.cpp	2001/09/27 22:54:41
@@ -111,7 +111,7 @@ int main( int argc, char** argv )
 	pos = header.findRev('/');
 	if ( pos != -1 )
 	    header = header.mid( pos+1 );
-	generateStubImpl( idl, header, base + "_stub." + suffix, de );
+	generateStubImpl( idl, header, base+".h", base + "_stub." + suffix, de );
     }
 
     return 0;
Index: dcopidl2cpp/main.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/main.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 main.h
--- dcopidl2cpp/main.h	2000/07/16 01:43:48	1.2
+++ dcopidl2cpp/main.h	2001/09/27 22:54:41
@@ -36,5 +36,5 @@ void generateStub( const QString& idl, c
 /**
  * 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 \
);  
Index: dcopidl2cpp/stubimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/stubimpl.cpp,v
retrieving revision 1.11
diff -u -3 -p -r1.11 stubimpl.cpp
--- dcopidl2cpp/stubimpl.cpp	2000/12/04 12:40:53	1.11
+++ dcopidl2cpp/stubimpl.cpp	2001/09/27 22:54:41
@@ -55,7 +55,7 @@ int isIntType( const QString& t)
 /**
  * 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 )  {
     QFile impl( filename );
     if ( !impl.open( IO_WriteOnly ) )
@@ -72,16 +72,21 @@ void generateStubImpl( const QString& id
     str << "*****************************************************************************/" \
<< endl;  str << endl;
 
-    str << "#include \"" << header  << "\"" << endl;
+    str << "#include \"" << header << "\"" << endl;
     str << "#include <dcopclient.h>" << endl << endl;
     str << "#include <kdatastream.h>" << endl << endl;
 
+    // if signal
+    str << "#include <kapp.h>" << endl << endl;
+    str << "#include \"" << headerBase << "\"" << endl << endl;
+
     QDomElement e = de.firstChild().toElement();
     for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
 	if ( e.tagName() == "CLASS" ) {
 	    QDomElement n = e.firstChild().toElement();
 	    ASSERT( n.tagName() == "NAME" );
-	    QString className = n.firstChild().toText().data() + "_stub";
+	    QString classNameBase = n.firstChild().toText().data();
+	    QString className = classNameBase + "_stub";
 	
 	    // find dcop parent ( rightmost super class )
 	    QString DCOPParent;
@@ -135,7 +140,8 @@ void generateStubImpl( const QString& id
 	    // Write marshalling code
 	    s = e.firstChild().toElement();
 	    for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
-		if ( s.tagName() == "FUNC" ) {
+		if ( s.tagName() == "FUNC" || s.tagName() == "SIGNAL" ) {
+                    bool signal = (s.tagName() == "SIGNAL");
 		    QDomElement r = s.firstChild().toElement();
 		    ASSERT( r.tagName() == "TYPE" );
 		    QString result = r.firstChild().toText().data();
@@ -153,7 +159,7 @@ void generateStubImpl( const QString& id
 		    r = r.nextSibling().toElement();
 		    ASSERT ( r.tagName() == "NAME" );
 		    QString funcName = r.firstChild().toText().data();
-		    str << className << "::" << funcName << "(";
+		    str << ( signal ? classNameBase : className ) << "::" << funcName << "(";
 
 		    QStringList args;
 		    QStringList argtypes;
@@ -199,12 +205,18 @@ void generateStubImpl( const QString& id
 			funcName += *it;
 		    }
 		    funcName += ")";
+		
+		    if ( async || signal ) {
+
+			if ( signal && (result != "void") )
+                            qFatal("Sorry DCOP signals can not return values.");
 		
-		    if ( async ) {
-			str << "    if ( !dcopClient()  ) {"<< endl;
-			str << "\tsetStatus( CallFailed );" << endl;
-			str << "\treturn;" << endl;
-			str << "    }" << endl;
+                        if (!signal) {
+                            str << "    if ( !dcopClient()  ) {"<< endl;
+                            str << "\tsetStatus( CallFailed );" << endl;
+                            str << "\treturn;" << endl;
+                            str << "    }" << endl;
+                        }
 		
 			str << "    QByteArray data;" << endl;
 			if ( !args.isEmpty() ) {
@@ -213,10 +225,15 @@ void generateStubImpl( const QString& id
 				str << "    arg << " << *args_count << ";" << endl;
 			    }
 			}
-			str << "    dcopClient()->send( app(), obj(), \"" << funcName << "\", data );" << \
                endl;
-			str << "    setStatus( CallSucceeded );" << endl;
+                        if (signal) 
+                            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 ))



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic