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; }
void linphone_gtk_uninit_instance(void){ if (server_pipe!=(ortp_pipe_t)-1){ ortp_pipe_t client; server_pipe_running=FALSE; /*this is to unblock the accept() of the server pipe*/ client=ortp_client_pipe_connect(pipe_name); ortp_pipe_write(client,(uint8_t*)" ",1); ortp_client_pipe_close(client); ms_thread_join(pipe_thread,NULL); server_pipe=(ortp_pipe_t)-1; g_free(pipe_name); pipe_name=NULL; } }
bool_t linphone_gtk_init_instance(const char *app_name, const char *addr_to_call){ pipe_name=make_name(app_name); ortp_pipe_t p=ortp_client_pipe_connect(pipe_name); if (p!=(ortp_pipe_t)-1){ uint8_t buf[256]={0}; g_message("There is already a running instance."); if (addr_to_call!=NULL){ //strncpy((char*)buf,addr_to_call,sizeof(buf)-1); sprintf((char*)buf, "%s %s %s", addr_to_call, aupkg_file, (g_enable_video==FALSE)?"audio":"video"); } if (ortp_pipe_write(p,buf,sizeof(buf))==-1){ g_error("Fail to send wakeup command to running instance: %s",strerror(errno)); }else{ g_message("Message to running instance sent."); } ortp_client_pipe_close(p); return FALSE; }else{ linphone_gtk_init_pipe(pipe_name); } return TRUE; }
bool_t linphone_gtk_init_instance(const char *app_name, int option, const char *addr_to_call){ ortp_pipe_t p; pipe_name=make_name(app_name); p=ortp_client_pipe_connect(pipe_name); if (p!=(ortp_pipe_t)-1){ uint8_t buf[256]={0}; g_message("There is already a running instance."); if (addr_to_call!=NULL){ sprintf((char *)buf,"%i%s",option,addr_to_call); } else { sprintf((char *)buf,"%i",option); } if (ortp_pipe_write(p,buf,sizeof(buf))==-1){ g_error("Fail to send wakeup command to running instance: %s",strerror(errno)); }else{ g_message("Message to running instance sent."); } ortp_client_pipe_close(p); return FALSE; }else{ linphone_gtk_init_pipe(pipe_name); } return TRUE; }