The K Desktop Environment

Next Previous Table of Contents

5. KNaming

The KDE Naming Service, KNaming, is also a very simple service, but it's pretty useful and in some cases a very nice solution to make a CORBA client connect to a persistent CORBA server.

With KNaming you can bind a freely chooseable name to a CORBA object. And since kded is system (session) wide available, your object becomes available for any client which is able to connect to kded.

There's not much to explain here :-} , so I suggest having a look at the KNaming API, in knaming.h.

Example code can be, again, found in kdelibs/corba/tutorials/kded . Here's just a short real example situation:

Just think of KDesktop, that nice app providing your background desktop icons. It provides some functionality via CORBA, just have a look at kdesktop.idl to see what I'm talking about. Now the problem for KDesktop is: How can it provide this service to other apps in the system? Writing an IOR into some file is no clean solution IMHO, and using KActivator doesn't work because KDesktop does not get started by kded but by the startkde script on KDE startup. So we find a better way and make KDesktop register it's object at KNaming. This is done by the following lines:

  ...
  KNaming *knaming = KdedInstance::self()->knaming();
  naming->bind( "KDesktop", kdesktop_object_here );
  ...
Well, I told you a lie ;) : KNaming does not really bind to "KDesktop" but instead to "IDL:KDesktopIf:1.0" , but since there's no naming convention for the naming I have choosen a more readable name, IMHO of course :-) (don't mind me David :] ) . I personally prefer human readable names ;) , in contrary to repository ids with tags.

Back to KNaming and KDesktop: Now any client application, kfmclient for example, can "connect" to KDesktop. Just like this:

  ..
  KNaming *knaming = KdedInstance::self()->knaming();
  ...
  CORBA::Object_var obj = knaming->resolve( "KDesktop" );
  KDesktopIf_var kdesky = KDesktopIf::_narrow( obj );
  kdesky->selectAll(); //let's confuse the user by selecting all icons ;-)
  ...

Next Previous Table of Contents