You are not logged in.

Dear visitor, welcome to KDE-Forum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, May 25th 2005, 4:26pm

DCOP - callAsync - registering callback fails

Hello *,

I want to evaluate DCOP IPC mechanisms and wanted to try the DCOPClient::callAsync() method. My server part works well, I can find my async() function e.g. with kdcop, call it, it gets executed, but I can't catch the reply (but the reply is sent: kdcop receives it!).
Here is some code of what I've tried, help will be highly appreciated

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DCOPClient * client = new DCOPClient(); 
client->attach();
QCString appID = client->registerAs(CLIENTNAME, false);
client->setNotifications(true);
Stuff * stuff = new Stuff();
int callID = client->callAsync(argv[1], "receiver", "async()", data, stuff, SLOT(theCallBackSlot(int, const QCString&, const QByteArray&)  ));
  if (callID > 0)
  {
   printf ("callAsync succeeded with ID=%i\n", callID); 
   printf ("We are back can do something else\n");
  }
  else
  {
   printf ("callAsync failed\n");       
  }

with

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <qobject.h>
#include <qcstring.h>
#include <stdio.h>

class Stuff : public QObject
{
  Q_OBJECT
public:
                                    
   Stuff();
  ~Stuff();
  
public slots:  
  void theCallBackSlot(int callId, const QCString& replyType, const QByteArray &replyData);                     
};

Stuff::Stuff() : QObject(NULL, NULL)
{}

Stuff::~Stuff()
{}


void Stuff::theCallBackSlot(int callId, const QCString& replyType, const QByteArray &replyData)
{
  printf ("CallBackSlot fired for ID:%i\n", callId);       
}


I think it has to be the registration of the callback function, but I don't know what it is...
There's no place like ::1

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

2

Wednesday, May 25th 2005, 9:29pm

Looks ok.

But why do you create a DCOPClient?
The one from KApplication is already attached after the KApplication constructor returns.

Is the moc file for Stuff generated properly?

Cheers,
_
Qt/KDE Developer
Debian User

3

Friday, May 27th 2005, 9:01am

Since this is only a test I am not using KApplication at all. I'm not even using a QApplication or something as this is a small command line utility without GUI.
The slot should be a real callback function. Do I need a K/QApplication?
All the other DCop functions are working correctly (client->registeredApplications, remoteObjects/Interfaces/functions, send &call) so why should I need the event queue for callAsync only?
I wrote the Makefile myself, the moc for Stuff-class is generated, compiled and linked...

I found an example where callAsync is used. I will compile it now and post further questions later (if there are any)
There's no place like ::1

4

Friday, May 27th 2005, 9:58am

SOLVED: What: DCOP - callAsync - registering callback fails

OK, I made some more tests and voila: if you take the docpclient from a true kapplication and call kApp.exec() it works!
Damn! Now I have to check the kapp constructor and exec() why...
There's no place like ::1

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

5

Friday, May 27th 2005, 12:38pm

I guess waiting for the answer means waiting on a socket for input.

As DCOP is usually used within GUI applications, this will be non-blocking, i.e. requiring running event loop.

Cheers,
_
Qt/KDE Developer
Debian User

6

Friday, May 27th 2005, 12:42pm

Exactly!

You have to create a QApplication, register the DCOPClient with this application (bindToApp(), this creates a QSocketNotifier) and start the event queue with app.exec() so that the events can be delievered/dispatched

Thanks everybody
There's no place like ::1