static void client_event_cb(struct pomp_ctx *ctx, enum pomp_event event, struct pomp_conn *conn, const struct pomp_msg *msg, void *userdata) { int fd, msgid; unsigned int bufsize; void *video_buffer; GstVideoFormat videoformat; unsigned int width, height; switch (event) { case POMP_EVENT_CONNECTED: ULOGI("connected to pimp user filter"); break; case POMP_EVENT_DISCONNECTED: ULOGI("disconnected from pimp user filter"); break; case POMP_EVENT_MSG: switch (msgid = pomp_msg_get_id(msg)) { case SEND_FD: pomp_msg_read(msg, "%x%u%u%u%u", &fd, &bufsize, &videoformat, &width, &height); ULOGI("received a FD from pimp: %d", fd); video_buffer = mmap(NULL, bufsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); s_app.process(video_buffer, bufsize, videoformat, width, height, s_app.priv); pomp_ctx_send(ctx, BUFFER_PROCESSING_DONE, NULL); break; default: ULOGW("received unknown message id from pimp : %d", msgid); break; } break; default: ULOGE("Unknown event: %d", event); break; } }
static void test_event_cb_t(struct pomp_ctx *ctx, enum pomp_event event, struct pomp_conn *conn, const struct pomp_msg *msg, void *userdata) { int fd; int res = 0; struct test_data *data = userdata; const char *eventstr = pomp_event_str(event); const struct sockaddr *addr = NULL; uint32_t addrlen = 0; const struct pomp_cred *cred = NULL; int isunix = 0; switch (event) { case POMP_EVENT_CONNECTED: data->connection++; /* Invalid get fd (NULL param) */ fd = pomp_conn_get_fd(NULL); CU_ASSERT_EQUAL(fd, -EINVAL); fd = pomp_conn_get_fd(conn); CU_ASSERT_TRUE(fd >= 0); addr = pomp_conn_get_local_addr(conn, &addrlen); CU_ASSERT_TRUE(addr != NULL); addr = pomp_conn_get_peer_addr(conn, &addrlen); CU_ASSERT_TRUE(addr != NULL); isunix = addr->sa_family == AF_UNIX; /* Invalid get addr (NULL param) */ addr = pomp_conn_get_local_addr(NULL, &addrlen); CU_ASSERT_TRUE(addr == NULL); addr = pomp_conn_get_local_addr(conn, NULL); CU_ASSERT_TRUE(addr == NULL); addr = pomp_conn_get_peer_addr(NULL, &addrlen); CU_ASSERT_TRUE(addr == NULL); addr = pomp_conn_get_peer_addr(conn, NULL); CU_ASSERT_TRUE(addr == NULL); if (!isunix) { /* Invalid get credentials (bad type or NULL param) */ cred = pomp_conn_get_peer_cred(conn); CU_ASSERT_TRUE(cred == NULL); cred = pomp_conn_get_peer_cred(NULL); CU_ASSERT_TRUE(cred == NULL); } else { cred = pomp_conn_get_peer_cred(conn); CU_ASSERT_TRUE(cred != NULL); } break; case POMP_EVENT_DISCONNECTED: data->disconnection++; break; case POMP_EVENT_MSG: data->msg++; if (pomp_msg_get_id(msg) == 1) { res = pomp_conn_send(conn, 2, "%s", eventstr); CU_ASSERT_EQUAL(res, 0); } if (data->isdgram) { res = pomp_conn_disconnect(conn); CU_ASSERT_EQUAL(res, -ENOTCONN); /* Internal function invalid arguments checks */ res = pomp_conn_send_msg_to(NULL, msg, NULL, 0); CU_ASSERT_EQUAL(res, -EINVAL); res = pomp_conn_send_msg_to(conn, NULL, NULL, 0); CU_ASSERT_EQUAL(res, -EINVAL); } else { /* Internal function invalid arguments checks */ res = pomp_conn_send_msg(NULL, msg); CU_ASSERT_EQUAL(res, -EINVAL); res = pomp_conn_send_msg(conn, NULL); CU_ASSERT_EQUAL(res, -EINVAL); } /* Internal function invalid arguments checks */ res = pomp_ctx_notify_event(NULL, POMP_EVENT_CONNECTED, conn); CU_ASSERT_EQUAL(res, -EINVAL); res = pomp_ctx_notify_event(ctx, POMP_EVENT_MSG, conn); CU_ASSERT_EQUAL(res, -EINVAL); res = pomp_ctx_notify_event(ctx, POMP_EVENT_CONNECTED, NULL); CU_ASSERT_EQUAL(res, -EINVAL); res = pomp_ctx_notify_msg(NULL, conn, msg); CU_ASSERT_EQUAL(res, -EINVAL); res = pomp_ctx_notify_msg(ctx, NULL, msg); CU_ASSERT_EQUAL(res, -EINVAL); res = pomp_ctx_notify_msg(ctx, conn, NULL); CU_ASSERT_EQUAL(res, -EINVAL); break; default: CU_ASSERT_TRUE_FATAL(0); break; } }
static void test_fd_passing_client(struct pomp_ctx *ctx, enum pomp_event event, struct pomp_conn *conn, const struct pomp_msg *msg, void *userdata) { int res = 0; int fds[3] = {-1, -1, -1}; char *str0 = NULL, *str1 = NULL, *str2 = NULL; char buf[32] = ""; struct test_data *data = userdata; TEST_IPC_LOG("%s : event=%d(%s) conn=%p msg=%p", __func__, event, pomp_event_str(event), conn, msg); switch (event) { case POMP_EVENT_CONNECTED: break; case POMP_EVENT_DISCONNECTED: data->stop = 1; break; case POMP_EVENT_MSG: if (pomp_msg_get_id(msg) == 1) { res = pomp_msg_read(msg, "%ms%x%ms%x%ms%x", &str0, &fds[0], &str1, &fds[1], &str2, &fds[2]); TEST_IPC_CHECK_EQUAL(data, res, 0); memset(buf, 0, sizeof(buf)); res = (int)read(fds[0], buf, sizeof(buf) - 1); TEST_IPC_CHECK_EQUAL(data, res, 5); TEST_IPC_CHECK_STRING_EQUAL(data, str0, "pipe0"); TEST_IPC_CHECK_STRING_EQUAL(data, buf, "pipe0"); memset(buf, 0, sizeof(buf)); res = (int)read(fds[1], buf, sizeof(buf) - 1); TEST_IPC_CHECK_EQUAL(data, res, 5); TEST_IPC_CHECK_STRING_EQUAL(data, str1, "pipe1"); TEST_IPC_CHECK_STRING_EQUAL(data, buf, "pipe1"); memset(buf, 0, sizeof(buf)); res = (int)read(fds[2], buf, sizeof(buf) - 1); TEST_IPC_CHECK_EQUAL(data, res, 5); TEST_IPC_CHECK_STRING_EQUAL(data, str2, "pipe2"); TEST_IPC_CHECK_STRING_EQUAL(data, buf, "pipe2"); free(str0); free(str1); free(str2); pomp_conn_disconnect(conn); } break; default: break; } }