/**********

     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_RowInterface *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("interface");
	GxSNMP_GSQLDB_TableOpen (gsqldbclient, table, &ev);

	while((host = GxSNMP_GSQLDB_GetRowInterface (gsqldbclient, &ev))){
		if(ev._major != CORBA_NO_EXCEPTION) break;
		printf("objid: %d\n", host->objid);
		printf("  created: %s\n", host->created);
		printf("  modified: %s\n", host->modified);
		printf("  host: %d\n", host->host);
		printf("  snmp: %d\n", host->snmp);
		printf("  transport: %d\n", host->transport);
		printf("  address: %s\n", host->address);
		printf("  netmask: %s\n", host->netmask);
		printf("  name: %s\n", host->name);
		printf("  tags: %s\n\n", host->tags);
		CORBA_free(host);
	}

	GxSNMP_GSQLDB_TableClose (gsqldbclient, table, &ev);

	CORBA_free(table);

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

	CORBA_exception_free (&ev);

	exit(0);
}
