bool ex_event_write(void *arg) { ssi_char_t string[SSI_MAX_CHAR]; ssi_event_t e_string; ssi_sprint (string, "foo"); ssi_event_init (e_string, SSI_ETYPE_STRING, Factory::AddString ("foo"), Factory::AddString ("string")); ssi_event_adjust (e_string, ssi_strlen (string) + 1); ssi_strcpy (e_string.ptr, string); ssi_event_t e_floats; ssi_event_init (e_floats, SSI_ETYPE_FLOATS, Factory::AddString ("foo"), Factory::AddString ("floats")); ssi_event_adjust (e_floats, 5 * sizeof (ssi_real_t)); ssi_real_t *ptr = ssi_pcast (ssi_real_t, e_floats.ptr); for (ssi_size_t i = 0; i < e_floats.tot / sizeof (ssi_real_t); i++) { *ptr++ = ssi_cast (ssi_real_t, i); } ssi_event_t e_tuple; ssi_event_init (e_tuple, SSI_ETYPE_NTUPLE, Factory::AddString ("foo"), Factory::AddString ("tuple")); ssi_event_adjust (e_tuple, 3 * sizeof (ssi_event_tuple_t)); ssi_event_tuple_t *tuple = ssi_pcast (ssi_event_tuple_t, e_tuple.ptr); for (ssi_size_t i = 0; i < e_tuple.tot / sizeof (ssi_event_tuple_t); i++) { ssi_sprint (string, "foo-%u", i); tuple[i].id = Factory::AddString (string); tuple[i].value = ssi_cast (ssi_real_t, i); } FileEventsOut eout; eout.open ("foo", File::ASCII); eout.write (e_string); eout.write (e_floats); eout.write (e_tuple); eout.close (); ssi_event_destroy (e_string); ssi_event_destroy (e_floats); ssi_event_destroy (e_tuple); return true; }
bool ex_event(void *arg) { FileEventsOut eout; FileEventsIn ein; ssi_event_t empty_event; ssi_event_init(empty_event, SSI_ETYPE_EMPTY, Factory::AddString("empty"), Factory::AddString("event"), 0, 5); ssi_event_t string_event; ssi_event_init(string_event, SSI_ETYPE_STRING, Factory::AddString("string"), Factory::AddString("event"), 100, 10); ssi_event_adjust(string_event, 100); ssi_sprint(string_event.ptr, "hello world"); ssi_event_t tuple_event; ssi_event_init(tuple_event, SSI_ETYPE_TUPLE, Factory::AddString("floats"), Factory::AddString("event"), 200, 20); ssi_event_adjust(tuple_event, 3 * sizeof(ssi_event_tuple_t)); ssi_real_t *tuple = ssi_pcast(ssi_event_tuple_t, tuple_event.ptr); tuple[0] = 0.0f; tuple[1] = 1.0f; tuple[2] = 2.0f; ssi_event_t map_event; ssi_event_init(map_event, SSI_ETYPE_MAP, Factory::AddString("ntuple"), Factory::AddString("event"), 500, 40); ssi_event_adjust(map_event, 3 * sizeof(ssi_event_map_t)); ssi_event_map_t *map = ssi_pcast(ssi_event_map_t, map_event.ptr); map[0].id = Factory::AddString("a"); map[0].value = 0.0f; map[1].id = Factory::AddString("b"); map[1].value = 1.0f; map[2].id = Factory::AddString("c"); map[2].value = 2.0f; eout.open("my", File::ASCII); eout.write(empty_event); eout.write(string_event); eout.write(tuple_event); eout.write(map_event); eout.close(); ein.open("my"); ssi_print("found %u events\n", ein.getSize()); ssi_event_t *e; while (e = ein.next()) { ssi_print("> sender=%s, event=%s, from=%u, dur=%u, prob=%.2f, type=%s, state=%s, glue=%u\n", Factory::GetString(e->sender_id), Factory::GetString(e->event_id), e->time, e->dur, e->prob, SSI_ETYPE_NAMES[e->type], SSI_ESTATE_NAMES[e->state], e->glue_id); switch (e->type) { case SSI_ETYPE_STRING: { ssi_print(" %s\n", e->ptr); break; } case SSI_ETYPE_TUPLE: { ssi_size_t n = e->tot / sizeof(ssi_event_tuple_t); ssi_event_tuple_t *ptr = ssi_pcast(ssi_event_tuple_t, e->ptr); for (ssi_size_t i = 0; i < n; i++) { ssi_print("%.2f ", ptr[i]); } ssi_print("\n"); break; } case SSI_ETYPE_MAP: { ssi_size_t n = e->tot / sizeof(ssi_event_map_t); ssi_event_map_t *ptr = ssi_pcast(ssi_event_map_t, e->ptr); for (ssi_size_t i = 0; i < n; i++) { ssi_print("%s=%.2f ", Factory::GetString (ptr[i].id), ptr[i].value); } ssi_print("\n") break; } } }; ein.close(); ssi_event_destroy(empty_event); ssi_event_destroy(string_event); ssi_event_destroy(tuple_event); ssi_event_destroy(map_event); return true; }