int main() { int mdp_sock; MSP_SOCKET msp_sock; struct mdp_sockaddr addr; struct sigaction act; struct timeval timeout; time_ms_t now; time_ms_t next_time = 0; /* sample message to reply to clients */ strcpy((char *)outbuf, "Hello World!"); if ((mdp_sock = mdp_socket()) < 0) { std::cerr << "server: error creating mdp socket" << std::endl; return -1; } msp_sock = msp_socket(mdp_sock, 0); addr.sid = SID_ANY; addr.port = PORT; msp_set_local(msp_sock, &addr); msp_set_handler(msp_sock, listen_handler, NULL); msp_listen(msp_sock); if (!msp_socket_is_open(msp_sock)) { std::cerr << "server: error listening on msp socket" << std::endl; return -1; } /* cleanup on CTRL-C */ memset(&act, 0, sizeof(act)); act.sa_handler = &cleanup; if (sigaction(SIGINT, &act, NULL) < 0) { fprintf(stderr, "error registering signal handler\n"); return -1; } /* main loop */ std::cout << "server: starting server..." << std::endl; quit = 0; while (!quit) { now = gettime_ms(); if (now < next_time) { struct timeval timeout = time_ms_to_timeval(next_time - now); setsockopt(mdp_sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); msp_recv(mdp_sock); } msp_processing(&next_time); } std::cout << "server: cleanup..." << std::endl; msp_close_all(mdp_sock); mdp_close(mdp_sock); return 0; }
// Function to check if a SID is reachable via MDP or MSP. int _rpc_sid_is_reachable (sid_t sid) { // Create a MDP socket. int mdp_sockfd; if ((mdp_sockfd = mdp_socket()) < 0) { pfatal("Could not create MDP lookup socket. Aborting."); return -1; } // Init a mdp_frame overlay_mdp_frame mdp; bzero(&mdp,sizeof(mdp)); // Set the packettype to get a routingtable. mdp.packetTypeAndFlags = MDP_ROUTING_TABLE; overlay_mdp_send(mdp_sockfd, &mdp, 0, 0); // Poll until there is nothing left. while (overlay_mdp_client_poll(mdp_sockfd, 200)) { // Create mdp_frame for incoming data. TTL is required but not needed... overlay_mdp_frame recv_frame; int ttl; if (overlay_mdp_recv(mdp_sockfd, &recv_frame, 0, &ttl)) { continue; } // Handle incoming data. int offset=0; while (offset + sizeof(struct overlay_route_record) <= recv_frame.out.payload_length) { // Make new route record struct where all needed information is stored in. struct overlay_route_record *record = &recv_frame.out.route_record; offset += sizeof(struct overlay_route_record); // If the record (aka SID) is reachable, and the record is the desired SID, return 1 and clean up. if ((record->reachable == REACHABLE_INDIRECT || record->reachable == REACHABLE_UNICAST || record->reachable == REACHABLE_BROADCAST || record->reachable == REACHABLE_SELF) && !cmp_sid_t(&record->sid, &sid)) { mdp_close(mdp_sockfd); return 1; } } } mdp_close(mdp_sockfd); return 0; }
long mdp_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) { int rc = 0; if (!sd) { WFD_MSG_ERR("Invalid arguments\n"); return -EINVAL; } switch (cmd) { case MDP_Q_BUFFER: rc = mdp_q_buffer(sd, arg); break; case MDP_DQ_BUFFER: rc = mdp_dq_buffer(sd, arg); break; case MDP_OPEN: rc = mdp_open(sd, arg); break; case MDP_START: rc = mdp_start(sd, arg); break; case MDP_STOP: rc = mdp_stop(sd, arg); break; case MDP_SET_PROP: rc = mdp_set_prop(sd, arg); break; case MDP_CLOSE: rc = mdp_close(sd, arg); break; case MDP_MMAP: rc = mdp_mmap(sd, arg); break; case MDP_MUNMAP: rc = mdp_munmap(sd, arg); break; case MDP_SECURE: rc = mdp_secure(sd); break; default: WFD_MSG_ERR("IOCTL: %u not supported\n", cmd); rc = -EINVAL; break; } return rc; }