#include <liberipc/eripc.h>
Go to the source code of this file.
Functions | |
G_BEGIN_DECLS gboolean | conn_add_profile (const char *medium) |
gboolean | conn_edit_profile (const char *medium, const char *profile) |
gboolean | conn_connect (const char *ipc_service, const char *medium, const char *profile) |
gboolean | conn_disconnect (const char *ipc_service) |
gboolean | conn_set_status (gboolean is_connected, const char *medium, const char *profile, const char *reason) |
gboolean | conn_status_request (const char *ipc_service) |
void | conn_on_statusitem_activated (void) |
void | conn_set_flightmode (gboolean is_enabled) |
void | conn_update_statusbar (void) |
void | conn_check_battery (gint level) |
void | conn_set_initialising (gboolean is_init) |
void | conn_on_enter_standby (void) |
void | conn_on_leave_standby (void) |
void | conn_stop (void) |
gboolean | conn_is_stopped (void) |
gboolean | conn_is_online (void) |
gboolean | conn_is_initialising (void) |
G_BEGIN_DECLS gboolean conn_add_profile | ( | const char * | medium | ) |
File Name : connections.h
Description: The functions for network connectivity Copyright (C) 2009 iRex Technologies B.V. All rights reserved.
Definition at line 980 of file connections.c.
References LOGPRINTF, and UNUSED.
Referenced by cb_conn_add_profile().
void conn_check_battery | ( | gint | level | ) |
Definition at line 362 of file connections.c.
References conn_disable_lowbatt(), conn_enable_lowbatt(), conn_is_online(), ipc_show_message(), and MIN_BATTERY_LEVEL_3G_KEEP.
Referenced by update_battery_info().
00363 { 00364 static gboolean warning_shown = FALSE; 00365 00366 if (level < MIN_BATTERY_LEVEL_3G_KEEP) 00367 { 00368 conn_enable_lowbatt(); 00369 } 00370 else if ((level <= MIN_BATTERY_LEVEL_3G_KEEP) && conn_is_online()) 00371 { 00372 if (!warning_shown) 00373 { 00374 // show pre warning when nearing minimum battery level 00375 ipc_show_message("3glowwarning", NULL, NULL); 00376 warning_shown = TRUE; 00377 } 00378 } 00379 else 00380 { 00381 conn_disable_lowbatt(); 00382 if (warning_shown) 00383 { 00384 warning_shown = FALSE; 00385 } 00386 } 00387 }
gboolean conn_connect | ( | const char * | ipc_service, | |
const char * | medium, | |||
const char * | profile | |||
) |
Definition at line 729 of file connections.c.
References app_add(), busy_add_foreground(), BUSY_DIALOG_DIRECT, CONN_STATE_CONNECTED, CONN_STATE_CONNECTING, CONN_STATE_DISCONNECTED, CONN_STATE_DISCONNECTING, CONN_STATE_FLIGHTMODE, CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, CONN_STATE_LOADING, CONN_STATE_LOWBATT, CONN_STATE_OFF, conn_state_str, CONN_STATE_UNLOADING, g_conn_state, g_profile, g_request, get_cooloff(), ipc_connect(), ipc_send_conn_status(), proc_t::ipc_service, ipc_show_message(), LOGPRINTF, MIN_BATTERY_LEVEL_3G_START, on_flightmode_dialog_return(), on_lowbatt_dialog_return(), REQ_CONNECT, set_conn_state(), set_request(), set_string, start_medium(), sys_battery_level(), sys_is_emulator(), and WARNPRINTF.
Referenced by cb_conn_connect().
00730 { 00731 gboolean retval = FALSE; 00732 int cooloff = get_cooloff(); 00733 00734 LOGPRINTF("state=%s req=%s medium=[%s] profile=[%s]", conn_state_str[g_conn_state], 00735 req_names[g_request], medium ? medium : "NULL", profile ? profile : "NULL"); 00736 00737 if (g_conn_state==CONN_STATE_INITIALISING) 00738 { 00739 LOGPRINTF("Connection still initialising, waiting until complete"); 00740 busy_add_foreground(0, BUSY_DIALOG_DIRECT, NULL); 00741 set_conn_state(CONN_STATE_INIT_WAITING); 00742 return TRUE; 00743 } 00744 00745 // it's possible to open new connections when already online 00746 // but don't start new connections when OFFLINE and below MIN_BATTERY_LEVEL_3G_START 00747 if (g_conn_state == CONN_STATE_OFF && sys_battery_level() < MIN_BATTERY_LEVEL_3G_START) 00748 { 00749 ipc_show_message("3glowconnect", on_lowbatt_dialog_return, g_strdup(ipc_service)); 00750 return FALSE; 00751 } 00752 00753 if (cooloff > 0) 00754 { 00755 LOGPRINTF("Need to cool off for another %d minutes [%d]", (cooloff+60-1) / 60, cooloff); 00756 gchar *message = g_strdup_printf("3gcooloff_%d", (cooloff+60-1) / 60); 00757 ipc_show_message(message, on_lowbatt_dialog_return, g_strdup(ipc_service)); 00758 g_free(message); 00759 return FALSE; 00760 } 00761 00762 if (g_conn_state != CONN_STATE_FLIGHTMODE) { 00763 app_add(ipc_service); 00764 set_string(g_profile, profile); // not used 00765 } 00766 00767 // on emulator: always return connected 00768 if (sys_is_emulator() && g_conn_state != CONN_STATE_FLIGHTMODE) { 00769 WARNPRINTF("emulator mode"); 00770 ipc_send_conn_status(ipc_service, TRUE, medium, profile, NULL); 00771 return TRUE; 00772 } 00773 00774 switch (g_conn_state) { 00775 case CONN_STATE_INITIALISING: 00776 case CONN_STATE_INIT_WAITING: 00777 break; 00778 case CONN_STATE_OFF: 00779 set_conn_state(CONN_STATE_LOADING); 00780 set_request(REQ_CONNECT); 00781 start_medium(medium); 00782 retval = TRUE; 00783 break; 00784 case CONN_STATE_LOWBATT: 00785 ipc_show_message("3glowconnect", on_lowbatt_dialog_return, g_strdup(ipc_service)); 00786 break; 00787 case CONN_STATE_FLIGHTMODE: 00788 ipc_show_message("flightmode", on_flightmode_dialog_return, g_strdup(ipc_service)); 00789 break; 00790 case CONN_STATE_DISCONNECTED: 00791 set_conn_state(CONN_STATE_CONNECTING); 00792 set_request(REQ_CONNECT); 00793 ipc_connect(g_service->ipc_service, medium, profile); 00794 retval = TRUE; 00795 break; 00796 case CONN_STATE_CONNECTED: 00797 ipc_send_conn_status(ipc_service, TRUE, medium, profile, NULL); 00798 retval = TRUE; 00799 break; 00800 case CONN_STATE_LOADING: 00801 case CONN_STATE_UNLOADING: 00802 case CONN_STATE_CONNECTING: 00803 case CONN_STATE_DISCONNECTING: 00804 set_request(REQ_CONNECT); 00805 retval = TRUE; 00806 break; 00807 default: 00808 WARNPRINTF("unhandled state [%d]", g_conn_state); 00809 break; 00810 } 00811 return retval; 00812 }
gboolean conn_disconnect | ( | const char * | ipc_service | ) |
Definition at line 816 of file connections.c.
References app_count(), app_remove(), CONN_STATE_CONNECTED, CONN_STATE_CONNECTING, CONN_STATE_DISCONNECTED, CONN_STATE_DISCONNECTING, CONN_STATE_FLIGHTMODE, CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, CONN_STATE_LOADING, CONN_STATE_LOWBATT, CONN_STATE_OFF, conn_state_str, CONN_STATE_UNLOADING, g_conn_state, g_medium, g_profile, g_request, ipc_disconnect(), ipc_send_conn_status(), proc_t::ipc_service, LOGPRINTF, REQ_DISCONNECT, set_conn_state(), set_request(), sys_is_emulator(), and WARNPRINTF.
Referenced by cb_conn_disconnect(), and on_process_exit().
00817 { 00818 LOGPRINTF("state=%s req=%s", conn_state_str[g_conn_state], req_names[g_request]); 00819 00820 app_remove(ipc_service); 00821 00822 if (sys_is_emulator()) { 00823 WARNPRINTF("emulator mode"); 00824 ipc_send_conn_status(ipc_service, FALSE, g_medium, g_profile, NULL); 00825 return TRUE; 00826 } 00827 00828 switch (g_conn_state) { 00829 case CONN_STATE_INITIALISING: 00830 case CONN_STATE_INIT_WAITING: 00831 case CONN_STATE_OFF: 00832 case CONN_STATE_FLIGHTMODE: 00833 case CONN_STATE_LOWBATT: 00834 case CONN_STATE_DISCONNECTED: 00835 LOGPRINTF("got disconnect request in state %s - cleanup", conn_state_str[g_conn_state]); 00836 return FALSE; 00837 case CONN_STATE_CONNECTED: 00838 if (app_count() == 0) { 00839 // no applications using connection, disconnect 00840 set_conn_state(CONN_STATE_DISCONNECTING); 00841 set_request(REQ_DISCONNECT); 00842 ipc_disconnect(g_service->ipc_service); 00843 } 00844 break; 00845 case CONN_STATE_LOADING: 00846 case CONN_STATE_UNLOADING: 00847 case CONN_STATE_CONNECTING: 00848 if (app_count() == 0) { 00849 set_request(REQ_DISCONNECT); 00850 } 00851 return TRUE; 00852 case CONN_STATE_DISCONNECTING: 00853 if (app_count() == 0) { 00854 set_request(REQ_DISCONNECT); 00855 // try to cancel connecting by sending disconnect to ConnMgr 00856 LOGPRINTF("trying to cancel conn. mgr"); 00857 ipc_disconnect(g_service->ipc_service); 00858 } 00859 return TRUE; 00860 } 00861 return FALSE; 00862 }
gboolean conn_edit_profile | ( | const char * | medium, | |
const char * | profile | |||
) |
Definition at line 989 of file connections.c.
References LOGPRINTF, and UNUSED.
Referenced by cb_conn_edit_profile().
00990 { 00991 UNUSED(medium); 00992 UNUSED(profile); 00993 LOGPRINTF("entry"); 00994 return FALSE; 00995 }
gboolean conn_is_initialising | ( | void | ) |
Definition at line 345 of file connections.c.
References CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, and g_conn_state.
Referenced by on_idle_timeout().
00346 { 00347 return (g_conn_state == CONN_STATE_INITIALISING || 00348 g_conn_state == CONN_STATE_INIT_WAITING); 00349 }
gboolean conn_is_online | ( | void | ) |
Definition at line 339 of file connections.c.
References CONN_STATE_CONNECTED, and g_conn_state.
Referenced by conn_check_battery(), on_idle_timeout(), and sys_update_rgb_led().
00340 { 00341 return (g_conn_state == CONN_STATE_CONNECTED); 00342 }
gboolean conn_is_stopped | ( | void | ) |
Definition at line 352 of file connections.c.
References CONN_STATE_FLIGHTMODE, CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, CONN_STATE_LOWBATT, CONN_STATE_OFF, and g_conn_state.
00353 { 00354 return (g_conn_state == CONN_STATE_OFF || 00355 g_conn_state == CONN_STATE_FLIGHTMODE || 00356 g_conn_state == CONN_STATE_LOWBATT || 00357 g_conn_state == CONN_STATE_INITIALISING || 00358 g_conn_state == CONN_STATE_INIT_WAITING); 00359 }
void conn_on_enter_standby | ( | void | ) |
Definition at line 302 of file connections.c.
References CONN_STATE_FLIGHTMODE, g_conn_state, LOGPRINTF, and sys_spawn_sync().
Referenced by conn_enable_flightmode(), conn_set_initialising(), and on_medium_exited().
00303 { 00304 #if MACHINE_IS_DR800SG 00305 if (g_conn_state != CONN_STATE_FLIGHTMODE) { 00306 LOGPRINTF("Disabling 3g"); 00307 sys_spawn_sync("3g_off.sh"); 00308 } 00309 #endif 00310 }
void conn_on_leave_standby | ( | void | ) |
Definition at line 313 of file connections.c.
References conn_set_initialising(), CONN_STATE_FLIGHTMODE, g_conn_state, LOGPRINTF, and sys_spawn_async_with_callback().
Referenced by enter_off_state().
00314 { 00315 #if MACHINE_IS_DR800SG 00316 if (g_conn_state != CONN_STATE_FLIGHTMODE) { 00317 LOGPRINTF("Enabling 3g"); 00318 conn_set_initialising(TRUE); 00319 sys_spawn_async_with_callback("3g_boot.sh", on_3g_ready, NULL); 00320 } 00321 #endif 00322 }
void conn_on_statusitem_activated | ( | void | ) |
Definition at line 1173 of file connections.c.
References conf_set_flightmode(), CONN_STATE_FLIGHTMODE, and g_conn_state.
Referenced by cb_status_item_activated().
01174 { 01175 if (g_conn_state == CONN_STATE_FLIGHTMODE) 01176 { 01177 conf_set_flightmode(FALSE); 01178 } 01179 }
void conn_set_flightmode | ( | gboolean | is_enabled | ) |
Definition at line 1160 of file connections.c.
References conn_disable_flightmode(), conn_enable_flightmode(), and LOGPRINTF.
Referenced by enter_off_state(), event_gconf_value_changed(), and set_startup_defaults().
01161 { 01162 LOGPRINTF("entry: is_enabled [%d]", is_enabled); 01163 01164 if (is_enabled) { 01165 conn_enable_flightmode(); 01166 } else { 01167 conn_disable_flightmode(); 01168 } 01169 }
void conn_set_initialising | ( | gboolean | is_init | ) |
Definition at line 568 of file connections.c.
References busy_remove_foreground(), conn_on_enter_standby(), CONN_STATE_FLIGHTMODE, CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, CONN_STATE_LOADING, CONN_STATE_OFF, conn_update_statusbar(), g_conn_state, g_request, LOGPRINTF, REQ_CONNECT, REQ_FLIGHTMODE, set_conn_state(), set_request(), start_medium(), and WARNPRINTF.
Referenced by conn_on_leave_standby().
00569 { 00570 LOGPRINTF("entry [%d]", is_init); 00571 00572 if (is_init) { 00573 // if we're initialising, just set the state 00574 set_conn_state(CONN_STATE_INITIALISING); 00575 } else { 00576 if (g_request == REQ_FLIGHTMODE) { 00577 // flight mode was enabled during init, shut it down 00578 WARNPRINTF("Flightmode was requested, but we were initialising. Shutting down"); 00579 conn_on_enter_standby(); 00580 set_conn_state(CONN_STATE_FLIGHTMODE); 00581 conn_update_statusbar(); 00582 } else if (g_conn_state==CONN_STATE_INIT_WAITING) { 00583 // connection requested, go immediately to connecting 00584 LOGPRINTF("3G now ready, starting"); 00585 busy_remove_foreground(0); 00586 set_conn_state(CONN_STATE_LOADING); 00587 set_request(REQ_CONNECT); 00588 start_medium("3g"); 00589 } else { 00590 // no connection requested, just go to off 00591 LOGPRINTF("3G now ready"); 00592 set_conn_state(CONN_STATE_OFF); 00593 } 00594 } 00595 }
gboolean conn_set_status | ( | gboolean | is_connected, | |
const char * | medium, | |||
const char * | profile, | |||
const char * | reason | |||
) |
Definition at line 932 of file connections.c.
References handle_connected_event(), and handle_disconnected_event().
Referenced by cb_conn_status().
00933 { 00934 int rc = FALSE; 00935 if (is_connected) { 00936 rc = handle_connected_event(medium, profile); 00937 } else { 00938 rc = handle_disconnected_event(medium, profile, reason); 00939 } 00940 return rc; 00941 }
gboolean conn_status_request | ( | const char * | ipc_service | ) |
Definition at line 945 of file connections.c.
References CONN_STATE_CONNECTED, CONN_STATE_CONNECTING, CONN_STATE_DISCONNECTED, CONN_STATE_DISCONNECTING, CONN_STATE_FLIGHTMODE, CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, CONN_STATE_LOADING, CONN_STATE_LOWBATT, CONN_STATE_OFF, conn_state_str, CONN_STATE_UNLOADING, g_conn_state, g_disconnect_reason, g_medium, g_profile, ipc_send_conn_status(), LOGPRINTF, and WARNPRINTF.
Referenced by cb_conn_status_request().
00946 { 00947 gboolean rc = FALSE; 00948 00949 LOGPRINTF("entry"); 00950 00951 switch (g_conn_state) 00952 { 00953 case CONN_STATE_CONNECTED: 00954 ipc_send_conn_status(ipc_service, TRUE, g_medium, g_profile, ""); 00955 rc = TRUE; 00956 break; 00957 00958 case CONN_STATE_INITIALISING: 00959 case CONN_STATE_INIT_WAITING: 00960 case CONN_STATE_OFF: 00961 case CONN_STATE_FLIGHTMODE: 00962 case CONN_STATE_LOWBATT: 00963 case CONN_STATE_DISCONNECTED: 00964 ipc_send_conn_status(ipc_service, FALSE, NULL, NULL, g_disconnect_reason); 00965 rc = TRUE; 00966 break; 00967 00968 case CONN_STATE_LOADING: 00969 case CONN_STATE_UNLOADING: 00970 case CONN_STATE_CONNECTING: 00971 case CONN_STATE_DISCONNECTING: 00972 WARNPRINTF("Received status request but state is %s. Status will follow", conn_state_str[g_conn_state]); 00973 break; 00974 } 00975 return rc; 00976 }
void conn_stop | ( | void | ) |
Definition at line 1182 of file connections.c.
References busy_remove_foreground(), CONN_STATE_CONNECTED, CONN_STATE_CONNECTING, CONN_STATE_DISCONNECTED, CONN_STATE_DISCONNECTING, CONN_STATE_FLIGHTMODE, CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, CONN_STATE_LOADING, CONN_STATE_LOWBATT, CONN_STATE_OFF, conn_state_str, CONN_STATE_UNLOADING, enter_off_state(), g_conn_state, g_request, ipc_disconnect(), proc_t::ipc_service, LOGPRINTF, REQ_DISCONNECT, set_conn_state(), set_request(), and stop_medium().
01183 { 01184 LOGPRINTF("state=%s req=%s", conn_state_str[g_conn_state], req_names[g_request]); 01185 switch (g_conn_state) 01186 { 01187 case CONN_STATE_OFF: 01188 case CONN_STATE_FLIGHTMODE: 01189 case CONN_STATE_LOWBATT: 01190 // already unloaded 01191 break; 01192 case CONN_STATE_INIT_WAITING: 01193 set_request(REQ_DISCONNECT); 01194 // NOTE: cancel connect request by sending disconnect 01195 // even though medium is not running yet 01196 busy_remove_foreground(0); 01197 enter_off_state(); 01198 break; 01199 case CONN_STATE_INITIALISING: 01200 case CONN_STATE_LOADING: 01201 case CONN_STATE_UNLOADING: 01202 case CONN_STATE_DISCONNECTING: 01203 set_request(REQ_DISCONNECT); 01204 break; 01205 case CONN_STATE_CONNECTING: 01206 set_request(REQ_DISCONNECT); 01207 // NOTE: cancel connect request by sending disconnect 01208 ipc_disconnect(g_service->ipc_service); 01209 break; 01210 case CONN_STATE_CONNECTED: 01211 set_request(REQ_DISCONNECT); 01212 set_conn_state(CONN_STATE_DISCONNECTING); 01213 ipc_disconnect(g_service->ipc_service); 01214 break; 01215 case CONN_STATE_DISCONNECTED: 01216 set_request(REQ_DISCONNECT); 01217 set_conn_state(CONN_STATE_UNLOADING); 01218 stop_medium(); 01219 break; 01220 } 01221 }
void conn_update_statusbar | ( | void | ) |
Definition at line 538 of file connections.c.
References CONN_STATE_CONNECTED, CONN_STATE_CONNECTING, CONN_STATE_DISCONNECTED, CONN_STATE_DISCONNECTING, CONN_STATE_FLIGHTMODE, CONN_STATE_INIT_WAITING, CONN_STATE_INITIALISING, CONN_STATE_LOADING, CONN_STATE_LOWBATT, CONN_STATE_OFF, CONN_STATE_UNLOADING, g_conn_state, g_medium, and ipc_menu_set_statusitem_state().
Referenced by conn_enable_flightmode(), conn_enable_lowbatt(), conn_set_initialising(), enter_connected_state(), enter_disconnected_state(), enter_off_state(), and on_phase_1_complete().
00539 { 00540 const char* state = NULL; 00541 switch (g_conn_state) { 00542 case CONN_STATE_INITIALISING: 00543 case CONN_STATE_INIT_WAITING: 00544 state = "disabled"; 00545 break; 00546 case CONN_STATE_FLIGHTMODE: 00547 state = "flightmode"; 00548 break; 00549 case CONN_STATE_CONNECTED: 00550 state = "connected"; 00551 break; 00552 case CONN_STATE_OFF: 00553 case CONN_STATE_LOWBATT: 00554 case CONN_STATE_LOADING: 00555 case CONN_STATE_UNLOADING: 00556 case CONN_STATE_CONNECTING: 00557 case CONN_STATE_DISCONNECTED: 00558 case CONN_STATE_DISCONNECTING: 00559 state = "disconnected"; 00560 break; 00561 } 00562 gchar *icon = g_strdup_printf("statusbar_%s", g_medium); 00563 ipc_menu_set_statusitem_state(icon, state); 00564 g_free(icon); 00565 }