int hpx_main() { { // Find the localities connected to this application. std::vector<hpx::id_type> localities = hpx::find_all_localities(); const std::string tuplespace_symbol_name = "/tuplespace"; examples::simple_central_tuplespace central_tuplespace; if (!central_tuplespace.create( tuplespace_symbol_name, localities.back())) { hpx::cerr << "locality " << hpx::get_locality_id() << ": " << "FAIL to create " << tuplespace_symbol_name << hpx::endl; return hpx::finalize(); } tuple_type tuple1; tuple1.push_back(std::string("first")) .push_back(10) // first elem: int .push_back(small_object(20)) // second elem: small_object .push_back(big_object(30, 40)); // third elem: big_object hpx::cout << "locality " << hpx::get_locality_id() << ": " << "created tuple1: "; print_tuple(tuple1); hpx::cout << hpx::endl; tuple_type tuple2; tuple2.push_back(std::string("second")) .push_back(std::string("string")) // first elem: string .push_back(small_object(50)) // second elem: small_object .push_back(big_object(60, 70)); // third elem: big_object hpx::cout << "locality " << hpx::get_locality_id() << ": " << "created tuple2: "; print_tuple(tuple2); hpx::cout << hpx::endl; std::vector<hpx::lcos::future<void>> futures; for (hpx::naming::id_type const& node : localities) { // Asynchronously start a new task. The task is encapsulated in a // future, which we can query to determine if the task has // completed. typedef simple_central_tuplespace_test_action action_type; futures.push_back( hpx::async<action_type>(node, tuplespace_symbol_name, tuple1)); futures.push_back( hpx::async<action_type>(node, tuplespace_symbol_name, tuple2)); } hpx::wait_all(futures); } // Initiate shutdown of the runtime systems on all localities. return hpx::finalize(); }
/* return 0 on success, 1 in case of error */ static int ct_seq_real_show(const struct ip_conntrack_tuple_hash *hash, struct seq_file *s) { struct ip_conntrack *conntrack = hash->ctrack; struct ip_conntrack_protocol *proto; MUST_BE_READ_LOCKED(&ip_conntrack_lock); IP_NF_ASSERT(conntrack); /* we only want to print DIR_ORIGINAL */ if (DIRECTION(hash)) return 0; proto = ip_ct_find_proto(conntrack->tuplehash[IP_CT_DIR_ORIGINAL] .tuple.dst.protonum); IP_NF_ASSERT(proto); if (seq_printf(s, "%-8s %u %lu ", proto->name, conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum, timer_pending(&conntrack->timeout) ? (conntrack->timeout.expires - jiffies)/HZ : 0) != 0) return 1; if (proto->print_conntrack(s, conntrack)) return 1; if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple, proto)) return 1; if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL])) return 1; if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status))) if (seq_printf(s, "[UNREPLIED] ")) return 1; if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple, proto)) return 1; if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY])) return 1; if (test_bit(IPS_ASSURED_BIT, &conntrack->status)) if (seq_printf(s, "[ASSURED] ")) return 1; #if defined(CONFIG_IP_NF_CONNTRACK_MARK) if (seq_printf(s, "mark=%ld ", conntrack->mark)) return 1; #endif if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use))) return 1; return 0; }
void recv_command(char *command) { struct tnt_iter i; tnt_iter_reply(&i, tnt); while (tnt_next(&i)) { struct tnt_reply *r = TNT_IREPLY_PTR(&i); printf("%s: respond %s (op: %"PRIu32", reqid: %"PRIu32", code: %"PRIu32", count: %"PRIu32")\n", command, tnt_strerror(tnt), r->op, r->reqid, r->code, r->count); struct tnt_iter it; tnt_iter_list(&it, TNT_REPLY_LIST(r)); while (tnt_next(&it)) { struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it); print_tuple(tu); } tnt_iter_free(&it); } if (i.status == TNT_ITER_FAIL) fail_tnt_perror("tnt_next"); tnt_iter_free(&i); }
static int data_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[CTA_MAX+1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); mnl_attr_parse(nlh, sizeof(*nfg), data_attr_cb, tb); if (tb[CTA_TUPLE_ORIG]) print_tuple(tb[CTA_TUPLE_ORIG]); if (tb[CTA_MARK]) printf("mark=%u ", ntohl(mnl_attr_get_u32(tb[CTA_MARK]))); if (tb[CTA_SECMARK]) printf("secmark=%u ", ntohl(mnl_attr_get_u32(tb[CTA_SECMARK]))); if (tb[CTA_COUNTERS_ORIG]) { printf("original "); print_counters(tb[CTA_COUNTERS_ORIG]); } if (tb[CTA_COUNTERS_REPLY]) { printf("reply "); print_counters(tb[CTA_COUNTERS_REPLY]); } printf("\n"); return MNL_CB_OK; }
void types_visitor::print_complex_item(complex_item* item) { switch(item->type) { case COMPLEX_SIMPLE: print_simple_item(item->data._simple); break; case COMPLEX_TUPLE: print_tuple(item->data._tuple); break; case COMPLEX_BAG: print_bag(item->data._bag); break; case COMPLEX_MAP: print_map(item->data._map); break; } }
/* * print a tuple linked list */ void print_tuple_list( TUPLE *tuple) { /* * print the tuple linked list structure */ while( tuple) { print_tuple( tuple); tuple = tuple->next; } return; }
void simple_central_tuplespace_test( const std::string& tuplespace_symbol_name, const tuple_type tuple) { examples::simple_central_tuplespace central_tuplespace; if (!central_tuplespace.connect(tuplespace_symbol_name)) { hpx::cerr << "locality " << hpx::get_locality_id() << ": " << "FAIL to connect " << tuplespace_symbol_name << hpx::endl; return; } int ret = central_tuplespace.write(hpx::launch::sync, tuple); hpx::cout << "locality " << hpx::get_locality_id() << ": " << "write_sync "; print_tuple(tuple); hpx::cout << " returns " << ret << hpx::endl; tuple_type partial_tuple; if (tuple.size() > 1) // use second field { partial_tuple.push_back_empty().push_back(*(tuple.begin() + 1)); } else { partial_tuple.push_back(*(tuple.begin())); } tuple_type return_tuple = central_tuplespace.read(hpx::launch::sync, partial_tuple, 0); hpx::cout << "locality " << hpx::get_locality_id() << ": " << "read_sync tuple with "; print_tuple(partial_tuple); hpx::cout << " returns "; print_tuple(return_tuple); hpx::cout << hpx::endl; return_tuple = central_tuplespace.take(hpx::launch::sync, partial_tuple, 0); hpx::cout << "locality " << hpx::get_locality_id() << ": " << "take_sync tuple with "; print_tuple(partial_tuple); hpx::cout << " (1st) returns "; print_tuple(return_tuple); hpx::cout << hpx::endl; return_tuple = central_tuplespace.take(hpx::launch::sync, partial_tuple, 0); hpx::cout << "locality " << hpx::get_locality_id() << ": " << "take_sync tuple with "; print_tuple(partial_tuple); hpx::cout << " (2nd) returns "; print_tuple(return_tuple); hpx::cout << hpx::endl << hpx::flush; }
void print_element(struct element *e) { int i, n, too_long, tag = e->tag; unsigned char *s; const int max_str_len = 16; switch (tag) { case 'i': logptr += sprintf(logbuf + logptr, "%d", e->data.i); break; case 'd': logptr += sprintf(logbuf + logptr, "%f", e->data.d); break; case 's': s = (unsigned char*)e->data.s.ptr; n = e->data.s.len; too_long = 0; if (n > max_str_len) { n = max_str_len; too_long = 1; } logbuf[logptr++] = '"'; for (i = 0; i < n; i++) { if (s[i] >= ' ' && s[i] <= '~') { logbuf[logptr++] = s[i]; } else { logptr += sprintf(logbuf + logptr, "\\%02X", s[i]); } } if (too_long) { logptr += sprintf(logbuf + logptr, " ..."); } logbuf[logptr++] = '"'; break; case 't': print_tuple(e->data.t); break; case '?': logptr += sprintf(logbuf + logptr, "???"); break; default: logptr += sprintf(logbuf + logptr, "<<unknown field, tag=%d>>", tag); break; } }
static int exp_seq_show(struct seq_file *s, void *v) { struct ip_conntrack_expect *expect = v; if (expect->timeout.function) seq_printf(s, "%lu ", timer_pending(&expect->timeout) ? (expect->timeout.expires - jiffies)/HZ : 0); else seq_printf(s, "- "); seq_printf(s, "proto=%u ", expect->tuple.dst.protonum); print_tuple(s, &expect->tuple, ip_ct_find_proto(expect->tuple.dst.protonum)); return seq_putc(s, '\n'); }
/********************************************************************* SELECT * FROM T; */ static ib_err_t do_query( /*=====*/ ib_crsr_t crsr) { ib_err_t err; ib_tpl_t tpl; tpl = ib_clust_read_tuple_create(crsr); assert(tpl != NULL); err = ib_cursor_first(crsr); assert(err == DB_SUCCESS); while (err == DB_SUCCESS) { err = ib_cursor_read_row(crsr, tpl); assert(err == DB_SUCCESS || err == DB_END_OF_INDEX || err == DB_RECORD_NOT_FOUND); if (err == DB_RECORD_NOT_FOUND || err == DB_END_OF_INDEX) { break; } print_tuple(stdout, tpl); err = ib_cursor_next(crsr); assert(err == DB_SUCCESS || err == DB_END_OF_INDEX || err == DB_RECORD_NOT_FOUND); tpl = ib_tuple_clear(tpl); assert(tpl != NULL); } if (tpl != NULL) { ib_tuple_delete(tpl); } if (err == DB_RECORD_NOT_FOUND || err == DB_END_OF_INDEX) { err = DB_SUCCESS; } return(err); }
int main(int argc, char **argv) { static char namebuf[1024]; /* space for tuple */ static char namebuf2[1024]; /* space for tuple */ BUNDLE_AGENT ba; BUNDLE_SPEC bs; BUNDLE_TUPLE tuple = { { 0, namebuf} , 0 }; BUNDLE_TUPLE dst = { { 0, namebuf2}, 0}; BUNDLE_WAITING bw; BUNDLE_ITERATOR iterator = BUNDLE_ITERATOR_NONE ; uint32_t reg_cookie = BUNDLE_REG_COOKIE_NONE; // // Read any defaults of out $HOME/.snd_bundlerc // readResourceFile(); // // Read off the command arguments // readCommandLineArgs(argc, argv); if ( debug>4 ) { writeDefaultsFile(1); // Write to stderr } // // Sanity check parameters // if ( theSource==0 ) { usage("snd_bundle", "-s option is required."); exit(EXIT_FAILURE); } if ( (theSource==2 || theSource==3) && (strlen(fname)==0) ) { usage("snd_bundle", ""); fprintf(stderr, "theSource (%d) specifies sending from file\n", theSource); fprintf(stderr, "but no [-f file_name] option given.\n"); exit(EXIT_FAILURE); } // // Open connection to bundle agent. // if ( debug>0 ) { printf("SND BUNDLE: ***opening bundle agent on host %s\n", bahost); } if ((ba = open_agent(bahost)) == NULL) { fprintf(stderr, "couldn't contact bundle daemon on %s\n", bahost); exit(1); } if ( debug>1 ) { printf(" Bundle agent on host %s open.\n", bahost); } // // Local tuple // if ( debug>0 ) { printf("snd_bundle: building local tuple with localstuff: '%s'\n", localstuff); } // // If the user specified a source region and source admin part, use those, // otherwise call local_tuple which will use one of our regions (the first // it finds in the config file) and our hostname. // if ( strlen(sourceIntf)>0 ) { if ( local_tuple(ba, sourceIntf, localstuff, &tuple) < 0 ) { fprintf(stderr, "trouble building local tuple with source (%s, %s)\n", sourceIntf, localstuff); exit(EXIT_FAILURE); } } else { if (local_tuple(ba, NULL, localstuff, &tuple) < 0) { fprintf(stderr, "trouble building tuple with local stuff %s\n", localstuff); exit(EXIT_FAILURE); } } if ( debug>0 ) { print_tuple(tuple); } // // Destination tuple // if ( debug>0 ) { printf("snd_bundle: building destination tuple: (%s)\n", destTuple); } if (remote_tuple(destTuple, &dst) < 0) { fprintf(stderr, "trouble building destination tuple\n"); exit(1); } if ( debug>0 ) { print_tuple(dst); } // Register the local tuple (dest demux string of inbound bundles) // in expectation of receiving responses to what we're going to // send. if ( pollForResponse ) { if ( debug>0 ) printf("registering tuple..."); if (demux_register(ba, tuple, BUNDLE_REG_ABORT, ®_cookie) < 0) { fprintf(stderr, "trouble registering tuple\n"); exit(1); } if ( debug>1 ) printf("ok, cookie was 0x%x\n", reg_cookie); } while ( timesToLoop-->0 ) { // // Send a bundle from memory // if ( theSource==1 || theSource==3 ) { if ( debug>0 ) { printf("sending bundle from memory...\n"); } /* build a bundle spec */ if (bundle_spec(COS_NORMAL, COS_NONE, tuple, dst, tuple, expire, &bs) < 0) { fprintf(stderr, "trouble building bundle_spec\n"); exit(1); } /* send the bundle with the spec */ if (send_bundle_mem(ba, bs, bundle_data, strlen(bundle_data)) < 0) { fprintf(stderr, "trouble sending bundle from memory\n"); exit(1); } } // // Send a bundle from a file // if ( theSource==2 || theSource==3 ) { if ( debug>0 ) { printf("sending bundle from file...\n"); } if (bundle_spec(COS_NORMAL, COS_NONE, tuple, dst, tuple, expire, &bs) < 0) { fprintf(stderr, "trouble building bundle_spec\n"); exit(EXIT_FAILURE); } if (send_bundle_file(ba, bs, fname) < 0) { fprintf(stderr, "trouble sending bundle from file '%s'\n", fname); exit(EXIT_FAILURE); } } } // // If we were looking for a response, here's how to poll // if ( pollForResponse ) { if ( debug>0 ) printf("Sleeping for a bit...\n"); sleep(15); if ( debug>0 ) { printf("polling for tuple:\n"); print_tuple(tuple); } while (bundle_poll(ba, tuple, &iterator, &bw) == BUNDLE_SUCCESS) { printf("yup, got a bundle at %s\n", bw.filename.filename_val); printf("with bundle spec:\n"); print_bundle_spec(bw.bs); } printf("no more incoming bundles...\n"); printf("unregistering tuple...\n"); if (demux_register_cancel(ba, reg_cookie) < 0) { fprintf(stderr, "trouble unregistering tuple\n"); exit(1); } } if ( debug>0 ) { printf("\n***all done (success)\n"); } close_agent(ba); if ( writeResourceFile ) { writeDefaultsFile(0); } exit(0); }
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos> ) { out << std::get< std::tuple_size<Tuple>::value-Pos >(t) << ','; return print_tuple(out, t, int_<Pos-1>()); }
std::ostream& operator<<(std::ostream& out, const std::tuple<Args...>& t) { print_tuple(out, t, int_<sizeof...(Args)>()); return out; }
std::ostream & operator<<(std::ostream & out, const std::tuple<Args...> & t) { return print_tuple(out, t, int_const< sizeof...(Args) >{}); }
void print_tuple(const std::tuple<Args...>& tuple) { print_tuple(tuple, typename gens<sizeof...(Args)>::type{}); }
void print2(int a, int b, int c) { print_tuple(std::make_tuple(a, b, c)); }
void print3(float a, float b, float c, float d) { print_tuple(std::make_tuple(a, b, c, d)); }
int main(int argc, char** argv) { static char namebuf[1024]; /* space for tuple */ BUNDLE_AGENT ba; BUNDLE_TUPLE tuple = { { 0, namebuf} , 0 }; BUNDLE_WAITING bw; int first_time = 1; int c, ret; int received_bundle_count = 0; // // Read any defaults of out $HOME/.polling_rcvrrc // readResourceFile(); // // Read off the command arguments // readCommandLineArgs(argc, argv); if ( debug>4 ) { writeDefaultsFile(1); // Write to stderr } // // Sanity check arguments // if ( strlen(bahost)==0 ) { usage("polling_rcvr", "bundleAgent required"); exit(-1); } if ( strlen(demuxString)==0 ) { usage("polling_rcvr", "demuxString required.\n"); exit(-1); } // // Open connection to bundle agent. // if ( debug>0) { printf("polling_rcvr: ***opening bundle agent on host %s\n", bahost); } if ((ba = open_agent(bahost)) == NULL) { fprintf(stderr, "couldn't contact bundle daemon on %s\n", bahost); exit(1); } if ( debug>1 ) { printf(" Bundle agent open.\n"); } /* API doesn't do mem alloc for us; we must do it */ if ( strlen(matchstr)>0 ) { if ( debug>0 ) printf("creating local tuple with name...\n"); if (local_tuple(ba, matchstr, localstuff, &tuple) < 0) { fprintf(stderr, "trouble building tuple with source matchstr %s\n", matchstr); exit(1); } } else { if ( debug>0 ) printf("creating local tuple...\n"); if (local_tuple(ba, NULL, localstuff, &tuple) < 0) { fprintf(stderr, "trouble building tuple with localstuff %s\n", localstuff); exit(1); } } if ( debug>0 ) { print_tuple(tuple); } if ( debug>0 ) { printf("polling for tuple:\n"); print_tuple(tuple); } for (c = 0; c < timesToPoll; c++ ) { if ((ret = bundle_poll(ba, tuple, &iterator, &bw)) == BUNDLE_SUCCESS) { if (first_time == 1) { if ( debug>0 ) printf("Bundle poll iterator set to %d\n", iterator); first_time = 0; } received_bundle_count++; if ( debug>0 ) { printf("yup, got a bundle[%d] at %s\n", received_bundle_count, bw.filename.filename_val); //printf("with bundle spec:\n"); //print_bundle_spec(bw.bs); //printf("and iterator 0x%x\n", iterator); } } else { if (first_time == 1) { if ( debug>0 ) printf("Bundle poll iterator set to %d\n", iterator); first_time = 0; } if ( debug>0 ) { printf("."); fflush(stdout); } sleep(1); } } if ( debug>0 ) { printf("I'm tired of waiting for bundles...\n"); printf("\n***all done (success)\n"); } close_agent(ba); if ( writeResourceFile ) { writeDefaultsFile(0); } exit(0); }
template<typename... T> std::ostream &operator <<(std::ostream &sout, expr<tags::function,T...> const &ex){ sout << std::get<0>(ex.childs) << "("; print_tuple(sout,ex.childs); return sout<<")" ; }
void print_size() { std::cout << "sizeof "; print_tuple(T()); std::cout << " == " << sizeof(T) << '\n'; }
int main(int argc,char **argv){ if(argc != 2){ printf("give me a database\table name\n"); return 1; } char *dtname=argv[1]; ib_err_t err; err=ib_init(); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_int("log_buffer_size", 8*1024*1024); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_int("force_recovery", 1); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_int("log_file_size", 128*1024*1024); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_int("log_files_in_group", 3); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_text("log_group_home_dir", "./"); //err = ib_cfg_set_text("log_group_home_dir", "/var/lib/mysql/"); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_text("data_home_dir", "./"); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_text("data_file_path", "ibdata1:500M:autoextend"); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err = ib_cfg_set_bool_on("file_per_table"); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err=ib_startup("Antelope"); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } ib_trx_t trx; ib_crsr_t crsr; trx=ib_trx_begin(IB_TRX_REPEATABLE_READ); assert(trx != NULL); err=ib_cursor_open_table(dtname,trx,&crsr); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } ib_tpl_t tpl; tpl=ib_clust_read_tuple_create(crsr); assert(tpl != NULL); err=ib_cursor_first(crsr); while(err == DB_SUCCESS){ err=ib_cursor_read_row(crsr,tpl); print_tuple(stdout,tpl); err=ib_cursor_next(crsr); tpl=ib_tuple_clear(tpl); } ib_tuple_delete(tpl); err=ib_cursor_close(crsr); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err=ib_trx_commit(trx); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } err=ib_shutdown(IB_SHUTDOWN_NORMAL); if(err != DB_SUCCESS){ puts(ib_strerror(err)); return err; } return 0; }
void print_tuple(std::basic_ostream<Ch,Tr>& os, T const& t, int_<I>) { print_tuple(os, t, int_<I-1>()); os << " " << std::get<I>(t); }
template<typename... T> std::ostream &operator <<(std::ostream &sout, expr<tags::subscript,T...> const &ex){ sout << std::get<0>(ex.childs) << "["; print_tuple(sout,ex.childs); return sout<<"]" ; }
std::ostream& operator<<(std::basic_ostream<Ch,Tr>& os, std::tuple<Args...> const& t) { print_tuple(os, t, int_<sizeof...(Args)-1>()); return os; }