void client_create(client_t **cli, poll_mgr_t *mgr) { *cli = (client_t *) malloc(sizeof(client_t)); client_t *c = *cli; rpc_common_create(&c->comm); poll_job_create(&c->pjob); c->pjob->do_read = handle_client_read; c->pjob->do_write = handle_client_write; c->pjob->holder = c; c->pjob->mgr = (mgr != NULL) ? mgr : mgr_; buf_create(&c->buf_recv); buf_create(&c->buf_send); LOG_DEBUG("a new client created."); }
void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me) { float sortbuf, glob, i; string fn; glob = search_begin(language_filename(get_model_datafilename(string_null, -1, "txt")), TRUE, TRUE); if (glob < 0) return; me.configureXonoticImage(me, string_null, -1); sortbuf = buf_create(); for(i = 0; i < search_getsize(glob); ++i) { // select model #i! fn = search_getfilename(glob, i); if(!get_model_parameters(fn, -1)) continue; bufstr_add(sortbuf, sprintf("%-128s%s", get_model_parameters_name, fn), 1); } search_end(glob); buf_sort(sortbuf, 128, 0); me.numModels = buf_getsize(sortbuf); me.bufModels = buf_create(); for(i = 0; i < me.numModels; ++i) { fn = substring(bufstr_get(sortbuf, i), 128, -1); if(!get_model_parameters(fn, -1)) error("But it JUST worked!"); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_TITLE, get_model_parameters_name); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_IMAGE, strcat("/", substring(get_model_datafilename(get_model_parameters_modelname, get_model_parameters_modelskin, "tga"), 0, -5))); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_MODEL, get_model_parameters_modelname); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_SKIN, ftos(get_model_parameters_modelskin)); get_model_parameters_desc = strcat(get_model_parameters_desc, "\n"); if(get_model_parameters_sex) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nSex: %s", get_model_parameters_sex)); if(get_model_parameters_weight) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nWeight: %g kg", get_model_parameters_weight)); if(get_model_parameters_age) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nAge: %g", get_model_parameters_age)); while(substring(get_model_parameters_desc, -1, 1) == "\n") get_model_parameters_desc = substring(get_model_parameters_desc, 0, -2); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_DESC, get_model_parameters_desc); } buf_del(sortbuf); get_model_parameters(string_null, 0); me.loadCvars(me); // this will select the initial model, depending on the current cvars me.go(me, 0); // this will set the vars for the selected model }
/* * utilities */ static void test_setup(void) { req = request_create(); rsp = response_create(); buf = buf_create(); }
void XonoticPlayerList_setPlayerList(entity me, string plist) { float buf,i,n; string s; buf = buf_create(); me.nItems = tokenizebyseparator(plist, "\n"); for(i = 0; i < me.nItems; ++i) { bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(i)); // -666 100 "^4Nex ^2Player" } for(i = 0; i < me.nItems; ++i) { s = bufstr_get(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME); n = tokenize_console(s); if(n == 4) { bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING, argv(1)); // 100 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, argv(2)); // 0 for spec, else 1, 2, 3, 4 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(3)); // ^4Nex ^2Player } else { bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING, argv(1)); // 100 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, "-1"); bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(2)); // ^4Nex ^2Player } } me.playerList = buf; }
/* description: chann r from local listen */ static void _local_chann_open(chann_t *r) { tun_local_t *tun = _tun_local(); tun_local_chann_t *c = NULL; if (lst_count(tun->free_lst) > 0) { c = lst_popf(tun->free_lst); } else { c = (tun_local_chann_t*)mm_malloc(sizeof(*c)); c->bufin = buf_create(TUNNEL_CHANN_BUF_SIZE); assert(c->bufin); c->chann_id = tun->chann_idx; tun->chann_idx += 1; } tun->channs[c->chann_id] = c; c->magic = (++tun->magic_code); c->tcpin = r; c->node = lst_pushl(tun->active_lst ,c); if (tun->mode == TUNNEL_LOCAL_MODE_FRONT) { c->state = LOCAL_CHANN_STATE_WAIT_LOCAL; /* wait local connect cmd */ mnet_chann_set_cb(c->tcpin, _local_chann_tcpin_cb_front, c); } /* _verbose("chann %d:%d open, [a:%d,f:%d]\n", c->chann_id, c->magic, */ /* lst_count(tun->active_lst), lst_count(tun->free_lst)); */ }
void configureNexuizCvarListNexuizCvarList(entity me) { me.configureNexuizListBox(me); me.handle = buf_create(); buf_cvarlist(me.handle, "", "_"); me.nItems = buf_getsize(me.handle); }
void PKT_init(PTInstVar pvar) { buf_create(&pvar->pkt_state.buf, &pvar->pkt_state.buflen); pvar->pkt_state.datastart = 0; pvar->pkt_state.datalen = 0; pvar->pkt_state.seen_server_ID = FALSE; pvar->pkt_state.seen_newline = FALSE; pvar->pkt_state.predecrypted_packet = FALSE; }
static struct pipe_resource * ilo_resource_create(struct pipe_screen *screen, const struct pipe_resource *templ) { if (templ->target == PIPE_BUFFER) return buf_create(screen, templ); else return tex_create(screen, templ, NULL); }
void sconn_create(sconn_t **sconn, server_t *svr) { *sconn = (sconn_t *) malloc(sizeof(sconn_t)); sconn_t *sc = *sconn; sc->tp = svr->tp; rpc_common_create(&sc->comm); sc->comm->ht = svr->comm->ht; // TODO should be copy. poll_job_create(&sc->pjob); sc->pjob->do_read = handle_sconn_read; sc->pjob->do_write = handle_sconn_write; sc->pjob->holder = sc; sc->pjob->mgr = svr->pjob->mgr; buf_create(&sc->buf_recv); buf_create(&sc->buf_send); }
void *X11_init_unspoofing_filter(PTInstVar pvar, X11AuthData FAR * auth_data) { X11UnspoofingFilterClosure FAR *closure = malloc(sizeof(X11UnspoofingFilterClosure)); closure->pvar = pvar; closure->auth_data = auth_data; closure->init_data_len = 0; buf_create(&closure->init_buf, &closure->init_buf_len); return closure; }
char *mfn_symbolName(MFN *p) { if (p->cname == NULL) { int i; int argc = vec_size(p->argv); StringBuffer *buf = buf_create(32); /* If the classname is not null then this is a method and the classname should prefix the generated cname */ if (p->classn != NULL) buf_printf(buf, "_%s",p->classn); /* If the fname starts with '~' (i.e. this is a destructor) convert it into an '_' */ if (p->fname[0] == '~') buf_printf(buf,"__%s__", p->fname+1); else buf_printf(buf, "_%s__", p->fname); for (i = 0; i < argc; i++) { FNArg *arg = (FNArg *)vec_get(p->argv, i); int l = strlen(arg->type); /* Output one P for each dimension of an array argument */ while(arg->type[l-1] == ']'){ buf_putc(buf,'P'); l -= 2; } /* For built in types output the first letter of the type name for the argument */ if(l == 3 && !strncmp(arg->type,"int",l)) buf_putc(buf,'i'); else if(l == 5 && !strncmp(arg->type,"float",l)) buf_putc(buf,'f'); else if(l == 6 && !strncmp(arg->type,"double",l)) buf_putc(buf,'d'); else if(l == 4 && !strncmp(arg->type,"char",l)) buf_putc(buf,'c'); else if(l == 4 && !strncmp(arg->type,"long",l)) buf_putc(buf,'l'); else if(l == 7 && !strncmp(arg->type,"boolean",l)) buf_putc(buf,'b'); else if(l == 4 && !strncmp(arg->type,"byte",l)) buf_putc(buf,'y'); else if(l == 6 && !strncmp(arg->type,"String",l)) buf_putc(buf,'S'); else if(l == 6 && !strncmp(arg->type,"Object",l)) buf_putc(buf,'O'); else if(arg->type[l-1] == ')') buf_putc(buf,'F'); else { buf_puti(buf, l); buf_put(buf,arg->type,l); } } p->cname = buf_toString(buf); buf_free(buf); } return p->cname; }
int main() { FILE *tp = fopen("db_file.txt", "wb"); fwrite("abcdBbcdaD", sizeof(unsigned char), 10, tp); fclose(tp); tuple_buffer* p = buf_create("db_file.txt"); printf("%d\n", buf_get_int(p)); printf("%c\n", buf_get_char(p)); printf("%d\n", buf_get_int(p)); printf("%c\n", buf_get_char(p)); buf_remove(p); printf("%d\n",0x64636261); printf("%d\n", 0x61646362); return 0; }
JSBool js_cache_put(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { char stash[256]; const char *key,*lstash; uint32_t len, maxage; JSObject *o; htsbuf_queue_t out; js_plugin_t *jsp = JS_GetPrivate(cx, obj); if (!JS_ConvertArguments(cx, argc, argv, "ssou", &lstash, &key, &o, &maxage)) return JS_FALSE; if (o == NULL) { JS_ReportError(cx, "Not an object"); return JS_FALSE; } // json encode object htsbuf_queue_init(&out, 0); if (js_json_encode_from_object(cx, o, &out) != 0) { JS_ReportError(cx, "Not an JSON object"); return JS_FALSE; } len = out.hq_size; buf_t *b = buf_create(len + 1); htsbuf_read(&out, b->b_ptr, len); buf_str(b)[len] = '\0'; // put json encoded object onto cache snprintf(stash, sizeof(stash), "plugin/%s/%s", jsp->jsp_id, lstash); blobcache_put(key, stash, b, maxage, NULL, 0, 0); buf_release(b); return JS_TRUE; }
int main(int argc, char **argv) { // Standard command line parsing. HASH_T *options = parse_cmdline(argc, argv, arg_opts); if(options == NULL || hash_get(options, "help") != NULL) { show_usage(argc, argv, arg_opts); return 1; } char *url = hash_get(options, "url"); const char *principal = hash_get(options, "principal"); CREDENTIALS_T *credentials = NULL; const char *password = hash_get(options, "credentials"); if(password != NULL) { credentials = credentials_create_password(password); } char *topic = hash_get(options, "topic"); // Setup for condition variable. apr_initialize(); apr_pool_create(&pool, NULL); apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool); apr_thread_cond_create(&cond, pool); // Create a session with Diffusion. SESSION_T *session = NULL; DIFFUSION_ERROR_T error; session = session_create(url, principal, credentials, NULL, NULL, &error); if(session == NULL) { fprintf(stderr, "TEST: Failed to create session\n"); fprintf(stderr, "ERR : %s\n", error.message); return 1; } // Create a payload. char *data = hash_get(options, "data"); BUF_T *payload = buf_create(); buf_write_bytes(payload, data, strlen(data)); // Build up some headers to send with the message. LIST_T *headers = list_create(); list_append_last(headers, "apple"); list_append_last(headers, "train"); // Parameters for send_msg() call. SEND_MSG_PARAMS_T params = { .topic_path = topic, .payload = *payload, .headers = headers, .priority = CLIENT_SEND_PRIORITY_NORMAL, .on_send = on_send, .context = "FOO" }; // Send the message and wait for the callback to acknowledge delivery. apr_thread_mutex_lock(mutex); send_msg(session, params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); // Politely close the client connection. session_close(session, &error); return 0; }
/* * Program entry point. */ int main(int argc, char** argv) { /* * Standard command-line parsing. */ const HASH_T *options = parse_cmdline(argc, argv, arg_opts); if(options == NULL || hash_get(options, "help") != NULL) { show_usage(argc, argv, arg_opts); return EXIT_FAILURE; } const char *url = hash_get(options, "url"); const char *principal = hash_get(options, "principal"); CREDENTIALS_T *credentials = NULL; const char *password = hash_get(options, "credentials"); if(password != NULL) { credentials = credentials_create_password(password); } const char *topic_name = hash_get(options, "topic"); const long seconds = atol(hash_get(options, "seconds")); /* * Setup for condition variable. */ apr_initialize(); apr_pool_create(&pool, NULL); apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool); apr_thread_cond_create(&cond, pool); /* * Create a session with the Diffusion server. */ SESSION_T *session; DIFFUSION_ERROR_T error = { 0 }; session = session_create(url, principal, credentials, NULL, NULL, &error); if(session == NULL) { fprintf(stderr, "TEST: Failed to create session\n"); fprintf(stderr, "ERR : %s\n", error.message); return EXIT_FAILURE; } /* * Create a topic holding simple string content. */ TOPIC_DETAILS_T *string_topic_details = create_topic_details_single_value(M_DATA_TYPE_STRING); const ADD_TOPIC_PARAMS_T add_topic_params = { .topic_path = topic_name, .details = string_topic_details, .on_topic_added = on_topic_added, .on_topic_add_failed = on_topic_add_failed, .on_discard = on_topic_add_discard, }; apr_thread_mutex_lock(mutex); add_topic(session, add_topic_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); topic_details_free(string_topic_details); /* * Define the handlers for add_update_source() */ const UPDATE_SOURCE_REGISTRATION_PARAMS_T update_reg_params = { .topic_path = topic_name, .on_init = on_update_source_init, .on_registered = on_update_source_registered, .on_active = on_update_source_active, .on_standby = on_update_source_standby, .on_close = on_update_source_closed }; /* * Register an updater. */ apr_thread_mutex_lock(mutex); CONVERSATION_ID_T *updater_id = register_update_source(session, update_reg_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Define default parameters for an update source. */ UPDATE_SOURCE_PARAMS_T update_source_params_base = { .updater_id = updater_id, .topic_path = topic_name, .on_success = on_update_success, .on_failure = on_update_failure }; time_t end_time = time(NULL) + seconds; while(time(NULL) < end_time) { if(active) { /* * Create an update structure containing the current time. */ BUF_T *buf = buf_create(); const time_t time_now = time(NULL); buf_write_string(buf, ctime(&time_now)); CONTENT_T *content = content_create(CONTENT_ENCODING_NONE, buf); UPDATE_T *upd = update_create(UPDATE_ACTION_REFRESH, UPDATE_TYPE_CONTENT, content); UPDATE_SOURCE_PARAMS_T update_source_params = update_source_params_base; update_source_params.update = upd; /* * Update the topic. */ update(session, update_source_params); content_free(content); update_free(upd); buf_free(buf); } sleep(1); } if(active) { UPDATE_SOURCE_DEREGISTRATION_PARAMS_T update_dereg_params = { .updater_id = updater_id, .on_deregistered = on_update_source_deregistered }; apr_thread_mutex_lock(mutex); deregister_update_source(session, update_dereg_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); } /* * Close session and free resources. */ session_close(session, NULL); session_free(session); conversation_id_free(updater_id); credentials_free(credentials); apr_thread_mutex_destroy(mutex); apr_thread_cond_destroy(cond); apr_pool_destroy(pool); apr_terminate(); return EXIT_SUCCESS; }
struct buf *buf_from_cstr(char *s) { struct buf *buf = buf_create(max(1, strlen(s)) * 2); buf_append(buf, s); return buf; }
int main(int argc, char** argv) { /* * Standard command-line parsing. */ HASH_T *options = parse_cmdline(argc, argv, arg_opts); if(options == NULL || hash_get(options, "help") != NULL) { show_usage(argc, argv, arg_opts); return EXIT_FAILURE; } char *url = hash_get(options, "url"); const char *principal = hash_get(options, "principal"); CREDENTIALS_T *credentials = NULL; const char *password = hash_get(options, "credentials"); if(password != NULL) { credentials = credentials_create_password(password); } // Setup for condition variable apr_initialize(); apr_pool_create(&pool, NULL); apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool); apr_thread_cond_create(&cond, pool); // Setup for session SESSION_T *session; DIFFUSION_ERROR_T error = { 0 }; session = session_create(url, principal, credentials, NULL, NULL, &error); if(session == NULL) { fprintf(stderr, "TEST: Failed to create session\n"); fprintf(stderr, "ERR : %s\n", error.message); return EXIT_FAILURE; } // Common params for all add_topic() functions. ADD_TOPIC_PARAMS_T common_params = { .on_topic_added = on_topic_added, .on_topic_add_failed = on_topic_add_failed, .on_discard = on_topic_add_discard }; /* * Create a stateless topic. */ TOPIC_DETAILS_T *topic_details = create_topic_details_stateless(); ADD_TOPIC_PARAMS_T stateless_params = common_params; stateless_params.topic_path = "stateless"; stateless_params.details = topic_details; apr_thread_mutex_lock(mutex); add_topic(session, stateless_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Create a topic with single value string data, but with * containing no default data. */ TOPIC_DETAILS_T *string_topic_details = create_topic_details_single_value(M_DATA_TYPE_STRING); ADD_TOPIC_PARAMS_T string_params = common_params; string_params.topic_path = "string"; string_params.details = string_topic_details; apr_thread_mutex_lock(mutex); add_topic(session, string_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Create a topic with single value string data and containing * some default data. */ ADD_TOPIC_PARAMS_T string_data_params = common_params; string_data_params.topic_path = "string-data"; string_data_params.details = string_topic_details; BUF_T *sample_data_buf = buf_create(); buf_write_string(sample_data_buf, "Hello, world"); string_data_params.content = content_create(CONTENT_ENCODING_NONE, sample_data_buf); apr_thread_mutex_lock(mutex); add_topic(session, string_data_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Create a topic with single value integer data, and with a * default value. */ TOPIC_DETAILS_T *integer_topic_details = create_topic_details_single_value(M_DATA_TYPE_INTEGER_STRING); integer_topic_details->topic_details_params.integer.default_value = 999; ADD_TOPIC_PARAMS_T integer_params = common_params; integer_params.topic_path = "integer"; integer_params.details = integer_topic_details; apr_thread_mutex_lock(mutex); add_topic(session, integer_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Create a topic with integer data, but using a CONTENT_T to * specify the initial data. */ ADD_TOPIC_PARAMS_T integer_data_params = common_params; integer_data_params.topic_path = "integer-data"; integer_data_params.details = integer_topic_details; BUF_T *integer_data_buf = buf_create(); buf_sprintf(integer_data_buf, "%d", 123); integer_data_params.content = content_create(CONTENT_ENCODING_NONE, integer_data_buf); apr_thread_mutex_lock(mutex); add_topic(session, integer_data_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Create a topic with single value decimal data, with a * default value and specifying the scale (i.e. positions * after the decimal place). */ TOPIC_DETAILS_T *decimal_topic_details = create_topic_details_single_value(M_DATA_TYPE_DECIMAL_STRING); decimal_topic_details->topic_details_params.decimal.default_value = 123.456; decimal_topic_details->topic_details_params.decimal.scale = 4; ADD_TOPIC_PARAMS_T decimal_params = common_params; decimal_params.topic_path = "decimal"; decimal_params.details = decimal_topic_details; apr_thread_mutex_lock(mutex); add_topic(session, decimal_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Create a topic with decimal data, using a CONTENT_T to * specify the initial data. */ ADD_TOPIC_PARAMS_T decimal_data_params = common_params; decimal_data_params.topic_path = "decimal-data"; decimal_data_params.details = decimal_topic_details; BUF_T *decimal_data_buf = buf_create(); buf_sprintf(decimal_data_buf, "%f", 987.654); decimal_data_params.content = content_create(CONTENT_ENCODING_NONE, decimal_data_buf); apr_thread_mutex_lock(mutex); add_topic(session, decimal_data_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Record topic data. * * The C API does not have the concept of "builders" for * creating record topic data, but requires you to build a * string containing XML that describes the structure of the * messages. */ /* * First of all, this adds a topic equivalent to single-value * strings, but defined with XML. */ BUF_T *manual_schema = buf_create(); buf_write_string(manual_schema, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"); buf_write_string(manual_schema, "<field name=\"x\" type=\"string\" default=\"xyzzy\" allowsEmpty=\"true\"/>"); TOPIC_DETAILS_T *manual_topic_details = create_topic_details_single_value(M_DATA_TYPE_STRING); manual_topic_details->user_defined_schema = manual_schema; ADD_TOPIC_PARAMS_T string_manual_params = common_params; string_manual_params.topic_path = "string-manual"; string_manual_params.details = manual_topic_details; apr_thread_mutex_lock(mutex); add_topic(session, string_manual_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * This adds a topic with a record containing multiple fields * of different types. */ BUF_T *record_schema = buf_create(); buf_write_string(record_schema, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); buf_write_string(record_schema, "<message topicDataType=\"record\" name=\"MyContent\">"); buf_write_string(record_schema, "<record name=\"Record1\">"); buf_write_string(record_schema, "<field type=\"string\" default=\"\" allowsEmpty=\"true\" name=\"Field1\"/>"); buf_write_string(record_schema, "<field type=\"integerString\" default=\"0\" allowsEmpty=\"false\" name=\"Field2\"/>"); buf_write_string(record_schema, "<field type=\"decimalString\" default=\"0.00\" scale=\"2\" allowsEmpty=\"false\" name=\"Field3\"/>"); buf_write_string(record_schema, "</record>"); buf_write_string(record_schema, "</message>"); TOPIC_DETAILS_T *record_topic_details = create_topic_details_record(); record_topic_details->user_defined_schema = record_schema; ADD_TOPIC_PARAMS_T record_params = common_params; record_params.topic_path = "record"; record_params.details = record_topic_details; apr_thread_mutex_lock(mutex); add_topic(session, record_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * We can also remove topics. First, add a couple of topics * and then remove their parent topic. All child topics are * removed with the parent. */ puts("Adding topics remove_me/1 and remove_me/2"); ADD_TOPIC_PARAMS_T topic_params = common_params; topic_params.details = topic_details; topic_params.topic_path = "remove_me/1"; apr_thread_mutex_lock(mutex); add_topic(session, topic_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); topic_params.topic_path = "remove_me/2"; apr_thread_mutex_lock(mutex); add_topic(session, topic_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); puts("Removing topics in 5 seconds..."); sleep(5); REMOVE_TOPICS_PARAMS_T remove_params = { .on_removed = on_topic_removed, .on_discard = on_topic_remove_discard, .topic_selector = ">remove_me" }; apr_thread_mutex_lock(mutex); remove_topics(session, remove_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Close our session, and release resources and memory. */ session_close(session, NULL); session_free(session); apr_thread_mutex_destroy(mutex); apr_thread_cond_destroy(cond); apr_pool_destroy(pool); apr_terminate(); return EXIT_SUCCESS; }
MotoEnv * moto_createEnv(int flags,char* filename) { MotoEnv *env = (MotoEnv *)emalloc(sizeof(MotoEnv)); env->flags = flags; env->filename = filename; if (flags & MMAN_LEVEL1_FLAG) { env->mman_level = 1; } else if (flags & MMAN_LEVEL2_FLAG) { env->mman_level = 2; } else { env->mman_level = 0; } env->mpool = mpool_create(2048); env->valpool = opool_createWithExt( (void*(*)())moto_createEmptyVal, NULL, NULL, NULL, env, 10 ); env->bufpool = opool_create( (void*(*)())buf_createDefault, (void(*)(void*))buf_free, (void(*)(void*))buf_clear, NULL, 10 ); env->stkpool = opool_create( (void*(*)())stack_createDefault, (void(*)(void*))stack_free, NULL, NULL, 10 ); env->fcache = stab_createDefault(); env->tree = moto_createTree(); env->ptrs = hset_createDefault(); env->out = buf_create(DEFAULT_BUF_SIZE); env->err = buf_create(DEFAULT_BUF_SIZE); env->types = stab_createDefault(); env->cdefs = stab_createDefault(); env->ccdef = NULL; env->globals = stab_createDefault(); env->frames = vec_createDefault(); env->ftable = ftab_create(); env->scope = stack_createDefault(); env->rxcache = stab_createDefault(); env->uses = sset_createDefault(); mttab_addBuiltInType(env, "boolean"); mttab_addBuiltInType(env, "byte"); mttab_addBuiltInType(env, "char"); mttab_addBuiltInType(env, "int"); mttab_addBuiltInType(env, "long"); mttab_addBuiltInType(env, "float"); mttab_addBuiltInType(env, "double"); mttab_addBuiltInType(env, "void"); /* Special symbol for the void type */ mttab_addBuiltInType(env, "null"); /* Special symbol for null type */ mttab_addBuiltInType(env, "Object"); mttab_addBuiltInType(env, "String"); mttab_addBuiltInType(env, "Exception"); mttab_addBuiltInType(env, "Regex"); /* compiler extras */ env->includes = sset_createDefault(); sset_add(env->includes, "<stdio.h>"); sset_add(env->includes, "\"mxarr.h\""); sset_add(env->includes, "\"stringbuffer.h\""); sset_add(env->includes, "\"excpfn.h\""); sset_add(env->includes, "\"mman.h\""); sset_add(env->includes, "\"runtime.h\""); sset_add(env->includes, "\"cdx_function.h\""); env->fdefs = htab_createDefault(); env->adefs = htab_createDefault(); env->constantPool = buf_createDefault(); env->constantCount = 0; env->fcodebuffer = buf_createDefault(); env->curScopeID = 0; env->scopeIDStack = istack_createDefault(); env->frameindex = -1; /* error stuff */ env->errs = sset_createDefault(); env->meta.filename = env->filename; env->meta.caller = NULL; env->meta.macroname = NULL; env->meta.lineno = 1; env->errflag = 0; return env; }