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=NULL;
28 gchar *make_name(const char *appname){
29 const char *username=getenv("USER");
31 return g_strdup_printf("%s-%s",appname,username);
33 return g_strdup(appname);
36 static gboolean execute_wakeup(char *uri){
37 linphone_gtk_show_main_window();
39 linphone_gtk_refer_received(linphone_gtk_get_core(),uri);
44 static void * server_pipe_thread(void *pointer){
48 child=ortp_server_pipe_accept_client(server_pipe);
49 if (server_pipe_running && child!=(ortp_pipe_t)-1){
51 if (ortp_pipe_read(child,(uint8_t*)buf,sizeof(buf))>0){
52 g_message("Received wakeup command with arg %s",buf);
54 g_timeout_add(20,(GSourceFunc)execute_wakeup,g_strdup(buf));
57 ortp_server_pipe_close_client(child);
59 }while(server_pipe_running);
60 ortp_server_pipe_close(server_pipe);
64 static void linphone_gtk_init_pipe(const char *name){
65 server_pipe=ortp_server_pipe_create(name);
66 if (server_pipe==(ortp_pipe_t)-1){
67 g_warning("Fail to create server pipe for name %s: %s",name,strerror(errno));
69 ms_thread_create(&pipe_thread,NULL,server_pipe_thread,NULL);
72 bool_t linphone_gtk_init_instance(const char *app_name, const char *addr_to_call){
73 pipe_name=make_name(app_name);
74 ortp_pipe_t p=ortp_client_pipe_connect(pipe_name);
75 if (p!=(ortp_pipe_t)-1){
77 g_message("There is already a running instance.");
78 if (addr_to_call!=NULL){
79 strncpy((char*)buf,addr_to_call,sizeof(buf)-1);
81 if (ortp_pipe_write(p,buf,sizeof(buf))==-1){
82 g_error("Fail to send wakeup command to running instance: %s",strerror(errno));
84 g_message("Message to running instance sent.");
86 ortp_client_pipe_close(p);
89 linphone_gtk_init_pipe(pipe_name);
94 void linphone_gtk_uninit_instance(void){
95 if (server_pipe!=(ortp_pipe_t)-1){
97 server_pipe_running=FALSE;
98 /*this is to unblock the accept() of the server pipe*/
99 client=ortp_client_pipe_connect(pipe_name);
100 ortp_pipe_write(client,(uint8_t*)" ",1);
101 ortp_client_pipe_close(client);
102 ms_thread_join(pipe_thread,NULL);
103 server_pipe=(ortp_pipe_t)-1;