int main (int argc, char *argv[]) { (void) signal (SIGINT, leave); if (argc != 2) { printf ("Usage: %s <socket-path>\n", argv[0]); return -1; } const char *my_user_data = "hello world"; reader = shmdata_any_reader_init (); shmdata_any_reader_set_debug (reader, SHMDATA_ENABLE_DEBUG); shmdata_any_reader_set_on_data_handler (reader, &on_data, (void *) my_user_data); // shmdata_any_reader_set_data_type(reader, "video/x-raw-yuv, format=(fourcc)YUY2, framerate=(fraction)25/1, width=(int)924, height=(int)576, interlaced=(boolean)true, pixel-aspect-ratio=(fraction)1/1"); shmdata_any_reader_set_data_type (reader, "text/plain"); //shmdata_any_reader_set_absolute_timestamp (reader, SHMDATA_ENABLE_ABSOLUTE_TIMESTAMP); shmdata_any_reader_set_absolute_timestamp (reader, SHMDATA_DISABLE_ABSOLUTE_TIMESTAMP); shmdata_any_reader_start (reader, argv[1]); //shmdata_any_reader is non blocking keep_going = yes; while (keep_going == yes) { sleep (1); } return 0; }
static void shmsrc_tilde_reader_restart (t_shmsrc_tilde *x) { shmdata_any_reader_close (x->x_reader); x->x_reader = shmdata_any_reader_init (); shmdata_any_reader_set_debug (x->x_reader, SHMDATA_ENABLE_DEBUG); shmdata_any_reader_set_on_data_handler (x->x_reader, &shmsrc_tilde_on_data, (void *) x); //shmdata_any_reader_set_data_type (reader, "application/helloworld_"); shmdata_any_reader_start (x->x_reader, x->x_shmdata_path); }
int check_read_write () { shmdata_any_reader_t *reader; shmdata_any_writer_t *writer; const char *my_user_data = "You can pass a pointer to the reader's data handler function."; const char *SOCKET_PATH = "/tmp/shmdata-test-check-write-read"; writer = shmdata_any_writer_init (); if (VERBOSE == yes) shmdata_any_writer_set_debug (writer, SHMDATA_ENABLE_DEBUG); shmdata_any_writer_set_path (writer, SOCKET_PATH); shmdata_any_writer_set_data_type (writer, "text/plain"); shmdata_any_writer_start (writer); reader = shmdata_any_reader_init (); if (VERBOSE == yes) shmdata_any_reader_set_debug (reader, SHMDATA_ENABLE_DEBUG); shmdata_any_reader_set_on_data_handler (reader, &on_data, (void *) my_user_data); shmdata_any_reader_set_data_type (reader, "text/plain"); shmdata_any_reader_start (reader, SOCKET_PATH); unsigned long long myclock = 0; unsigned long long nsecPeriod = 30000000; keep_going = yes; shmdata_any_writer_push_data (writer, message, sizeof (message), myclock, &data_not_required_anymore, message); while (keep_going == yes) { //data should be serialized if network is involved // here it is not usleep (nsecPeriod / 1000); myclock += nsecPeriod; } shmdata_any_writer_close (writer); shmdata_any_reader_close (reader); if (success == yes) return 0; else return 1; }