コード例 #1
0
ファイル: routing.c プロジェクト: SimleCat/opensips
rt_data_t*
build_rt_data( void )
{
	rt_data_t *rdata=NULL;

	if( NULL==(rdata=shm_malloc(sizeof(rt_data_t)))) {
		LM_ERR("no more shm mem\n");
		goto err_exit;
	}
	memset(rdata, 0, sizeof(rt_data_t));

	INIT_PTREE_NODE(NULL, rdata->pt);

	rdata->pgw_tree = map_create( AVLMAP_SHARED );
	rdata->carriers_tree = map_create( AVLMAP_SHARED );

	if (rdata->pgw_tree == NULL || rdata->carriers_tree == NULL) {
		LM_ERR("Initializing avl failed!\n");
		if (rdata->pgw_tree)
			map_destroy(rdata->pgw_tree, 0);
		goto err_exit;

	}


	return rdata;
err_exit:
	if (rdata)
		shm_free(rdata);
	return 0;
}
コード例 #2
0
ファイル: malloc.c プロジェクト: chang-gyu/rtos
int malloc_init() {
	uint64_t start = (uint64_t)LOCAL_MALLOC_START;
	uint64_t end = (uint64_t)LOCAL_MALLOC_END; 

	__malloc_pool = (void*)start;
	init_memory_pool((uint32_t)(end - start), __malloc_pool, 0);

	#if DEBUG
	statistics = map_create(512, map_uint64_hash, map_uint64_equals, NULL);
	tracing = map_create(8192, map_uint64_hash, map_uint64_equals, NULL);
	is_debug = true;
	#endif /* DEBUG */

	return 0;
}
コード例 #3
0
ファイル: arp.c プロジェクト: GNsunghokim/rtos
static void arp_pack_func(void** state) {
	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x10c37b9309d1;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);

	uint32_t spa = 0xc0a80a6f;
	uint32_t dpa = 0xc0a80a90;
	arp_request(__nics[0], dpa, spa);

	Packet* packet = fifo_pop(__nics[0]->output_buffer); 
	uint32_t comp_size = packet->end;
	packet->end = 0;

	arp_pack(packet);

	// Checking packet->end
	assert_int_equal(comp_size, packet->end);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
