
/*
 * FILE:
 * myclient.c
 *
 * FUNCTION:
 * Implements a sample client.
 *
 * Author:
 *   Miguel de Icaza  (miguel@helixcode.com)
 * Modifications by Linas Vepstas <linas@linas.org>
 */


#include <gnome.h>
#include <liboaf/liboaf.h>
#include <bonobo.h>
#include "iface.h"


static void
init_bonobo (int argc, char *argv [])
{
    CORBA_ORB orb;

    gnome_init_with_popt_table (
         "myclient", "1.0",
         argc, argv,
         oaf_popt_options, 0, NULL); 

    orb = oaf_init (argc, argv);
    if (!bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL))
             g_error (_("I could not initialize Bonobo"));

    bonobo_activate ();
}

static void
usage (void)
{
    fprintf (stderr, "Uh-oh! and error occured! To use this program,\n"
       " read the README file !! \n");
}

int 
main (int argc, char *argv [])
{
    BonoboObjectClient *server;
    Bonobo_Dasample_MyServer  my_server;
    CORBA_Environment ev;
    char               *obj_id;

    init_bonobo (argc, argv);

    obj_id = "OAFIID:Bonobo_Dasample_MyServer";

    server = bonobo_object_activate (obj_id, 0);
    if (!server) 
    {
        printf ("Could not create an instance of the %s component\n", obj_id);
        return 1;
    }

    /*
     * Get the CORBA Object reference from the BonoboObjectClient
     */
    CORBA_exception_init (&ev);
    my_server = BONOBO_OBJREF (server);

    /* Send a message */
    Bonobo_Dasample_MyServer_sendmsg (my_server, "rock on duude!\n", &ev);

    printf ("we sent the message!\n");
    if (BONOBO_EX (&ev))
    {
      usage ();
    }
    CORBA_exception_free (&ev);
    bonobo_object_unref (BONOBO_OBJECT (server));

    return 0;
}
  
/* =========================== END OF FILE ===================== */

