static int send_command(const char *command, char *reply, int reply_len, int print_errors){ ortp_pipe_t pp; int i; int err; char path[128]; #ifndef WIN32 snprintf(path,sizeof(path)-1,"linphonec-%i",getuid()); #else { char username[128]; DWORD size=sizeof(username)-1; GetUserName(username,&size); snprintf(path,sizeof(path)-1,"linphonec-%s",username); } #endif if ((pp=ortp_client_pipe_connect(path))==ORTP_PIPE_INVALID){ if (print_errors) fprintf(stderr,"ERROR: Failed to connect pipe: %s\n",strerror(errno)); return -1; } if (ortp_pipe_write(pp,(uint8_t*)command,strlen(command))==-1){ if (print_errors) fprintf(stderr,"ERROR: Fail to send command to remote linphonec\n"); ortp_client_pipe_close(pp); return -1; } /*wait for replies */ i=0; while ((err=ortp_pipe_read(pp,(uint8_t*)&reply[i],reply_len-i-1))>0){ i+=err; } reply[i]='\0'; ortp_client_pipe_close(pp); return 0; }
static void * server_pipe_thread(void *pointer){ ortp_pipe_t child; do{ child=ortp_server_pipe_accept_client(server_pipe); if (server_pipe_running && child!=(ortp_pipe_t)-1){ char buf[256]={0}; if (ortp_pipe_read(child,(uint8_t*)buf,sizeof(buf))>0){ g_message("Received wakeup command with arg %s",buf); gdk_threads_enter(); g_timeout_add(20,(GSourceFunc)execute_wakeup,g_strdup(buf)); gdk_threads_leave(); } ortp_server_pipe_close_client(child); } }while(server_pipe_running); ortp_server_pipe_close(server_pipe); return NULL; }
static void *pipe_thread(void*p) { char tmp[250]; server_sock=create_server_socket(); if (server_sock==ORTP_PIPE_INVALID) return NULL; while(pipe_reader_run) { while(client_sock!=ORTP_PIPE_INVALID) { /*sleep until the last command is finished*/ #ifndef WIN32 usleep(20000); #else Sleep(20); #endif } client_sock=ortp_server_pipe_accept_client(server_sock); if (client_sock!=ORTP_PIPE_INVALID) { int len; /*now read from the client */ if ((len=ortp_pipe_read(client_sock,(uint8_t*)tmp,sizeof(tmp)-1))>0) { ortp_mutex_lock(&prompt_mutex); tmp[len]='\0'; strcpy(received_prompt,tmp); printf("Receiving command '%s'\n",received_prompt); fflush(stdout); have_prompt=TRUE; ortp_mutex_unlock(&prompt_mutex); } else { printf("read nothing\n"); fflush(stdout); ortp_server_pipe_close_client(client_sock); client_sock=ORTP_PIPE_INVALID; } } else { if (pipe_reader_run) fprintf(stderr,"accept() failed: %s\n",strerror(errno)); } } ms_message("Exiting pipe_reader_thread."); fflush(stdout); return NULL; }