コード例 #4
0
ファイル: app_ema.c プロジェクト: ArkShen/xcb
static int load_module(void) {
	load_config();
	contracts = map_create();
	if (msgs_hook(&default_msgs, ema_exec, NULL) == -1)
		return MODULE_LOAD_FAILURE;
	return register_application(app, ema_exec, desc, fmt, mod_info->self);
}
コード例 #5
0
ファイル: service.c プロジェクト: sdnnfv/loadbalancer
Service* service_alloc(Endpoint* service_endpoint) {
	bool service_add(NetworkInterface* ni, Service* service) {
		Map* services = ni_config_get(ni, SERVICES);
		if(!services) {
			services = map_create(16, NULL, NULL, ni->pool);
			if(!services)
				return false;
			if(!ni_config_put(ni, SERVICES, services))
				return false;
		}

		uint64_t key = (uint64_t)service->endpoint.protocol << 48 | (uint64_t)service->endpoint.addr << 16 | (uint64_t)service->endpoint.port;

		if(!map_put(services, (void*)key, service)) {
			if(map_is_empty(services)) {
				ni_config_remove(ni, SERVICES);
				map_destroy(services);
			}

			return false;
		} 
		printf("here???\n");

		return true;
	}
コード例 #6
0
ファイル: arp.c プロジェクト: GNsunghokim/rtos
static void arp_announce_func(void** state) {
	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x10c37b9309d1;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);

	uint32_t spa = 0xc0a80a6f;
	arp_announce(__nics[0], spa);

	Packet* packet = fifo_pop(__nics[0]->output_buffer); 
	
	assert_memory_equal(packet->buffer + packet->start, arp_announce_packet, 46);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
コード例 #7
0
ファイル: map.c プロジェクト: lee212/eucalyptus
//!
//! Initialize a given map entry with a key and value
//!
//! @param[in] m a pointer to the map entry structure
//! @param[in] key the unique key string
//! @param[in] val a transparent pointer to the value
//!
void map_set(map * m, const char *key, void *val)
{
    map *mp = NULL;

    if (m->key == NULL) {
        // empty map
        set(m, key, val);
    } else {
        // map has stuff
        for (mp = m; mp != NULL; mp = mp->next) {
            if (strcmp(key, mp->key) == 0) {
                // key already exists, overwrite it
                mp->val = val;
                return;
            } else {
                // we are at the end, so add a new entry
                if (mp->next == NULL) {
                    mp->next = map_create(1);
                    mp = mp->next;
                    if (mp != NULL)    //! @todo need to return an error if calloc failed
                        set(mp, key, val);
                    return;
                }
            }
        }
    }
}
コード例 #8
0
ファイル: map.c プロジェクト: obaltzer/group-movement
int main(int argc, char** argv)
{
    map_config_t config;
    dataset_t* dataset;
    map_t* map;

    configure(&config, argc, argv);

    if(config.ot == OT_CREATE)
    {
        dataset = dataset_load(config.infile);
        if(dataset)
        {
            map = map_create(dataset, &config.level);
            if(config.print)
                map_print(map);
            map_save(config.outfile, map);
            map_destroy(map);
        }
        dataset_destroy(&dataset);
    }
    else if(config.ot == OT_READ)
    {
        map = map_load(config.infile);
        if(config.print)
            map_print(map);
        map_destroy(map);
    }
    return 0;
}
コード例 #9
0
static string
try_fontmap P4C(const_string, font_name,
                unsigned, dpi,
		string *, glyph_paths,
                kpse_font_file_type *, font_file)
{
  static hash_table_type fontmap;
  string *mapped_names;
  string ret = NULL;

  if (fontmap.size == 0)
    { /* If we wanted to complicate our lives, we could handle separate
         maps for GF and PK ones.  I don't see that this has any
         practical utility, though, because if someone wants an alias,
         most likely the alias should apply to non-glyphs as well as
         glyphs (let alone to only GF format or PK format).  */
      const_string map_path = KPSE_GLYPH_PATH ();
      fontmap = map_create (map_path);
    }

  mapped_names = map_lookup (fontmap, font_name);
  if (mapped_names)
    {
      string mapped_name;
      while ((mapped_name = *mapped_names++) && !ret)
        {
          xputenv ("KPATHSEA_NAME", mapped_name);
          ret = try_resolution (mapped_name, dpi, glyph_paths, font_file);
        }
    }

  return ret;
}
コード例 #10
0
ファイル: socket.c プロジェクト: GNsunghokim/ipsec
bool socket_add(NetworkInterface* ni, uint32_t ip, uint16_t port, Socket* socket) {
	Map* sockets = ni_config_get(ni, SOCKETS);
	if(!sockets) {
		sockets = map_create(16, NULL, NULL, ni->pool);
		if(!sockets) {
			printf("Can'nt create socket table\n");
			return false;
		}

		if(!ni_config_put(ni, SOCKETS, sockets)) {
			map_destroy(sockets);
			return false;
		}
	}

	uint64_t key = (uint64_t)ip << 32 | (uint64_t)port;
	if(!map_put(sockets, (void*)key, socket)) {
		if(map_is_empty(sockets)) {
			map_destroy(sockets);
			ni_config_remove(ni, SOCKETS);
		}
		return false;
	}

	return true;
}
コード例 #11
0
ファイル: usr_avp.c プロジェクト: Distrotech/opensips
int init_extra_avps(void)
{
	extra_lock = lock_alloc();
	if (!extra_lock) {
		LM_ERR("cannot allocate lock\n");
		return -1;
	}
	if (!lock_init(extra_lock)) {
		LM_ERR("cannot init lock\n");
		return -1;
	}
	last_avp_index_shm = shm_malloc(sizeof(int));
	if (!last_avp_index_shm) {
		LM_ERR("not enough shm mem\n");
		return -1;
	}
	*last_avp_index_shm = last_avp_index;
	/* initialize map for dynamic avps */
	avp_map_shm = map_create(AVLMAP_SHARED);
	if (!avp_map_shm) {
		LM_ERR("cannot create shared avp_map\n");
		return -1;
	}
	return 0;
}
コード例 #12
0
ファイル: map_stuff.c プロジェクト: nohupped/map_lib
void test_strings() {   
   struct map_t *test;

   printf("\nExercising maps of strings...\n");
   printf("------\n");
   test=map_create();
   map_set(test,"One","Won");
   map_set(test,"Two","Too");
   map_set(test,"Four","Fore");


      // display them out of order
   display_both(test,"Two");
   display_both(test,"Four");
   display_both(test,"One");

   printf("\n");

      // reset an existing entry
   map_set(test,"Two","To");

   display_both(test,"Two");
   display_both(test,"Four");
   display_both(test,"One");

   printf("\n");

   display_both(test,"Eight");

   map_set(test,"Eight","Ate");

   printf("\n");

   display_both(test,"Eight");
}
コード例 #13
0
ファイル: test.c プロジェクト: carriercomm/ipsec-1
void ginit(int argc, char** argv) {
	ni = ni_get(0);
	ni->config = map_create(8, map_string_hash, map_string_equals, malloc, free);
	map_put(ni->config, "ip", (void*)(uint64_t)0xc0a80a99);	// 192.168.10.153
	map_put(ni->config, "netmask", (void*)(uint64_t)0xffffff00);

	init_list();
}
コード例 #14
0
ファイル: misc_z.c プロジェクト: GunioRobot/quickdev16
static void
init_fh_map (void)
{
  fh_map = map_create (20);                     // 20 simultaneous open files
  map_put (fh_map, stdin, &finfo_list[0]);      //  should be enough to start with
  map_put (fh_map, stdout, &finfo_list[0]);
  map_put (fh_map, stderr, &finfo_list[0]);
}
コード例 #15
0
ファイル: bfs.c プロジェクト: wqferr/P-A-T-H
void _solver_bfs_init(solver *s) {
	bfs_data *data = malloc(sizeof(*data));
	data->visited = set_create(sizeof(vec2), &vec2ref_hash, &vec2ref_comp);
	data->queue = list_create(sizeof(vec2));
	data->parent = map_create(
		sizeof(vec2), sizeof(vec2), &vec2ref_hash, &vec2ref_comp);
	solver_set_data(s, data);
}
コード例 #16
0
ファイル: lab.cpp プロジェクト: hedane/HHCARobot
/////////////////////////////////////////////
//跑1次实验
int lab_run_once(CMAP map_tpl, ROBOT &robot)
{
	MAP map = map_create(map_tpl);//拷贝地图
	int res = lab_run_once(map, robot.gene, robot.steps);
	map_destroy(map);//释放资源

	return res;
}
コード例 #17
0
ファイル: cli.c プロジェクト: campbelljc/535ospf
/*
 * This is the main routine of the CLI. Everything starts here.
 * The CLI registers and commands into a hash table and forks a thread to
 * handle the command line.
 */
int CLIInit(router_config *rarg)
{

	int stat, *jstat;

	if (!(cli_map = map_create(free)))
		return EXIT_FAILURE;

	/*
	 * Disable certain signals such as Ctrl+C.. make the shell a little stable
	 */
	redefineSignalHandler(SIGINT, dummyFunction);
	redefineSignalHandler(SIGQUIT, dummyFunction);
	redefineSignalHandler(SIGTSTP, dummyFunction);

	verbose(2, "[cliHandler]:: Registering CLI commands in the command table ");
	/*
	 * Register the commands allowed in the CLI. Each command is implemented by a
	 * function. The function is inserted into the command registary and picked up
	 * when the leading string is typed in the CLI.
	 */
	registerCLI("help", helpCmd, SHELP_HELP, USAGE_HELP, LHELP_HELP);  // Check
	registerCLI("version", versionCmd, SHELP_VERSION, USAGE_VERSION, LHELP_VERSION); // Check
	registerCLI("set", setCmd, SHELP_SET, USAGE_SET, LHELP_SET); // Check
	registerCLI("get", getCmd, SHELP_GET, USAGE_GET, LHELP_GET); // Check
	registerCLI("source", sourceCmd, SHELP_SOURCE, USAGE_SOURCE, LHELP_SOURCE); // Check
	registerCLI("ifconfig", ifconfigCmd, SHELP_IFCONFIG, USAGE_IFCONFIG, LHELP_IFCONFIG);
	registerCLI("route", routeCmd, SHELP_ROUTE, USAGE_ROUTE, LHELP_ROUTE);
	registerCLI("arp", arpCmd, SHELP_ARP, USAGE_ARP, LHELP_ARP);
	registerCLI("ping", pingCmd, SHELP_PING, USAGE_PING, LHELP_PING); // Check
	registerCLI("console", consoleCmd, SHELP_CONSOLE, USAGE_CONSOLE, LHELP_CONSOLE); // Check
	registerCLI("halt", haltCmd, SHELP_HALT, USAGE_HALT, LHELP_HALT); // Check
	registerCLI("exit", haltCmd, SHELP_EXIT, USAGE_EXIT, LHELP_EXIT); // Check
	registerCLI("queue", queueCmd, SHELP_QUEUE, USAGE_QUEUE, LHELP_QUEUE); // Check
	registerCLI("qdisc", qdiscCmd, SHELP_QDISC, USAGE_QDISC, LHELP_QDISC); // Check
	registerCLI("spolicy", spolicyCmd, SHELP_SPOLICY, USAGE_SPOLICY, LHELP_SPOLICY); // Check
	registerCLI("class", classCmd, SHELP_CLASS, USAGE_CLASS, LHELP_CLASS);
	registerCLI("filter", filterCmd, SHELP_FILTER, USAGE_FILTER, LHELP_FILTER);
	registerCLI("hello", helloCmd, SHELP_EXIT, USAGE_EXIT, LHELP_EXIT);


	if (rarg->config_dir != NULL)
		chdir(rarg->config_dir);                  // change to the configuration directory
	if (rarg->config_file != NULL)
	{
		FILE *ifile = fopen(rarg->config_file, "r");
		rl_instream = ifile;              // redirect the input stream
		CLIProcessCmds(ifile, 0);
		rl_instream = stdin;
	}

	if (rarg->cli_flag != 0)
		stat = pthread_create((pthread_t *)(&(rarg->clihandler)), NULL, CLIProcessCmdsInteractive, (void *)stdin);

	pthread_join(rarg->clihandler, (void **)&jstat);
	verbose(2, "[cliHandler]:: Destroying the CLI datastructures ");
	CLIDestroy();
}
コード例 #18
0
ファイル: driver.c プロジェクト: tuxfan/ska
int main(int argc, char *argv[])
{
	PetscErrorCode ierr;
	int i;
	grid *grd;

	MPI_Init(&argc,&argv);

	option options = parse_options(argc, argv);

	if (options.problem == JUMP) {
		grd = grid_create(-1, 1, options.nx,
		                  -1, 1, options.ny,
		                  -1, 1, options.nz);
	} else {
		grd = grid_create(0, 1, options.nx,
		                  0, 1, options.ny,
		                  0, 1, options.nz);
	}
	if (options.periodic > -1) grd->periodic[options.periodic] = 1;
	int rank;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	if (rank == 0) print_intro(&options);

	map *mp = map_create(options.map);
	grid_apply_map(grd, mp);

	problem *pb = problem_create(options.problem, grd->nd, mp->id);
	solver *sol = solver_create(grd, pb);

	ierr = solver_init(sol, grd);CHKERRQ(ierr);
	ierr = solver_run(sol);CHKERRQ(ierr);

	double *u = (double*) malloc(grd->num_pts*sizeof(double));
	double *diff = (double*) malloc(grd->num_pts*sizeof(double));
	grid_eval(grd, pb->sol, u);

	for (i = 0; i < grd->num_pts; i++)
		diff[i] = sol->state->phi[i] - u[i];

	print_norm(diff, grd->num_pts);

	free(u); free(diff);
	grid_destroy(grd); free(grd);
	map_destroy(mp); free(mp);
	problem_destroy(pb); free(pb);
	ierr = solver_destroy(sol);CHKERRQ(ierr); free(sol);

	if (options.eig && rank == 0) {
		system("./python/plot.py");
	}

	MPI_Finalize();

	return 0;
}
コード例 #19
0
ファイル: usr_avp.c プロジェクト: Distrotech/opensips
int init_global_avps(void)
{
	/* initialize map for static avps */
	avp_map = map_create(0);
	if (!avp_map) {
		LM_ERR("cannot create avp_map\n");
		return -1;
	}
	return 0;
}
コード例 #20
0
ファイル: arp.c プロジェクト: GNsunghokim/rtos
static void arp_process_func(void** state) {
	// Timer setting
	timer_init("IntelCore(TM) i5-4670 CPU @ 3.40GHz");

	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x74d4358f66cb;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);


	// Arp request
	Packet* packet = nic_alloc(__nics[0], sizeof(arp_request_packet));
	memcpy(packet->buffer + packet->start, arp_request_packet, sizeof(arp_request_packet));

	Ether* ether = (Ether*)(packet->buffer + packet->start);
	ARP* arp = (ARP*)ether->payload;
	uint32_t addr = endian32(arp->tpa);
	nic_ip_add(__nics[0], addr);

	assert_true(arp_process(packet));
	packet = fifo_pop(__nics[0]->output_buffer); 
	assert_memory_equal(packet->buffer + packet->start, arp_reply_packet, 42);

	nic_free(packet);
	packet = NULL;
	
	// Arp response
	packet = nic_alloc(__nics[0], sizeof(arp_reply_packet));
	memcpy(packet->buffer + packet->start, arp_reply_packet, sizeof(arp_reply_packet));

	ether = (Ether*)(packet->buffer + packet->start);
	arp = (ARP*)ether->payload;
	addr = endian32(arp->tpa);
	nic_ip_add(__nics[0], addr);

	uint8_t comp_mac[6] = { 0xcb, 0x66, 0x8f, 0x35, 0xd4, 0x74 }; 
	uint32_t sip = endian32(arp->spa);
	Map* arp_table = nic_config_get(packet->nic, "net.arp.arptable");
	assert_true(arp_process(packet));
	ARPEntity* entity = map_get(arp_table, (void*)(uintptr_t)sip);

	assert_memory_equal((uint8_t*)&entity->mac, comp_mac, 6);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
コード例 #21
0
struct _map * rdis_g_references (struct _rdis * rdis)
{
    struct _map * references = map_create();

    struct _graph_it * git;
    // for each node
    for (git = graph_iterator(rdis->graph); git != NULL; git = graph_it_next(git)) {
        struct _graph_node * node = graph_it_node(git);
        struct _list_it * lit;

        // for each instruction
        for (lit = list_iterator(node->data); lit != NULL; lit = lit->next) {
            struct _ins * ins = lit->data;
            struct _list_it * rit;

            // for each reference
            for (rit = list_iterator(ins->references); rit != NULL; rit = rit->next) {
                struct _reference * reference = rit->data;
                int delete_reference = 0;

                if (reference->type == REFERENCE_CONSTANT) {
                    uint64_t lower = map_fetch_max_key(rdis->memory, reference->address);
                    struct _buffer * buffer = map_fetch(rdis->memory, lower);
                    if (buffer == NULL)
                        continue;
                    uint64_t upper = lower + buffer->size;
                    if (    (reference->address < lower)
                         || (reference->address >= upper))
                        continue;
                    reference = object_copy(reference);
                    reference->type = REFERENCE_CONSTANT_ADDRESSABLE;
                    delete_reference = 1;
                }


                struct _list * ref_list = map_fetch(references, reference->address);
                if (ref_list == NULL) {
                    ref_list = list_create();
                    map_insert(references, reference->address, ref_list);
                    object_delete(ref_list);
                    ref_list = map_fetch(references, reference->address);
                }

                list_append(ref_list, reference);

                if (delete_reference)
                    object_delete(reference);
            }
        }
    }

    return references;
}
コード例 #22
0
struct _rdis * rdis_deserialize (json_t * json)
{
    json_t * graph     = json_object_get(json, "graph");
    json_t * labels    = json_object_get(json, "labels");
    json_t * functions = json_object_get(json, "functions");
    json_t * memory    = json_object_get(json, "memory");

    if (! json_is_object(graph))
        return NULL;
    if (! json_is_object(labels))
        return NULL;
    if (! json_is_object(functions))
        return NULL;
    if (! json_is_object(memory))
        return NULL;

    struct _graph * ggraph = deserialize(graph);
    if (ggraph == NULL)
        return NULL;
    struct _map * llabels = deserialize(labels);
    if (llabels == NULL) {
        object_delete(ggraph);
        return NULL;
    }
    struct _map * ffunctions = deserialize(functions);
    if (ffunctions == NULL) {
        object_delete(ggraph);
        object_delete(llabels);
        return NULL;
    }
    struct _map * mmemory = deserialize(memory);
    if (mmemory == NULL) {
        object_delete(ggraph);
        object_delete(llabels);
        object_delete(mmemory);
        return NULL;
    }

    struct _rdis * rdis = (struct _rdis *) malloc(sizeof(struct _rdis));

    rdis->object           = &rdis_object;
    rdis->callback_counter = 0;
    rdis->callbacks        = map_create();
    rdis->gui              = NULL;
    rdis->loader           = NULL;
    rdis->graph            = ggraph;
    rdis->labels           = llabels;
    rdis->functions        = ffunctions;
    rdis->memory           = mmemory;
    rdis->rdis_lua         = rdis_lua_create(rdis);

    return rdis;
}
コード例 #23
0
ファイル: main.c プロジェクト: MickaelBlet/42_zappy
int		main(int ac, char **av)
{
	t_env	e;

	srand(clock());
	init_env(&e);
	get_opt(&e, ac, av);
	srv_create(&e, e.port);
	map_create(&e);
	main_loop(&e);
	return (0);
}
コード例 #24
0
ファイル: x8664.c プロジェクト: 0day1day/rdis
struct _map * x8664_functions (uint64_t address, struct _map * memory)
{

    struct _map  * functions    = map_create();
    struct _tree * disassembled = tree_create();

    x8664_functions_r(functions, disassembled, address, memory);

    object_delete(disassembled);

    return functions;
}
コード例 #25
0
ファイル: kv_store.c プロジェクト: NormB/opensips
map_t store_deserialize(const str *input)
{
	map_t map;
	cJSON *json_map, *obj;
	str key;
	int_str_t value;

	map = map_create(AVLMAP_SHARED);
	if (!map) {
		LM_ERR("oom\n");
		return NULL;
	}

	cJSON_InitHooks(&shm_hooks);

	json_map = cJSON_Parse(input->s);
	if (!json_map) {
		LM_ERR("bad JSON input or oom\n");
		goto out;
	}

	if (json_map->type != cJSON_Object) {
		LM_BUG("non-cJSON_Object kv_store col type (%d)", json_map->type);
		goto out;
	}

	for (obj = json_map->child; obj; obj = obj->next) {
		init_str(&key, obj->string);

		switch (obj->type) {
		case cJSON_String:
			value.is_str = 1;
			init_str(&value.s, obj->valuestring);
			break;
		case cJSON_Number:
			value.is_str = 0;
			value.i = obj->valueint;
			break;
		default:
			LM_BUG("unknown obj type (%d)", obj->type);
			continue;
		}

		if (!kv_put(map, &key, &value))
			LM_ERR("oom, map will be incomplete\n");
	}

out:
	cJSON_Delete(json_map);
	cJSON_InitHooks(NULL);
	return map;
}
コード例 #26
0
ファイル: map.c プロジェクト: ajinkya93/netbsd-src
int
map_init(gpt_t gpt, off_t size)
{
	char buf[32];

	gpt->mediamap = map_create(0LL, size, MAP_TYPE_UNUSED);
	if (gpt->mediamap == NULL) {
		gpt_warn(gpt, "Can't create map");
		return -1;
	}
	gpt->lbawidth = snprintf(buf, sizeof(buf), "%ju", (uintmax_t)size);
	if (gpt->lbawidth < 5)
		gpt->lbawidth = 5;
	return 0;
}
コード例 #27
0
ファイル: lab.cpp プロジェクト: hedane/HHCARobot
/////////////////////////////////////////////
//创建多线程参数组
inline PLAB_THREAD_PARAM_GROUP lab_thread_params_create(const ROBOTS robots, time_t rnd_seed, int thread_num, CMAP map_tpl)
{
	//创建地图
	MAP map = map_create(map_tpl);

	//计算线程数量
	int rem = gConfig.lab_more_robot_count;
	int div = 0;

	//根据逻辑CPU数量分配参数
	LAB_THREAD_PARAMS params = NULL;
	if(thread_num > 1)
	{
		div = gConfig.lab_more_robot_count / thread_num;
		rem = gConfig.lab_more_robot_count % thread_num;
		//分配线程参数数组空间
		params = (LAB_THREAD_PARAMS)malloc(sizeof(LAB_THREAD_PARAM) * thread_num);
		//线程参数初始化
		for(int i=0;i<thread_num;i++)
		{
			LAB_THREAD_PARAM &param = params[i];
			param.robots = &robots[div * i]; //数组指针
			param.len = div;	//数组长度
			param.map = map;
			param.rnd_seed = rnd_seed + i + 1;
			param.no = i + 1;
		}
	}

	//单个CPU或多余的部分
	PLAB_THREAD_PARAM rem_param = NULL;
	if(rem > 0)
	{
		rem_param = (PLAB_THREAD_PARAM)malloc(sizeof(LAB_THREAD_PARAM));
		rem_param->robots = &robots[div * thread_num];
		rem_param->len = rem;
		rem_param->map = map;
		rem_param->rnd_seed = rnd_seed;
		rem_param->no = 0;
	}
	//构建返回结构
	PLAB_THREAD_PARAM_GROUP tpg = (PLAB_THREAD_PARAM_GROUP)malloc(sizeof(LAB_THREAD_PARAM_GROUP));
	tpg->map = map;
	tpg->num = thread_num;
	tpg->params = params;
	tpg->rem_param = rem_param;
	return tpg;
}
コード例 #28
0
ファイル: mapconfig.cpp プロジェクト: Ding8222/mytest
bool CMapConfig::Init()
{
	m_MapSet.resize(MAP_ID_MAX, nullptr);

	for (auto &i : CSVData::CMapDB::m_Data)
	{
		CSVData::stMap *mapinfo = i.second;
		if (mapinfo->nMapID <= 0 || mapinfo->nMapID >= static_cast<int>(m_MapSet.size()))
		{
			RunStateError("地图ID错误!");
			return false;
		}

		m_TotalMapList.insert(mapinfo->nMapID);
		
		if (mapinfo->nLineID != 0 && mapinfo->nLineID != Config.GetLineID())
		{
			continue;
		}
		
		if (m_MapSet[mapinfo->nMapID] != nullptr)
		{
			RunStateError("添加地图失败!地图ID已存在:%d", mapinfo->nMapID);
			return false;
		}

		CMapInfo* newmap = map_create();
		if (!newmap)
		{
			RunStateError("创建CMapInfo失败!");
			return false;
		}

		if (!newmap->Init(mapinfo->nMapID, mapinfo->nType, mapinfo->sMapBar.c_str()))
		{
			RunStateError("初始化加载地图阻挡失败!地图ID:%d", mapinfo->nMapID);
			delete newmap;
			return false;
		}

		newmap->SetMapBirthPoint(mapinfo->nX, mapinfo->nY, mapinfo->nZ);

		m_MapSet[mapinfo->nMapID] = newmap;
		m_MapList.push_back(newmap);
	}
		
	return true;
}
コード例 #29
0
ファイル: map.c プロジェクト: lee212/eucalyptus
//!
//! Main entry point of the application
//!
//! @param[in] argc the number of parameter passed on the command line
//! @param[in] argv the list of arguments
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
//! @note little unit test: compile with gcc -g -D_TEST_MAP map.c
//!
int main(int argc, char *argv[])
{
    char *s1 = "string 1";
    char *s2 = "string 2";
    map *m = map_create(10);

    assert(map_get(m, "foo") == NULL);
    map_set(m, "k1", s1);
    assert(map_get(m, "k1") == s1);
    map_set(m, "k2", s2);
    assert(map_get(m, "k2") == s2);
    map_set(m, "k2", s1);
    assert(map_get(m, "k2") == s1);

    return (EUCA_OK);
}
コード例 #30
0
/*
 * Initialize cache slot structure
 */
int init_slot(struct udomain* _d, hslot_t* _s, int n)
{
    _s->records = map_create( MAP_SHARED | MAP_NO_DUPLICATE);

    if( _s->records == NULL )
        return -1;

    _s->d = _d;

#ifdef GEN_LOCK_T_PREFERED
    _s->lock = &ul_locks->locks[n%ul_locks_no];
#else
    _s->lockidx = n%ul_locks_no;
#endif
    return 0;
}