Exemple #1
0
static void
test_rmessage(struct pbc_env *env, struct pbc_slice *slice) {
	struct pbc_rmessage * m = pbc_rmessage_new(env, "tutorial.Person", slice);
	printf("name = %s\n", pbc_rmessage_string(m , "name" , 0 , NULL));
	printf("id = %d\n", pbc_rmessage_integer(m , "id" , 0 , NULL));
	printf("email = %s\n", pbc_rmessage_string(m , "email" , 0 , NULL));

	int phone_n = pbc_rmessage_size(m, "phone");
	int i;

	for (i=0;i<phone_n;i++) {
		struct pbc_rmessage * p = pbc_rmessage_message(m , "phone", i);
		printf("\tnumber[%d] = %s\n",i,pbc_rmessage_string(p , "number", i ,NULL));
		printf("\ttype[%d] = %s\n",i,pbc_rmessage_string(p, "type", i, NULL));
	}

	int n = pbc_rmessage_size(m , "test");

	for (i=0;i<n;i++) {
		printf("test[%d] = %d\n",i, pbc_rmessage_integer(m , "test" , i , NULL));
	}

	printf("tutorial.Ext.test = %d\n", pbc_rmessage_integer(m,"tutorial.Ext.test",0,NULL));
	pbc_rmessage_delete(m);
}
Exemple #2
0
static void
_register_extension(struct pbc_env *p, struct _stringpool *pool , const char * prefix, int prefix_sz, struct pbc_rmessage * msg, pbc_array queue) {
	int extension_count = pbc_rmessage_size(msg , "extension");
	if (extension_count <= 0) 
		return;
	int i;

	const char * last = NULL;

	for (i=0;i<extension_count;i++) {
		struct pbc_rmessage * extension = pbc_rmessage_message(msg, "extension", i);
		int field_name_sz = 0;
		struct _field f;
		const char * field_name = pbc_rmessage_string(extension , "name" , 0, &field_name_sz);
		f.name =  _concat_name(pool, prefix, prefix_sz, field_name, field_name_sz, NULL);

		_register_field(extension, &f , pool);

		const char * extendee = pbc_rmessage_string(extension , "extendee" , 0, NULL);

		_pbcP_push_message(p, extendee + 1 , &f , queue);

		if (last == NULL) {
			last = extendee;
		} else if (strcmp(extendee,last) != 0) {
			_pbcP_init_message(p, last+1);
			last = extendee;
		} 
	}
	_pbcP_init_message(p, last+1);
}
Exemple #3
0
static void
test_rmessage(struct pbc_env *env, struct pbc_slice *slice) {
	struct pbc_rmessage * m = pbc_rmessage_new(env, "tutorial.Person", slice);
	if (m==NULL) {
		printf("Error : %s",pbc_error(env));
		return;
	}
	printf("name = %s\n", pbc_rmessage_string(m , "name" , 0 , NULL));
	printf("id = %d\n", pbc_rmessage_integer(m , "id" , 0 , NULL));
	printf("email = %s\n", pbc_rmessage_string(m , "email" , 0 , NULL));

	int phone_n = pbc_rmessage_size(m, "phone");
	int i;
	const char * field_name;
	pbc_type(env, "tutorial.Person", "phone", &field_name);
	printf("phone type [%s]\n",field_name);

	for (i=0;i<phone_n;i++) {
		struct pbc_rmessage * p = pbc_rmessage_message(m , "phone", i);
		printf("\tnumber[%d] = %s\n",i,pbc_rmessage_string(p , "number", i ,NULL));
		printf("\ttype[%d] = %s\n",i,pbc_rmessage_string(p, "type", i, NULL));
	}

	int n = pbc_rmessage_size(m , "test");

	for (i=0;i<n;i++) {
		printf("test[%d] = %d\n",i, pbc_rmessage_integer(m , "test" , i , NULL));
	}

	printf("tutorial.Ext.test = %d\n", pbc_rmessage_integer(m,"tutorial.Ext.test",0,NULL));
	pbc_rmessage_delete(m);
}
Exemple #4
0
static void
dump_value(struct pbc_rmessage *m, const char *key, int type, int idx, int level) {
	int i;
	for (i=0;i<level;i++) {
		printf("  ");
	}
	printf("%s",key);
	if (type & PBC_REPEATED) {
		printf("[%d]",idx);
		type -= PBC_REPEATED;
	}
	printf(" : ");

	uint32_t low;
	uint32_t hi;
	double real;
	const char *str;

	switch(type) {
	case PBC_INT:
		low = pbc_rmessage_integer(m, key, i, NULL);
		printf("%d", (int) low);
		break;
	case PBC_REAL:
		real = pbc_rmessage_real(m, key , i);
		printf("%lf", real);
		break;
	case PBC_BOOL:
		low = pbc_rmessage_integer(m, key, i, NULL);
		printf("%s", low ? "true" : "false");
		break;
	case PBC_ENUM:
		str = pbc_rmessage_string(m, key , i , NULL);
		printf("[%s]", str);
		break;
	case PBC_STRING:
		str = pbc_rmessage_string(m, key , i , NULL);
		printf("'%s'", str);
		break;
	case PBC_MESSAGE:
		printf("\n");
		dump_message(pbc_rmessage_message(m, key, i),level+1);
		return;
	case PBC_FIXED64:
		low = pbc_rmessage_integer(m, key, i, &hi);
		printf("0x%8x%8x",hi,low);
		break;
	case PBC_FIXED32:
		low = pbc_rmessage_integer(m, key, i, NULL);
		printf("0x%x",low);
		break;
	default:
		printf("unkown");
		break;
	}

	printf("\n");
}
Exemple #5
0
static void
_register(struct pbc_env *p, struct pbc_rmessage * file, struct _stringpool *pool) {
	int package_sz;
	const char *package = pbc_rmessage_string(file, "package", 0, &package_sz);

	pbc_array queue;
	_pbcA_open(queue);

	int enum_count = pbc_rmessage_size(file, "enum_type");
	int i;

	for (i=0;i<enum_count;i++) {
		struct pbc_rmessage * enum_type = pbc_rmessage_message(file, "enum_type", i);
		_register_enum(p,  pool , enum_type, package, package_sz);
	}

	int message_count = pbc_rmessage_size(file, "message_type");
	for (i=0;i<message_count;i++) {
		struct pbc_rmessage * message_type = pbc_rmessage_message(file, "message_type", i);
		_register_message(p, pool, message_type, package, package_sz, queue);
	}

	_register_extension(p, pool, package, package_sz, file , queue);

	_pbcB_register_fields(p, queue);

	_pbcA_close(queue);
}
Exemple #6
0
static void
_register_field(struct pbc_rmessage * field, struct _field * f, struct _stringpool *pool) {
	f->id = pbc_rmessage_integer(field, "number", 0 , 0);
	f->type = pbc_rmessage_integer(field, "type", 0 , 0);	// enum
	f->label = pbc_rmessage_integer(field, "label", 0, 0) - 1; // LABEL_OPTIONAL = 0
	if (pbc_rmessage_size(field , "options") > 0) {
		struct pbc_rmessage * options = pbc_rmessage_message(field, "options" , 0);
		int packed = pbc_rmessage_integer(options , "packed" , 0 , NULL);
		if (packed) {
			f->label = LABEL_PACKED;
		}
	}
	f->type_name.n = pbc_rmessage_string(field, "type_name", 0 , NULL) +1;	// abandon prefix '.' 
	int vsz;
	const char * default_value = pbc_rmessage_string(field, "default_value", 0 , &vsz);
	_set_default(pool , f , f->type, default_value , vsz);
}
Exemple #7
0
static int
_rmessage_string(lua_State *L) {
	struct pbc_rmessage * m = (struct pbc_rmessage *)checkuserdata(L,1);
	const char * key = luaL_checkstring(L,2);
	int index = lua_tointeger(L,3);
	int sz = 0;
	const char * v = pbc_rmessage_string(m,key,index,&sz);
	lua_pushlstring(L,v,sz);
	return 1;
}
Exemple #8
0
static void
_register_enum(struct pbc_env *p, struct _stringpool *pool, struct pbc_rmessage * enum_type, const char *prefix, int prefix_sz) {
	int field_count = pbc_rmessage_size(enum_type, "value");
	struct map_kv *table = malloc(field_count * sizeof(struct map_kv));
	int i;
	for (i=0;i<field_count;i++) {
		struct pbc_rmessage * value = pbc_rmessage_message(enum_type, "value", i);
		int enum_name_sz;
		const char *enum_name = pbc_rmessage_string(value , "name" , 0 , &enum_name_sz);
		table[i].pointer = (void *)_pbcS_build(pool, enum_name , enum_name_sz);
		table[i].id = pbc_rmessage_integer(value , "number", 0 , 0);
	}
	int name_sz;
	const char * name = pbc_rmessage_string(enum_type, "name", 0 , &name_sz);
	const char *temp = _concat_name(pool, prefix , prefix_sz , name , name_sz, NULL);

	_pbcP_push_enum(p,temp,table,field_count);
	free(table);
}
Exemple #9
0
static void
_register_message(struct pbc_env *p, struct _stringpool *pool, struct pbc_rmessage * message_type, const char *prefix, int prefix_sz, pbc_array queue) {
	int name_sz;
	const char * name = pbc_rmessage_string(message_type, "name", 0 , &name_sz);
	int sz = 0;
	const char *temp = _concat_name(pool, prefix , prefix_sz , name , name_sz, &sz);

	int field_count = pbc_rmessage_size(message_type, "field");
	int i;
	for (i=0;i<field_count;i++) {
		struct pbc_rmessage * field = pbc_rmessage_message(message_type, "field" , i);
		struct _field f;
		int field_name_sz;
		const char * field_name = pbc_rmessage_string(field, "name", 0 , &field_name_sz);
		f.name = _pbcS_build(pool,field_name,field_name_sz);

		_register_field(field, &f , pool);

		_pbcP_push_message(p, temp , &f , queue);
	}

	_pbcP_init_message(p, temp);

	_register_extension(p, pool, temp, sz,message_type, queue);

	// nested enum

	int enum_count = pbc_rmessage_size(message_type, "enum_type");

	for (i=0;i<enum_count;i++) {
		struct pbc_rmessage * enum_type = pbc_rmessage_message(message_type, "enum_type", i);
		_register_enum(p, pool, enum_type, temp, sz);
	}
	
	// nested type
	int message_count = pbc_rmessage_size(message_type, "nested_type");
	for (i=0;i<message_count;i++) {
		struct pbc_rmessage * nested_type = pbc_rmessage_message(message_type, "nested_type", i);
		_register_message(p, pool, nested_type, temp, sz, queue);
	}
}
Exemple #10
0
static int
_check_file_name(struct pbc_env * p , struct pbc_rmessage * file, const char ** fname) {
	const char * filename = pbc_rmessage_string(file, "name", 0, NULL);
//	printf("reg :%s\n",filename);
	if (_pbcM_sp_query(p->files, filename)) {
		return CHECK_FILE_EXIST;
	}
	int sz = pbc_rmessage_size(file, "dependency"); 
	int i;
	for (i=0;i<sz;i++) {
		const char *dname = pbc_rmessage_string(file,"dependency",i,NULL);
//		printf("dependency :%s\n",dname);
		if (_pbcM_sp_query(p->files, dname) == NULL) {
			return CHECK_FILE_DEPENDENCY;
		}
	}

	*fname = filename;

	return CHECK_FILE_OK;
}
Exemple #11
0
static void
test(struct pbc_env *env) {
	// int i;
	// for(i=0; i<COUNT; i++)
	// {
	// 		struct pbc_wmessage* w_msg = pbc_wmessage_new(env, "at");
	// 		struct pbc_rmessage* r_msg = NULL;
	// 		struct pbc_slice sl;
	// 		char buffer[1024];
	// 		sl.buffer = buffer, sl.len = 1024;
	// 		pbc_wmessage_integer(w_msg, "aa", 123, 0);
	// 		pbc_wmessage_integer(w_msg, "bb", 456, 0);
	// 		pbc_wmessage_string(w_msg, "cc", "test string!", 0);
	// 		pbc_wmessage_buffer(w_msg, &sl);

	// 		r_msg = pbc_rmessage_new(env, "at", &sl);

	// 		//===============
	// 		printf("aa = %d\n", pbc_rmessage_integer(r_msg, "aa", 0, NULL));
	// 		printf("bb = %d\n", pbc_rmessage_integer(r_msg, "bb", 0, NULL));
	// 		printf("cc = %s\n", pbc_rmessage_string(r_msg, "cc", 0, NULL));
	// 		//===============

	// 		pbc_rmessage_delete(r_msg);
	// 		pbc_wmessage_delete(w_msg);
	// }

	struct pbc_wmessage *w_msg = pbc_wmessage_new(env, "at");
	pbc_wmessage_integer(w_msg, "aa", 123, 0);
	pbc_wmessage_integer(w_msg, "bb", 456, 0); 
	pbc_wmessage_string(w_msg, "cc", "test string!", 0);

	struct pbc_slice slice;
	char buffer[1024];
	slice.len = 1024;
	slice.buffer = buffer;
	pbc_wmessage_buffer(w_msg, &slice);
	// pbc_wmessage_delete(w_msg);  //!!!!!!!! should not delete here

	struct pbc_rmessage *r_msg = pbc_rmessage_new(env, "at", &slice);
	printf("aa = %d\n", pbc_rmessage_integer(r_msg, "aa", 0, NULL));
	printf("bb = %d\n", pbc_rmessage_integer(r_msg, "bb", 0, NULL));
	printf("cc = %s\n", pbc_rmessage_string(r_msg, "cc", 0, NULL));

	pbc_rmessage_delete(r_msg);
	pbc_wmessage_delete(w_msg);
}
Exemple #12
0
static void
test_rmessage(struct pbc_env *env, struct pbc_slice *slice) {
	struct pbc_rmessage * m = pbc_rmessage_new(env, "test", slice);
	if (m==NULL) {
		printf("Error : %s",pbc_error(env));
		return;
	}

	int phone_n = pbc_rmessage_size(m, "el");
	int i;


	for (i=0;i<phone_n;i++) {
		struct pbc_rmessage * p = pbc_rmessage_message(m , "el", i);
		printf("\tint16_min[%d] = %d\n",i,pbc_rmessage_integer(p , "int16_min", i ,NULL));
		printf("\tdouble_max[%d] = %f\n",i,pbc_rmessage_real(p, "double_max", i));
		printf("\tstring[%d] = %s\n",i,pbc_rmessage_string(p, "str", i, NULL));
	}

	pbc_rmessage_delete(m);
}
static int orte_ras_yarn_allocate_internal(int np, opal_list_t* nodes) {
    int rc, i;

    // create and send allocate message
    struct pbc_wmessage* msg = pbc_wmessage_new(orte_hdclient_pb_env, "AllocateRequestProto");
    if (!msg) {
        opal_output(0, "%s ras:yarn failed to create AllocateRequestProto", 
            ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
        return ORTE_ERROR;
    }
    pbc_wmessage_integer(msg, "resource_count", np, 0);
    rc = orte_hdclient_send_message_and_delete(msg, HAMSTER_MSG_ALLOCATE);
    if (rc != 0) {
        opal_output(0, "%s ras:yarn error happened when send allocate msg to AM",
            ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
        return ORTE_ERROR;
    }

    // read rmessage out
    struct pbc_rmessage* response = orte_hdclient_recv_message("AllocateResponseProto");
    if (!response) {
        opal_output(0, "%s ras:yarn error happened when recv allocate response from AM",
            ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
        return ORTE_ERROR;
    }

    int n = pbc_rmessage_size(response, "node_resources");
    if (n <= 0) {
        opal_output(0, "%s ras:yarn got n(=%d) <= 0, please check",
            ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), n);
        return ORTE_ERROR;
    }

    // read node resources
    for (i = 0; i < n; i++) {
        struct pbc_rmessage* node_res = pbc_rmessage_message(response, "node_resources", i);
        if (!node_res) {
            opal_output(0, "%s ras:yarn error when parse returned resource from AM", 
                ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
            return ORTE_ERROR;
        }
        
        // parse host, slot
        const char* host = pbc_rmessage_string(node_res, "host_name", 0, NULL);
        if (!host) {
            opal_output(0, "%s ras:yarn error when parse host from returned resource from AM",
                ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
            return ORTE_ERROR;
        }
        int slot = pbc_rmessage_integer(node_res, "slot", 0, NULL);

        // make node_t and add it to nodes
        orte_node_t* node = OBJ_NEW(orte_node_t);
        if (!node) {
            opal_output(0, "%s ras:yarn failed to create orte_node_t obj", 
                ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
            return ORTE_ERROR;
        }

        node->name = strdup(host);
        node->state = ORTE_NODE_STATE_UP;
        node->slots_inuse = 0;
        node->slots_max = 0;
        node->slots = slot;
        opal_list_append(nodes, &node->super);

        OPAL_OUTPUT_VERBOSE((5, orte_ras_base.ras_output,
                     "%s ras:yarn: adding node %s with %d slot",
                     ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
                     host, slot));
    }

    // All done
    OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output,
                         "%s ras:yarn:allocate: success",
                         ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));

    return ORTE_SUCCESS;
}