예제 #1
0
파일: render.c 프로젝트: Chunjie/hilti
static hlt_string _map_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_map* map = *(hlt_map **)obj;
    const hlt_type_info* ktype = hlt_map_key_type(type, excpt, ctx);
    const hlt_type_info* vtype = hlt_map_value_type(type, excpt, ctx);

    hlt_iterator_map i = hlt_map_begin(map, excpt, ctx);
    hlt_iterator_map end = hlt_map_end(excpt, ctx);

    hlt_string sep = hlt_string_from_asciiz(": ", excpt, ctx);
    hlt_string s = hlt_string_from_asciiz("{", excpt, ctx);

    int first = 1;

    while ( ! hlt_iterator_map_eq(i, end, excpt, ctx) ) {
        void* kp = hlt_iterator_map_deref_key(i, excpt, ctx);
        void* vp = hlt_iterator_map_deref_value(i, excpt, ctx);
        hlt_string ks = _object_to_string(ktype, kp, seen, excpt, ctx);
        hlt_string vs = _object_to_string(vtype, vp, seen, excpt, ctx);

        if ( ! first )
            s = hlt_string_concat_asciiz(s, ", ", excpt, ctx);

        s = hlt_string_concat(s, ks, excpt, ctx);
        s = hlt_string_concat(s, sep, excpt, ctx);
        s = hlt_string_concat(s, vs, excpt, ctx);

        i = hlt_iterator_map_incr(i, excpt, ctx);
        first = 0;
    }

    s = hlt_string_concat_asciiz(s, "}", excpt, ctx);

    return s;
}
예제 #2
0
파일: render.c 프로젝트: Chunjie/hilti
static hlt_string _list_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_list* list = *(hlt_list **)obj;
    const hlt_type_info* etype = hlt_list_element_type(type, excpt, ctx);

    hlt_iterator_list i = hlt_list_begin(list, excpt, ctx);
    hlt_iterator_list end = hlt_list_end(list, excpt, ctx);

    hlt_string s = hlt_string_from_asciiz("[", excpt, ctx);

    int first = 1;

    while ( ! hlt_iterator_list_eq(i, end, excpt, ctx) ) {
        void* ep = hlt_iterator_list_deref(i, excpt, ctx);
        hlt_string es = _object_to_string(etype, ep, seen, excpt, ctx);

        if ( ! first )
            s = hlt_string_concat_asciiz(s, ", ", excpt, ctx);

        s = hlt_string_concat(s, es, excpt, ctx);

        i = hlt_iterator_list_incr(i, excpt, ctx);
        first = 0;
    }

    s = hlt_string_concat_asciiz(s, "]", excpt, ctx);

    return s;
}
예제 #3
0
파일: render.c 프로젝트: Chunjie/hilti
static hlt_string _tuple_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    void* tuple = obj;

    hlt_string s = hlt_string_from_asciiz("(", excpt, ctx);

    for ( int i = 0; i < hlt_tuple_length(type, excpt, ctx); i++ ) {
        void* ev = hlt_tuple_get(type, tuple, i, excpt, ctx);
        hlt_tuple_element et = hlt_tuple_get_type(type, i, excpt, ctx);

        if ( i > 0 )
            s = hlt_string_concat_asciiz(s, ", ", excpt, ctx);

        if ( et.name && *et.name ) {
            hlt_string n = hlt_string_from_asciiz(et.name, excpt, ctx);
            s = hlt_string_concat(s, n, excpt, ctx);
            s = hlt_string_concat_asciiz(s, "=", excpt, ctx);
        }

        hlt_string es = _object_to_string(et.type, ev, seen, excpt, ctx);
        s = hlt_string_concat(s, es, excpt, ctx);
    }

    s = hlt_string_concat_asciiz(s, ")", excpt, ctx);

    return s;
}
예제 #4
0
파일: render.c 프로젝트: Chunjie/hilti
hlt_string binpac_object_to_string(const hlt_type_info* type, void* obj, hlt_exception** excpt, hlt_execution_context* ctx)
{
    __hlt_pointer_stack seen;
    __hlt_pointer_stack_init(&seen);

    hlt_string s = _object_to_string(type, obj, &seen, excpt, ctx);

    __hlt_pointer_stack_destroy(&seen);

    return s;
}
예제 #5
0
파일: render.c 프로젝트: Chunjie/hilti
static hlt_string _unit_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    void* unit = *(void**)obj;

    if ( ! unit )
        return hlt_string_from_asciiz("(Null)", excpt, ctx);

    binpac_unit_cookie cookie = 0;
    binpac_unit_item item;

    int first = 1;

    hlt_string v;
    hlt_string s = hlt_string_from_asciiz("<", excpt, ctx);

    while ( (cookie = binpac_unit_iterate(&item, type, unit, 0, cookie, excpt, ctx)) ) {

        if ( ! item.value )
            // Don't print fields that aren't set.
            continue;

        if ( ! first )
            s = hlt_string_concat_asciiz(s, ", ", excpt, ctx);

        if ( item.name )
            s = hlt_string_concat_asciiz(s, item.name, excpt, ctx);
        else
            s = hlt_string_concat_asciiz(s, "<\?\?\?>", excpt, ctx);

        s = hlt_string_concat_asciiz(s, "=", excpt, ctx);

        v = item.value ? _object_to_string(item.type, item.value, seen, excpt, ctx)
                       : hlt_string_from_asciiz("(not set)", excpt, ctx);

        s  = hlt_string_concat(s, v, excpt, ctx);

        first = 0;
    }

    s = hlt_string_concat_asciiz(s, ">", excpt, ctx);

    return s;
}
main()
{
    FILE          *fileref;
    char          *exID;
    Environment   ev;
    Bar           barObj;
    long          test_long;
    long          count;
    string        stringref;
    string        return_string;
    string        arg1;
    long          arg2 = 210;
    ReferenceData arg3;

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

    /*
     *  test to see if the object exists
     */

    if ( !(fileref = fopen("fileref","r")) )
    {
        /*
	 *  if the object doesn't exist, create the object remotely  -
	 *  the local proxy is loaded by the runtime
	 */

	barObj = somdCreate(&ev, "Bar", TRUE);
	if ( CheckEv(ev) ) goto process_error;

	stringref = _object_to_string (SOMD_ORBObject,&ev,(SOMDObject) barObj);
	if ( CheckEv(ev) ) goto process_error;

	fileref = fopen("fileref", "w");
	fprintf(fileref, "%s", stringref);
	fclose(fileref);
	somPrintf("Created an object of class Bar\n");
    }
    else
    {
	/*
	 *  object does exist so use string_to_object to load the proxy
	 */

	stringref = (string) SOMMalloc(1024);
	fscanf(fileref, "%s", stringref);
	barObj = (Bar) _string_to_object(SOMD_ORBObject, &ev, stringref);
	if ( CheckEv(ev) ) goto process_error;
	somPrintf("Found reference to an object of class Bar\n");
    }

    test_long = Bar__get_attribute_long(barObj, &ev);
    if ( CheckEv(ev) ) goto process_error;
    somPrintf("Initial attribute_long = %d\n", test_long);

    /* set, get and print long attribute */
    Bar__set_attribute_long(barObj, &ev, 8888);
    test_long = Bar__get_attribute_long(barObj, &ev);
    if ( CheckEv(ev) ) goto process_error;
    somPrintf("Modified attribute_long = %d\n", test_long);

    arg3._maximum = 1024;
    arg3._length = sizeof("ReferenceData");
    arg3._buffer = (octet *) "ReferenceData";

    somPrintf("Invoking remote Bar method1\n");
    return_string = Bar_method1(barObj, &ev, &arg1, &arg2, &arg3);
    if ( CheckEv(ev) ) goto process_error;

    somPrintf("Should return: 'method1 completed', 'abc', 1234\n");
    somPrintf("return_string = %s\n", return_string);
    somPrintf("arg1 = %s\n", arg1);
    somPrintf("arg2 = %d\n\n", arg2);

    for (count = 0; count < 5; count++)
    {
	DosSleep(100);
	Bar__set_attribute_long(barObj, &ev, count);
	test_long = Bar__get_attribute_long(barObj, &ev);
	if ( CheckEv(ev) ) goto process_error;
	somPrintf("Incremented attribute_long = %d\n", test_long);
    };

    /* Release local barObj and exit */

    _release(barObj, &ev);
    SOMD_Uninit(&ev);
    SOM_UninitEnvironment(&ev);
    return(0);

process_error:
    exID = somExceptionId(&ev);

    if ( ev._major == SYSTEM_EXCEPTION )
    {
       somPrintf("System exception: %s\n", exID);

       if ( strcmp(ev.exception._exception_name, "INV_OBJREF") == 0 )
       {
	  somPrintf("Object reference no longer valid.\n");
	  somPrintf("Delete the file named fileref and rerun sample program.\n");
       }
    }
    else if ( ev._major == USER_EXCEPTION )
    {
       somPrintf("User exception: %s\n", exID);
    }

    somdExceptionFree(&ev);
    if (barObj != NULL) _release(barObj,&ev);
    SOMD_Uninit(&ev);
    SOM_UninitEnvironment(&ev);
    return(1);
}