Example code

Following is an incomplete example showing how to use the DII to invoke a request having the method procedure prototype shown here:

string _testMethod( testObject              obj,
                    Environment             *ev,
                    long                    input_value,
);
main()
{
   ORBStatus rc;
   Environment ev;
   SOMDObject obj;
   NVList arglist;
   NamedValue result;
   Context ctx;
   Request reqObj;
   OperationDef opdef;
   Description desc;
   OperationDescription opdesc;
   static long input_value = 999;

   SOM_InitEnvironment(&ev);
   SOMD_Init(&ev);

/* create the argument list */
/* get the operation description from the interface repository */
   opdef = _lookup_id(SOM_InterfaceRepository, *ev,
                  "testObject::testMethod");
   desc = _describe(opdef, &ev);
   opdesc = (OperationDescription *) desc.value._value;

/* fill in the TypeCode field for the result */
   result.argument._type = opdesc->result;

/* Initialize the argument list */
   rc = _create_operation_list(SOMD_ORBObject, &ev, opdef,
                               &arglist);

/* get default context */
   rc = _get_default_context(SOMD_ORBObject, &ev, &ctx);

/* put value and length into the NVList */
   _get_item(arglist, &ev, 0, &name, &tc, &dummy, &dummylen,
             &flags);

   _set_item(arglist, &ev, 0, name, tc, &input_value,
             sizeof(input_value),flags);
    ...
/* create the request - assume the object reference came from
   somewhere -- from a file or returned by a previous request*/
   rc = _create_request(obj, &ev, ctx,
                        "testMethod", arglist, &result, &reqObj,
                        (Flags)0);
/* invoke request */
   rc = invoke(reqObj, &ev, (Flags)0);

/* print result */
   printf("result: %s\n",*(string*)(result.argument._value));
   return(0);
}


[Back: Initiating a Request]
[Next: Creating user-supplied proxies]