2 linphone, gtk interface.
3 Copyright (C) 2011 Belledonne Communications SARL
4 Author: Simon MORLAT (simon.morlat@linphone.org)
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 static ms_thread_t pipe_thread;
24 static ortp_pipe_t server_pipe=(ortp_pipe_t)-1;
25 static gboolean server_pipe_running=TRUE;
26 static char *pipe_name;
28 static gboolean execute_wakeup(char *uri){
29 linphone_gtk_show_main_window();
31 linphone_gtk_refer_received(linphone_gtk_get_core(),uri);
36 static void * server_pipe_thread(void *pointer){
40 child=ortp_server_pipe_accept_client(server_pipe);
41 if (server_pipe_running && child!=(ortp_pipe_t)-1){
43 if (ortp_pipe_read(child,(uint8_t*)buf,sizeof(buf))>0){
44 g_message("Received wakeup command with arg %s",buf);
46 g_timeout_add(20,(GSourceFunc)execute_wakeup,g_strdup(buf));
49 ortp_server_pipe_close_client(child);
51 }while(server_pipe_running);
52 ortp_server_pipe_close(server_pipe);
56 static void linphone_gtk_init_pipe(const char *name){
57 pipe_name=g_strdup(name);
58 server_pipe=ortp_server_pipe_create(name);
59 if (server_pipe==(ortp_pipe_t)-1){
60 g_warning("Fail to create server pipe for name %s: %s",name,strerror(errno));
62 ms_thread_create(&pipe_thread,NULL,server_pipe_thread,NULL);
65 bool_t linphone_gtk_init_instance(const char *app_name, const char *addr_to_call){
66 ortp_pipe_t p=ortp_client_pipe_connect(app_name);
67 if (p!=(ortp_pipe_t)-1){
69 g_message("There is already a running instance.");
70 if (addr_to_call!=NULL){
71 strncpy((char*)buf,addr_to_call,sizeof(buf)-1);
73 if (ortp_pipe_write(p,buf,sizeof(buf))==-1){
74 g_error("Fail to send wakeup command to running instance: %s",strerror(errno));
76 g_message("Message to running instance sent.");
78 ortp_client_pipe_close(p);
81 linphone_gtk_init_pipe(app_name);
86 void linphone_gtk_uninit_instance(void){
87 if (server_pipe!=(ortp_pipe_t)-1){
89 server_pipe_running=FALSE;
90 /*this is to unblock the accept() of the server pipe*/
91 client=ortp_client_pipe_connect(pipe_name);
92 ortp_pipe_write(client,(uint8_t*)" ",1);
93 ortp_client_pipe_close(client);
94 ms_thread_join(pipe_thread,NULL);
95 server_pipe=(ortp_pipe_t)-1;