Re: [Newbie] Server Garbage Collection:- Post Client



>         Can you post your code again ? you shouldn't need to do anything
> except return the sequence for it to be freed I think.
>
>         Regards,
>
>                 Michael.



IDL file:-

----------------------------------------
module FooBar {
	interface HelloWorld {
		typedef sequence<string> stringlist;
		
		/* get sequence*/
		stringlist get_large_sequence();
		stringlist get_small_sequence();
	};
};
----------------------------------------


server file

----------------------------------------
/* A Hello world corba server */

#include <glib.h>
#include <stdio.h>
#include <orb/orbit.h>

/* Include the corba header file */
#include "corba-hello.h"


FooBar_HelloWorld hello_client = CORBA_OBJECT_NIL;


static  CORBA_sequence_CORBA_string * 
get_large_sequence(PortableServer_Servant servant, CORBA_Environment *ev);

static  CORBA_sequence_CORBA_string * 
get_small_sequence(PortableServer_Servant servant, CORBA_Environment *ev);


/*** epv structures ***/
static PortableServer_ServantBase__epv base_epv = {NULL,NULL,NULL};
static POA_FooBar_HelloWorld__epv epv = 
{NULL,get_large_sequence,get_small_sequence};

/*** vepv structures ***/
static POA_FooBar_HelloWorld__vepv vepv = {&base_epv,&epv};
static POA_FooBar_HelloWorld poa_hello_servant = { NULL, &vepv };



/*
	Declare the sequence loading functions
*/


static  CORBA_sequence_CORBA_string * 
get_large_sequence(PortableServer_Servant servant, CORBA_Environment *ev)
{
	CORBA_sequence_CORBA_string *sequence;
	int i;
	sequence=CORBA_sequence_CORBA_string__alloc();
	sequence->_buffer=CORBA_sequence_CORBA_string_allocbuf(100000);
	sequence->_length=100000;
	
	for(i=0;i<100000;i++){
		 sequence->_buffer[i]=CORBA_string_dup("Hello World");
	}
	
	CORBA_sequence_set_release( sequence, TRUE);
	return sequence;
}

static  CORBA_sequence_CORBA_string * 
get_small_sequence(PortableServer_Servant servant, CORBA_Environment *ev)
{
	CORBA_sequence_CORBA_string *sequence;
	int i;	 
	sequence=CORBA_sequence_CORBA_string__alloc();
	sequence->_buffer=CORBA_sequence_CORBA_string_allocbuf(100);
	sequence->_length=100;
	for(i=0;i<100;i++){
		 sequence->_buffer[i]=CORBA_string_dup("Hello World");
	}
	
	CORBA_sequence_set_release( sequence, TRUE);
	return sequence;
}




int
main (int argc, char *argv[])
{
    PortableServer_ObjectId objid = {0, sizeof("HelloString"), "HelloString"};
    PortableServer_POA poa;
    CORBA_ORB orb;
    CORBA_Environment ev;
    char *retval;
    FILE * ofp;
    
    CORBA_exception_init(&ev);
    orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev);

    POA_FooBar_HelloWorld__init(&poa_hello_servant, &ev);
    poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, 
"RootPOA", &ev);
    
    
PortableServer_POAManager_activate(PortableServer_POA__get_the_POAManager(poa, 
&ev), &ev);
    PortableServer_POA_activate_object_with_id(poa,&objid, 
&poa_hello_servant, &ev);
    hello_client = 
PortableServer_POA_servant_to_reference(poa,&poa_hello_servant,&ev);
    
    if (!hello_client) {
	printf("Cannot get objref\n");
	return 1;
    }

    retval = CORBA_ORB_object_to_string(orb, hello_client, &ev);
    
    ofp = fopen("hello.ior","w");     
    fprintf(ofp,"%s", retval);
    fclose(ofp);
    
    CORBA_free(retval);
    CORBA_ORB_run(orb, &ev);

    return 0;
}


----------------------------------------



client file
----------------------------------------
/* HelloWorld client */
#include <glib.h>
#include <stdio.h>
#include <orb/orbit.h>
#include "corba-hello.h"

int
main (int argc, char *argv[])
{
	CORBA_Environment ev;
	CORBA_ORB orb;
	CORBA_sequence_CORBA_string *large_seq;
	CORBA_sequence_CORBA_string *small_seq;
	FooBar_HelloWorld client;
	FILE * ifp;
	char * ior;
	char filebuffer[1024]; 
	
	
	
	large_seq=CORBA_sequence_CORBA_string__alloc();
	small_seq=CORBA_sequence_CORBA_string__alloc();
	
	CORBA_exception_init(&ev);

	/* initialize */
	orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev);

    	ifp = fopen("hello.ior","r");
    	if( ifp == NULL ){
      		g_error("No echo.ior file!");
      		return 1;
    	}     
	fgets(filebuffer, 1024, ifp);
    	ior = g_strdup(filebuffer);     
	fclose(ifp);  
	
	/* get our server object */
	client = CORBA_ORB_string_to_object(orb, ior, &ev);

	/* catch errors */
	if (client == CORBA_OBJECT_NIL) {
		g_print ("Cannot bind to %s\n", ior);
		return 1;
	}
	if (ev._major != CORBA_NO_EXCEPTION) {
		g_print ("Corba Exception!\n");
		return 1;
	}

	g_free (ior);

	/* From now on we ignore exceptions for simplicity */

	g_print("Doing large sequence fill\n");
	large_seq = FooBar_HelloWorld_get_large_sequence(client, &ev);
	
	g_print("Doing small sequence fill\n");
	small_seq = FooBar_HelloWorld_get_large_sequence(client, &ev);

	g_print("Releasing objects\n");
	
	CORBA_free(large_seq);
	CORBA_free(small_seq);
	/* Release objects */

	CORBA_Object_release (client, &ev);
	CORBA_Object_release ((CORBA_Object)orb, &ev);
	CORBA_exception_free(&ev);
	g_print("Calling goodbye\n");
	return 0;
}

----------------------------------------




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]