weird diagnostics from trivial Bonobo server

Ben Liblit <[email protected]> Mon, 08 Sep 2003 17:29:55 -0700
Newsgroups gmane.comp.gnome.components
Message-ID <[email protected]>
I'm trying to use Bonobo activation to implement a simple application 
with singleton semantics: no more than one copy running at a time.

For so trivial a use of Bonobo, I don't need a custom IDL interface or 
even a special BonoboObject subclass.  My plan was to create a 
BonoboObject directly and register it with Bonobo activation using my 
hard-wired IID.

Unfortunately that code, attached below, fails in weird ways.  First, 
when creating the BonoboObject, I get a warning diagnostic:

     server = g_object_new(BONOBO_OBJECT_TYPE, 0);
=>
     Bonobo-WARNING **: It looks like you used g_type_unique
     instead of b_type_unique on type 'BonoboObject'

I didn't use any of these type creation functions; I just used the 
existing BonoboObject type.  What's going wrong here?

Continuing along, I register the server with Bonobo activation:

     object = BONOBO_OBJREF(server);
     result = bonobo_activation_register_active_server(iid, object, 0);

The returned value from that registration call should be a member of the 
Bonobo_RegistrationResult enum.  But it's not even close: 1074293632. 
What in the world is that supposed to indicate?  (As a sanity check, if 
I register an IID which was not listed in any "*.server" file, I do get 
back Bonobo_ACTIVATION_REG_NOT_LISTED as expected.)

Lastly, I unregister the server using 
bonobo_activation_unregister_active_server() and exit with 
bonobo_debug_shutdown().  I receive one final warning:

     Bonobo-WARNING **: Leaked a total of 1 refs to 1 bonobo object(s)

When did that reference leak?  I thought I was cleaning everything up 
properly, but apparently not.

These must be easy errors, as the code itself is so simple.  If someone 
wants to lend me a clue, I'd be most grateful.
test.c (text/plain, 1.1 KB)
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-object.h>


int main(int argc, char *argv[])
{
  bonobo_init(&argc, argv);
  bonobo_activation_orb_init(&argc, argv);

  const char iid[] = "OAFIID:SamplerSingleton:1.0";
  BonoboObject *server = g_object_new(BONOBO_OBJECT_TYPE, 0);
  CORBA_Object object = BONOBO_OBJREF(server);
  
  Bonobo_RegistrationResult result = bonobo_activation_register_active_server(iid, object, 0);
  switch (result)
    {
    case Bonobo_ACTIVATION_REG_SUCCESS:
      fputs("Bonobo_ACTIVATION_REG_SUCCESS\n", stderr);
      break;
    case Bonobo_ACTIVATION_REG_NOT_LISTED:
      fputs("Bonobo_ACTIVATION_REG_NOT_LISTED", stderr);
      break;
    case Bonobo_ACTIVATION_REG_ALREADY_ACTIVE:
      fputs("Bonobo_ACTIVATION_REG_ALREADY_ACTIVE", stderr);
      break;
    case Bonobo_ACTIVATION_REG_ERROR:
      fputs("Bonobo_ACTIVATION_REG_ERROR", stderr);
      break;
    default:
      fprintf(stderr, "Bonobo activation mystery result: %d", result);
      break;
    }

  bonobo_activation_unregister_active_server(iid, object);
  return bonobo_debug_shutdown();
}