/**********

     THIS IS A INTERIM TEST CLIENT

*************/

#include <stdio.h>
#include <orb/orbit.h>
#include <gnome.h>
#include <liboaf/liboaf.h>

#include "orbit-gxsnmp-db.h"

int main (int argc, char **argv)
{
CORBA_Environment ev;
CORBA_ORB orb;

GxSNMP_GSQLDB gsqldbclient;

GxSNMP_GSQLDB_GSQLDBTable *table;
GxSNMP_GSQLDB_RowHost *host;

gchar *query;

	CORBA_exception_init (&ev);

	orb = oaf_init(argc,argv);

	query = g_strdup("repo_ids.has ('IDL:GxSNMP/DB:1.0')");
	gsqldbclient = oaf_activate (query, NULL, 0, NULL, &ev);
	g_free(query);
	if(gsqldbclient == CORBA_OBJECT_NIL) {
		g_print("cannot bind to object\n");
		exit(-1);
	}

/***** GSQLDB operation *****/

	table = GxSNMP_GSQLDB_GSQLDBTable__alloc();
	table->table = CORBA_string_dup("host");
	GxSNMP_GSQLDB_TableOpen (gsqldbclient, table, &ev);

	while((host = GxSNMP_GSQLDB_GetRowHost (gsqldbclient, &ev))){
		if(ev._major != CORBA_NO_EXCEPTION) break;
		fprintf(stderr,"objid: %d\n", host->objid);
		fprintf(stderr,"created: %s\n", host->created);
		fprintf(stderr,"modified: %s\n", host->modified);
		fprintf(stderr,"dnsname: %s\n", host->dnsname);
		fprintf(stderr,"name: %s\n", host->name);
		fprintf(stderr,"description: %s\n", host->description);
		fprintf(stderr,"contact: %s\n", host->contact);
		fprintf(stderr,"tags: %s\n\n", host->tags);
		CORBA_free(host);
	}

	GxSNMP_GSQLDB_TableClose (gsqldbclient, table, &ev);

	CORBA_free(table);

/************/

	CORBA_exception_free (&ev);

	exit(0);
}
