Beispiel #1
0
void handle_exception(CORBA_Environment *ev)
{
	switch (ev->_major) {
	case CORBA_NO_EXCEPTION:
		break;
		
	case CORBA_SYSTEM_EXCEPTION: {
		/*
		 * All CORBA system exceptions have the same fields, so we
		 * arbitrarily cast to `CORBA_UNKNOWN *'.
		 */
		CORBA_UNKNOWN *e = ((CORBA_UNKNOWN *)
				    CORBA_exception_value(ev));
		
		printf(("A system exception was raised: "
			"id = %s, minor = %d, completed = %d.\n"),
		       CORBA_exception_id(ev),
		       e->minor,
		       e->completed);
		break;
	}
	
	case CORBA_USER_EXCEPTION:
		printf("A user exception was raised: ");
		
		if (!strcmp(CORBA_exception_id(ev), ex_data_duplicate)) {
			data_duplicate *dup
				= ((data_duplicate *)
				   CORBA_exception_value(ev));
			
			printf("duplicate, phone = `%s'.\n", dup->p);
			/*
			 * XXX --- Flick's `CORBA_exception_free'
			 * doesn't yet do a ``deep free.''
			 */
			CORBA_free(dup->p);
				
		} else if (!strcmp(CORBA_exception_id(ev), ex_data_notfound))
			printf("notfound.\n");
		
		else
			printf("unknown exception, id = %s.\n",
			       CORBA_exception_id(ev));
		break;
		
	default:
		printf("Error: unknown exception class %d!\n", ev->_major);
		break;
	}
	
	CORBA_exception_free(ev);
}
Beispiel #2
0
void handle_exception(CORBA_Environment *ev)
{
	switch (ev->_major) {
	case CORBA_NO_EXCEPTION:
		return; /* don't abort the program */
	case CORBA_SYSTEM_EXCEPTION:
		fprintf(stderr, "%s ERROR %d.%d\n",
			CORBA_exception_id(ev),
			((CORBA_UNKNOWN *)CORBA_exception_value(ev))->minor,
			((CORBA_UNKNOWN *)CORBA_exception_value(
				ev))->completed);		
		break;
	case CORBA_USER_EXCEPTION:
		fprintf(stderr, "UNKNOWN USER EXCEPTION %s!\n",
			CORBA_exception_id(ev));
		break;
	default:
		fprintf(stderr, "Unknown exception type\n");
	}
	
	CORBA_exception_free(ev);
}
Beispiel #3
0
int oe_server_receive_tmo(CORBA_Environment *env, oe_map_t *map, 
			  unsigned int send_ms, 
			  unsigned int recv_ms)
{
    int res = 0, loop = 1;
    erlang_msg msg;

    while (res >= 0 && loop > 0) {
        res = ei_receive_encoded_tmo(env->_fd, &env->_inbuf, &env->_inbufsz, 
				 &msg, &env->_iin, recv_ms); 
	switch(res) {
	case ERL_SEND:
	case ERL_REG_SEND:
	    oe_exec_switch(NULL, env, map);
	    switch(env->_major) {
	    case CORBA_NO_EXCEPTION:
		break;
	    case CORBA_SYSTEM_EXCEPTION:
		/* XXX stderr */
		fprintf(stderr, "Request failure, reason : %s\n", 
			(char *) CORBA_exception_value(env));
		CORBA_exception_free(env);
		break;
	    default: /* Should not happen */
		CORBA_exception_free(env);
		break;
	    }
	    /* send reply */
	    /* XXX We are required to set env->_iout = 0 if oneway?? */
	    if (env->_iout > 0) 
		ei_send_encoded_tmo(env->_fd, &env->_caller, env->_outbuf, 
				env->_iout, send_ms);
	    loop = 0;
	    break;
	case ERL_TICK:
	    break;
	default: 
	    /* XXX */
	    if (res < 0) {
		fprintf(stderr, "Result negative: %d\n", res);
		loop = 0;
	    }
	    break;
	}
    }	

    return 0;
}
/**
 * e_get_activation_failure_msg:
 * @ev: An exception returned by an oaf_activate call.
 *
 * Get a descriptive error message from @ev.
 *
 * Return value: A newly allocated string with the printable error message.
 **/
