#include <orbit/orbit.h>

int
main(int argc, char **argv)
{
  CORBA_Environment ev;
  CORBA_ORB orb;
  CORBA_Object objref;
  CORBA_char *repo_id;
  ORBit_IInterface *iface;

  CORBA_exception_init(&ev);

  orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev);
  if (ev._major != CORBA_NO_EXCEPTION) {
    g_warning("could not initialise ORB");
    return 1;
  }
  g_message("created ORB");

  objref = CORBA_ORB_string_to_object(orb, argv[1], &ev);
  if (ev._major != CORBA_NO_EXCEPTION || objref == CORBA_OBJECT_NIL) {
    g_warning("could not create object reference");
    return 1;
  }
  g_message("got objref");
  g_message("non_existent == %d", CORBA_Object_non_existent(objref, &ev));

  repo_id = ORBit_small_get_type_id(objref, &ev);
  if (ev._major != CORBA_NO_EXCEPTION) {
    g_warning("could not get repo id");
    return 1;
  }
  g_message("repo_id == %s", repo_id);

  iface = ORBit_small_get_iinterface(objref, repo_id, &ev);
  if (ev._major != CORBA_NO_EXCEPTION) {
    g_warning("could not get IInterface for objref");
    return 1;
  }
  g_message("iface == %p", iface);

  CORBA_Object_release(objref, NULL);

  CORBA_exception_free(&ev);
  return 0;
}