char *
e_get_activation_failure_msg (CORBA_Environment *ev)
{
	g_return_val_if_fail (ev != NULL, NULL);

	if (CORBA_exception_id (ev) == NULL)
		return NULL;

	if (strcmp (CORBA_exception_id (ev), ex_Bonobo_GeneralError) != 0) {
		return bonobo_exception_get_text (ev);
	} else {
		const Bonobo_GeneralError *oaf_general_error;

		oaf_general_error = CORBA_exception_value (ev);
		return g_strdup (oaf_general_error->description);
	}
}
Beispiel #5
0
static void
do_query_server_info(void)
{
	Bonobo_ActivationContext ac;
	Bonobo_ServerInfoList *slist;
	Bonobo_StringList reqs = { 0 };

	if (acior) {
                ac = CORBA_ORB_string_to_object (orb, acior, &ev);
                if (ev._major != CORBA_NO_EXCEPTION)
                        g_print ("Error doing string_to_object(%s)\n", acior);
        } else
                ac = bonobo_activation_activation_context_get ();

	slist = Bonobo_ActivationContext_query (
                                        ac, specs, &reqs,
                                        bonobo_activation_context_get (), &ev);
	switch (ev._major) {
        case CORBA_NO_EXCEPTION:
		od_dump_list (slist);
		CORBA_free (slist);
		break;
	case CORBA_USER_EXCEPTION:
		{
			char *id;
			id = CORBA_exception_id (&ev);
			g_print ("User exception \"%s\" resulted from query\n", id);
			if (!strcmp (id, "IDL:Bonobo/ActivationContext/ParseFailed:1.0")) {
				Bonobo_Activation_ParseFailed
						* exdata = CORBA_exception_value (&ev);
				if (exdata)
					g_print ("Description: %s\n", exdata->description);
			}
		}
		break;
	case CORBA_SYSTEM_EXCEPTION:
		{
			char *id;
			id = CORBA_exception_id (&ev);
			g_print ("System exception \"%s\" resulted from query\n", id);	
        	}
		break;
        }	
	return;	
}
static char *
matecomponent_activation_exception_id (CORBA_Environment *ev)
{
        if (ev->_major == CORBA_USER_EXCEPTION) {
                if (!strcmp (ev->_id, "IDL:MateComponent/GeneralError:1.0")) {
                        MateComponent_GeneralError *err = CORBA_exception_value (ev);
                        
                        if (!err || !err->description) {
                                return "No general exception error message";
                        } else {
                                return err->description;
                        }
                } else {
                        return ev->_id;
                }
        } else {
                return CORBA_exception_id (ev);
        }
}
Beispiel #7
0
int main(int argc, char **argv)
#endif
{
    struct hostent *hp;
    MyTimeval start, stop;
    int i, fd, ires, tries;
    CORBA_Environment *env;
    char *this_node_name = NULL;
    char *peer_node = NULL;
    char *cookie = NULL;
    char host[HOSTNAMESZ + 1];
    char this_node[NODENAMESZ + 1];
    erlang_msg msg;
    int status, loop; 
    
#ifdef __WIN32__
    WORD wVersionRequested;
    WSADATA wsaData;
    
    wVersionRequested = MAKEWORD(2, 0);
    
    if (WSAStartup(wVersionRequested, &wsaData) != 0) {
	fprintf(stderr, "Could not load winsock2 v2.0 compatible DLL");
	exit(1);
    }
#endif
    
    progname = argv[0];
    host[HOSTNAMESZ] = '\0';
    if (gethostname(host, HOSTNAMESZ) < 0) {
	fprintf(stderr, "Can't find own hostname\n");
	done(1);
    } 
    if ((hp = gethostbyname(host)) == 0) {
	fprintf(stderr, "Can't get ip address for host %s\n", host);
	done(1);
    }
    for (i = 1; i < argc; i++) {
	if (strcmp(argv[i], "-help") == 0) {
	    usage();
	    done(0);
	} else if (strcmp(argv[i], "-this-node-name") == 0) {
	    i++;
	    this_node_name = argv[i];
	} else if (strcmp(argv[i], "-peer-node") == 0) {
	    i++;
	    peer_node = argv[i];
	} else if (strcmp(argv[i], "-cookie") == 0) {
	    i++;
	    cookie = argv[i];
	} else {
	    fprintf(stderr, "Error : invalid argument \"%s\"\n", argv[i]);
	    usage();
	    done(1);
	}
    }

    if (this_node_name == NULL || peer_node == NULL || cookie == NULL) {
	fprintf(stderr, "Error: missing option\n");
	usage();
	done(1);
    }

    /* Behead hostname at first dot */
    for (i=0; host[i] != '\0'; i++) {
	if (host[i] == '.') { host[i] = '\0'; break; }
    }
    sprintf(this_node, "%s@%s", this_node_name, host);

    fprintf(stderr, "c_server: this node: \"%s\"\n", this_node);
    fprintf(stderr, "c_server: peer node: \"%s\"\n", peer_node);

    /* initialize erl_interface */
    erl_init(NULL, 0);

    for (tries = 0; tries < MAXTRIES; tries++) {
	/* connect to peer node */ 
    	ires = erl_connect_xinit(host, this_node_name, this_node, 
				 (struct in_addr *)*hp->h_addr_list, 
				 cookie, 0);
	fprintf(stderr, "c_server: erl_connect_xinit(): %d\n", ires);
    
	fd = erl_connect(peer_node);
	fprintf(stderr, "c_server: erl_connect(): %d\n", fd);
	if (fd >= 0) 
	    break;
	fprintf(stderr, "c_server: cannot connect, retrying\n");
    }
    if (fd < 0) {
	fprintf(stderr, "c_server: cannot connect, exiting\n");
	done(1);
    }
    env = CORBA_Environment_alloc(INBUFSZ, OUTBUFSZ);
    env->_fd = fd; 

    status = 1;
    loop = 1;
    my_gettimeofday(&start);
    while (status >= 0 && loop > 0) {
        status = ei_receive_encoded(env->_fd, &env->_inbuf, &env->_inbufsz, 
				    &msg, &env->_iin); 
	switch(status) {
	case ERL_SEND:
	case ERL_REG_SEND:
	    /* get result */
	    m_i__switch(NULL, env);
	    switch(env->_major) {
	    case CORBA_NO_EXCEPTION:
		break;
	    case CORBA_SYSTEM_EXCEPTION:
		fprintf(stderr, "Request failure, reason : %s\n", 
			(char *) CORBA_exception_value(env));
		CORBA_exception_free(env);
		break;
	    default: /* Should not happen */
		CORBA_exception_free(env);
		break;
	    }
	    /* send back result data */
	    if (env->_iout > 0) 
		ei_send_encoded(env->_fd, &env->_caller, env->_outbuf, 
				env->_iout);
	    loop = 0;
	    break;
	case ERL_TICK:
	    break;
	default: 
	    if (status < 0) {
		fprintf(stderr, "Status negative: %d\n", status);
		loop = 0;
	    }
	    break;
	}
    }	
    my_gettimeofday(&stop);
    showtime(&start, &stop);

    erl_close_connection(fd);

    CORBA_free(env->_inbuf);
    CORBA_free(env->_outbuf);
    CORBA_free(env);
    if (status < 0) 
	done(-status);
    else 
	done(0); 
}
Beispiel #8
0
int main()
{
    double result=0;
    int i=0;
    erlang_pid pid;
    CORBA_Environment *env;
    ei_cnode ec;
  
    /* Create and init CORBA_Environment */
    env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ);
  
    /* Initiating the connection */
    ei_connect_init(&ec, "c47", COOKIE, 0);

    /* Initiating pid*/
    strcpy(pid.node, CLNODE);
    pid.num = 99;
    pid.serial = 0;
    pid.creation = 0;

    /* Fixing environment variable */
    env->_fd = ei_connect(&ec, SNODE);
    strcpy(env->_regname,SERVER);
    env->_to_pid = NULL;
    env->_from_pid = &pid;
  
    if (env->_fd < 0) {
	fprintf(stderr,"Error : Cannot connect to Server\n");

	/* Free env & buffers */
	CORBA_free(env->_inbuf);
	CORBA_free(env->_outbuf);
	CORBA_free(env);
	exit(1);
    }
  
    /* Calling the init function */
    rmod_random_init(NULL, 1, 2, 3, env);
 
    switch(env->_major) {
    case CORBA_NO_EXCEPTION:	/* Success */
	printf("Init complete !\n");
	break;
    case CORBA_SYSTEM_EXCEPTION: /* System exception */
	printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env));
	CORBA_exception_free(env);
	client_exit(env);
    default:			/* Should not come here */
	client_exit(env);
    }

    /* Calling the produce function */
    for(i=1; i<=10; i++) {
	result = rmod_random_produce(NULL, env);

	switch(env->_major) {
	case CORBA_NO_EXCEPTION: /* Success */
	    break;
	case CORBA_SYSTEM_EXCEPTION: /* System exception */
	    printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env));
	    CORBA_exception_free(env);
	    client_exit(env);
	default:		/* Should not come here */
	    client_exit(env);
	}

	printf("the random number nr%d is %f\n",i,result);
    }

    /* Closing the connection */
    close(env->_fd);
  
    /* Free env & buffers */
    CORBA_free(env->_inbuf);
    CORBA_free(env->_outbuf);
    CORBA_free(env);

    return 0;
}
Beispiel #9
0
int main(int argc, char **argv)
{
	CORBA_ORB orb = 0;
	CORBA_Object obj;
#define C_DECLV(type) CORBA_##type	ret##type, in##type, out##type, inout##type
#define T_DECLV(type) test1_##type	ret##type, in##type, out##type, inout##type
	C_DECLV(short);
	C_DECLV(long);
	T_DECLV(ushort);
	T_DECLV(ulong);
	C_DECLV(float);
	C_DECLV(double);
	C_DECLV(char);
	C_DECLV(boolean);
	C_DECLV(octet);
	C_DECLV(Object);
	
	CORBA_char *instring, *outstring, *inoutstring, *retstring;
	CORBA_long case_num;
	CORBA_Environment ev;
	
	orb = CORBA_ORB_init(&argc, argv, 0 /* use default ORBid */, &ev);
	obj = CORBA_ORB_string_to_object(orb, argv[1], &ev);
	if (ev._major != CORBA_NO_EXCEPTION) {
		printf("Problem converting `%s' to an object.\n", argv[1]);
		exit(1);
	}
	printf("Beginning communication...\n");
#define SHOWPARMS(prn, type)						    \
	if (ev._major != CORBA_NO_EXCEPTION)				    \
		printf("Exception: `%s' EXCEPTION RAISED FOR " #type "!\n", \
		       CORBA_exception_id(&ev));			    \
	else								    \
		printf("Exception: no\n");				    \
	printf("In:       " #prn"\n", in##type);			    \
	printf("Inout:    " #prn"\n", inout##type);			    \
	printf("Out:      " #prn"\n", out##type);			    \
	printf("Result:   " #prn"\n", ret##type);
#define RUNTEST(type, inval, inoutval, otherval, prn)			\
	in##type = inval;						\
	inout##type = inoutval;						\
	ret##type = out##type = otherval;				\
	ev._major = CORBA_NO_EXCEPTION;					\
	printf("Testing " #type" Before Call:\n");			\
	SHOWPARMS(##prn, ##type);					\
	printf("Calling Server...\n");					\
	ret##type = test1_test_##type(obj, in##type, &out##type,	\
				      &inout##type, &ev);		\
	printf("After Call:\n");					\
	SHOWPARMS(##prn, ##type);
	
	RUNTEST(short, 1234, 4321, 7, %d);
	RUNTEST(ushort, 65500, 33000, 6, %d);
	RUNTEST(long, 12341234, 43214321, 2, %d);
	RUNTEST(ulong, 3000000000U, 4000000000U, 5, %u);
	RUNTEST(float, 1.234, 2.345, 3.1415, %f);
	RUNTEST(double, 1.2345678901, 2.3456789012, 2.71828, %f);
	RUNTEST(boolean, 0, 1, 2, %d);
	RUNTEST(octet, 12, 23, 34, %d);
	RUNTEST(char, 'a', 'b', 'c', %c);
	
	/* Must allocate the `inout' string with the CORBA allocator. */
	inoutstring = (char *) CORBA_alloc(sizeof("Howdy"));
	(void)strcpy(inoutstring, "Howdy");
	RUNTEST(string, "Hello", inoutstring, "Ugh", %s);
	
	/* Now run the object passing test */
        inObject = CORBA_Object_duplicate(obj, &ev);
        inoutObject = CORBA_Object_duplicate(obj, &ev);
	/* check for exception */
        retObject = outObject = 0;
        printf("Testing Object Before Call:\n");
	if (ev._major != CORBA_NO_EXCEPTION)
		printf("Exception: `%s' EXCEPTION RAISED FOR Object!\n",
		       CORBA_exception_id(&ev));
	else
		printf("Exception: no\n");
        printf("In:       %p\nURL:\t%s\nIOR:\t%s\n", inObject,
	       CORBA_ORB_object_to_readable_string(orb, inObject, &ev),
	       CORBA_ORB_object_to_string(orb, inObject, &ev));
        printf("Inout:    %p\nURL:\t%s\nIOR:\t%s\n", (void *)inoutObject,
	       CORBA_ORB_object_to_readable_string(orb, inoutObject, &ev),
	       CORBA_ORB_object_to_string(orb, inoutObject, &ev));
        printf("Out:      %p\nURL:\t%s\nIOR:\t%s\n", (void *)outObject,
	       CORBA_ORB_object_to_readable_string(orb, outObject, &ev),
	       CORBA_ORB_object_to_string(orb, outObject, &ev));
        printf("Result:   %p\nURL:\t%s\nIOR:\t%s\n", (void *)retObject,
	       CORBA_ORB_object_to_readable_string(orb, retObject, &ev),
	       CORBA_ORB_object_to_string(orb, retObject, &ev));
        printf("Calling Server...\n");
        retObject = test1_test_Object(obj, inObject, &outObject, &inoutObject,
				      &ev);
        printf("After Call:\n");
	if (ev._major != CORBA_NO_EXCEPTION) 
		printf("Exception: `%s' EXCEPTION RAISED FOR Object!\n",
		       CORBA_exception_id(&ev));
	else
		printf("Exception: no\n");
        printf("In:       %p\nURL:\t%s\nIOR:\t%s\n", inObject,
	       CORBA_ORB_object_to_readable_string(orb, inObject, &ev),
	       CORBA_ORB_object_to_string(orb, inObject, &ev));
        printf("Inout:    %p\nURL:\t%s\nIOR:\t%s\n", inoutObject,
	       CORBA_ORB_object_to_readable_string(orb, inoutObject, &ev),
	       CORBA_ORB_object_to_string(orb, inoutObject, &ev));
        printf("Out:      %p\nURL:\t%s\nIOR:\t%s\n", outObject,
	       CORBA_ORB_object_to_readable_string(orb, outObject, &ev),
	       CORBA_ORB_object_to_string(orb, outObject, &ev));
        printf("Result:   %p\nURL:\t%s\nIOR:\t%s\n", retObject,
	       CORBA_ORB_object_to_readable_string(orb, retObject, &ev),
	       CORBA_ORB_object_to_string(orb, retObject, &ev));
	
	for (case_num = -1; case_num <= 5; case_num++) {
		ev._major = CORBA_NO_EXCEPTION;
		printf("Testing test_throw Before Call:\n"); 	
		if (ev._major != CORBA_NO_EXCEPTION) 
			printf("Exception: `%s' EXCEPTION RAISED FOR throw!\n",
			       CORBA_exception_id(&ev));	       
		else
			printf("Exception: no\n");
		printf("In:       %d\n", case_num);
		printf("Calling Server...\n");
		test1_test_throw(obj, case_num, &ev);
		printf("After Call:\n");
		switch (ev._major) {
		case CORBA_USER_EXCEPTION:
			if (!strcmp(CORBA_exception_id(&ev), ex_test1_x1))
				printf("Caught exception test1_x1!  "
				       "Case_Num: %d\n",
				       ((test1_x1 *)
					CORBA_exception_value(&ev))
				       ->case_num);
			else if (!strcmp(CORBA_exception_id(&ev),
					 ex_test1_x2))
				printf("Caught exception test1_x2!  "
				       "Obj URL: %s,  value: %d\n",
				       CORBA_ORB_object_to_readable_string(
					       orb,
					       ((test1_x2 *)
						CORBA_exception_value(&ev))->
					       obj,
					       &ev),
				       ((test1_x2 *)
					CORBA_exception_value(&ev))->value);
			else
				printf("Unknown User Exception Raised: `%s' "
				       "for throw!\n",
				       CORBA_exception_id(&ev));
			break;
		case CORBA_SYSTEM_EXCEPTION:
			printf("Exception: `%s' EXCEPTION RAISED FOR throw!\n",
			       CORBA_exception_id(&ev));
			break;
		default:
			printf("Exception: no\n");
			printf("In:       %d\n", case_num);
		}
	}
	
	printf("About to tell the server to exit...\n");
	test1_please_exit(obj, &ev);
	printf("Server should be exiting any moment...\n");
	return 0;
}
Beispiel #10
0
static void server_loop(int sd, int epmd_fd)
{
  ErlConnect conn;
  erlang_msg msg;
  int status=1;
  CORBA_Environment *env;
  
  /* Create and init CORBA_Environment */
  env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ);
  
  while (status >= 0) {
    
    status = 1;
    
    if ((env->_fd = erl_accept(sd,&conn)) < 0) {       
      /* error */
      fprintf(stderr,"Accept failed: %s\n",strerror(errno));
    }
    else {
      /* connection */
      fprintf(stderr,"Accepted connection from %s\n",conn.nodename);
      
      while (status >= 0) {

	/* write message to buffer */
	status = ei_receive_encoded(env->_fd, &env->_inbuf, &env->_inbufsz, &msg, &env->_iin); 
	switch(status) {
	case ERL_SEND:
	case ERL_REG_SEND :
	  /* do transaction with fd */
	  rmod_random__switch(NULL,env);
	  
	  switch(env->_major) {
	  case CORBA_NO_EXCEPTION: /* Success */
	    break;
	  case CORBA_SYSTEM_EXCEPTION: /* System exception */
	    printf("Request failure, reason : %s\n",(char *) CORBA_exception_value(env));
	  CORBA_exception_free(env);
	  break;
	  default: /* Should not come here */
	    CORBA_exception_free(env);
	    break;
	}
	  
	  /* send outdata */
	  if (env->_iout > 0) 
	    ei_send_encoded(env->_fd,&env->_caller,env->_outbuf,env->_iout);
	  break;
	  
      case ERL_TICK :
	break;
	default : /* < 0 */
	  printf("Connection terminated\n");
	  break;
	}  
      }
    }
    status=0; /* restart */
  }
  
  /* close file descriptors */
  terminate(&env->_fd, &sd, &epmd_fd);
  
  /* Free env & buffers */
  CORBA_free(env->_inbuf);
  CORBA_free(env->_outbuf);
  CORBA_free(env);
} 
Beispiel #11
0
int main(){
  
  double result=0;
  int i=0;
  int error = 0;
  erlang_pid pid;
  char host[HOSTNAMESZ];
  char server_node[HOSTNAMESZ];
  char client_node[HOSTNAMESZ];
  CORBA_Environment *env;
  
  /* Initiate names */
#ifdef __WIN32__
  WORD wVersionRequested;
  WSADATA wsaData;

  wVersionRequested = MAKEWORD(1, 1);
  if ((error = WSAStartup(wVersionRequested, &wsaData))) {
      fprintf(stderr,"Can't initialize windows sockets: %d",error);
      return 0;
  }
#endif
  error = gethostname(host,HOSTNAMESZ);
  if (error) {
#ifdef __WIN32__
      fprintf(stderr,"can't find own hostname (error = %ld) !\n",WSAGetLastError());
#else /* not __WIN32__ */
      fprintf(stderr,"can't find own hostname !\n");
#endif
  }
  sprintf(client_node,"%s@%s",CLNODENAME,host);
  sprintf(server_node,"%s@%s",SNODENAME,host);
    
  /* Create and init CORBA_Environment */
  env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ);
  
  /* Initiating the connection */
  erl_init(NULL,0);
  erl_connect_init(50,COOKIE,0);

  /* Initiating pid*/
  strcpy(pid.node,client_node);
  pid.num = 99;
  pid.serial = 0;
  pid.creation = 0;

  /* Fixing environment variable */
  env->_fd=erl_connect(server_node);
  strcpy(env->_regname,SREGNAME);
  env->_to_pid = NULL;
  env->_from_pid = &pid;
  
  if (env->_fd < 0) {
    fprintf(stderr,"Error : Cannot connect to Server\n");

    /* Free env & buffers */
    CORBA_free(env->_inbuf);
    CORBA_free(env->_outbuf);
    CORBA_free(env);
    exit(1);
  }
  
  /* Calling the init function */
  rmod_random_init(NULL, 1, 2, 3, env);
 
  switch(env->_major) {
  case CORBA_NO_EXCEPTION: /* Success */
    printf("Init complete !\n");
    break;
  case CORBA_SYSTEM_EXCEPTION: /* System exception */
    printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env));
    CORBA_exception_free(env);
    client_exit(env);
  default: /* Should not come here */
    client_exit(env);
  }

  /* Calling the produce function */
  for(i=1; i<=10; i++) {
    result = rmod_random_produce(NULL, env);

    switch(env->_major) {
    case CORBA_NO_EXCEPTION: /* Success */
      break;
    case CORBA_SYSTEM_EXCEPTION: /* System exception */
      printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env));
      CORBA_exception_free(env);
      client_exit(env);
    default: /* Should not come here */
      client_exit(env);
    }

    printf("the random number nr%d is %f\n",i,result);
  }

  /* Closing the connection */
  erl_close_connection(env->_fd);
  
  /* Free env & buffers */
  CORBA_free(env->_inbuf);
  CORBA_free(env->_outbuf);
  CORBA_free(env);

  return 0;
}
Beispiel #12
0
static int
do_activating(void)
{
	Bonobo_ActivationEnvironment environment;
	Bonobo_ActivationResult *a_res;
	Bonobo_ActivationContext ac;	
	Bonobo_StringList reqs = { 0 };
	char *resior;
	int res = 1;

	if (acior) {
                ac = CORBA_ORB_string_to_object (orb, acior, &ev);
                if (ev._major != CORBA_NO_EXCEPTION)
        	return 1;
	} else
                ac = bonobo_activation_activation_context_get ();

	memset (&environment, 0, sizeof (Bonobo_ActivationEnvironment));
                                                                                                                             
	a_res = Bonobo_ActivationContext_activateMatchingFull (
 				ac, specs, &reqs, &environment, 0,
                                bonobo_activation_client_get (),
				bonobo_activation_context_get (), &ev);
	switch (ev._major) {
	case CORBA_NO_EXCEPTION:
		g_print ("Activation ID \"%s\" ", a_res->aid);
		switch (a_res->res._d) {
		case Bonobo_ACTIVATION_RESULT_OBJECT:
			g_print ("RESULT_OBJECT\n");
			resior = CORBA_ORB_object_to_string (orb,
							     a_res->
							     res._u.res_object,
							     &ev);
			g_print ("%s\n", resior);
			break;
		case Bonobo_ACTIVATION_RESULT_SHLIB:
			g_print ("RESULT_SHLIB\n");
      			break;
		case Bonobo_ACTIVATION_RESULT_NONE:
			g_print ("RESULT_NONE\n");
			break;
		}
		res = 0;	
		break;
	case CORBA_USER_EXCEPTION:
		{
			char *id;
			id = CORBA_exception_id (&ev);
			g_print ("User exception \"%s\" resulted from query\n",
				 id);
			if (!strcmp (id,"IDL:Bonobo/ActivationContext/ParseFailed:1.0")) {
				Bonobo_Activation_ParseFailed
					* exdata = CORBA_exception_value (&ev);
                                if (exdata)
					g_print ("Description: %s\n",
						 exdata->description);
			} else if (!strcmp (id,"IDL:Bonobo/GeneralError:1.0")) {
				Bonobo_GeneralError *exdata;
                                                                                                                             
				exdata = CORBA_exception_value (&ev);
                                                                                                                             
				if (exdata)
					g_print ("Description: %s\n",
						 exdata->description);
			}
			res = 1;
		}
		break;
	case CORBA_SYSTEM_EXCEPTION:
		{
			char *id;
			id = CORBA_exception_id (&ev);
			g_print ("System exception \"%s\" resulted from query\n",
				 id);
			res = 1;
		}
		break;
	}
	return res;
}
int
main (int argc, char *argv[])
{
	MateComponent_ServerInfoList *result;
	CORBA_Environment ev;
	char *query;
	char **sort_criteria;
	int i;

	CORBA_exception_init (&ev);
	matecomponent_activation_init (argc, argv);

	sort_criteria = NULL;

	if (argc > 1) {
		query = argv[1];
		if (argc > 2) {
			int i;
			int num_conditions;

			num_conditions = argc - 2;

			printf ("Number of sort criteria: %d\n",
				num_conditions);

			sort_criteria =
				g_malloc (sizeof (char *) *
					  (num_conditions + 1));

			for (i = 0; i < num_conditions; i++) {
				sort_criteria[i] = g_strdup (argv[i + 2]);
				puts (sort_criteria[i]);
			}

			sort_criteria[num_conditions] = NULL;
		}
	} else {
		query = "repo_ids.has('IDL:Empty:1.0')";
	}

	/* putenv("MateComponent_BARRIER_INIT=1"); */
	result = matecomponent_activation_query (query, sort_criteria, &ev);

	/* result = matecomponent_activation_query ("iid == 'OAFIID:Empty:19991025'", NULL, &ev); */

        if (ev._major != CORBA_NO_EXCEPTION) {
                if (ev._major == CORBA_USER_EXCEPTION) {
                        if (!strcmp (ev._id, ex_MateComponent_GeneralError)) {
                                MateComponent_GeneralError *err = CORBA_exception_value (&ev);
                                printf ("An exception '%s' occurred\n", err->description);
                        } else {
                                printf ("An unknown user exception ('%s') "
                                        "occurred\n", ev._id);
                        }
                } else if (ev._major == CORBA_SYSTEM_EXCEPTION) {
                        printf ("A system exception ('%s') occurred\n", ev._id);
                } else {
                        g_assert_not_reached ();
                }
	} else if (result == NULL) {
		puts ("NULL result failed");
	} else {
		printf ("number of results: %d\n", result->_length);

		for (i = 0; i < result->_length; i++) {
			puts ((result->_buffer[i]).iid);
		}
                CORBA_free (result);
	}

	CORBA_exception_free (&ev);

        if (matecomponent_activation_debug_shutdown ()) {
                return 0;
        } else {
                return 1;
        }
}