int activate_sync_post(const char *mode) { GList *iter; log_debug("activate post sync"); if( sync_list == 0 ) { log_debug("No sync list! skipping post sync\n"); return 0; } #ifdef APP_SYNC_DBUS /* check dbus initialisation, skip dbus activated services if this fails */ if(!usb_moded_app_sync_init()) { log_debug("dbus setup failed => skipping dbus launched apps \n"); no_dbus = 1; } #endif /* APP_SYNC_DBUS */ /* go through list and launch apps */ for( iter = sync_list; iter; iter = g_list_next(iter) ) { struct list_elem *data = iter->data; if(!strcmp(mode, data->mode)) { /* launch only items marked as post, others are already running */ if(!data->post) continue; log_debug("launching post-enum-app %s\n", data->name); if(data->systemd) { if(systemd_control_service(data->name, SYSTEMD_START)) goto error; mark_active(data->name, 1); } else if(data->launch) { /* skipping if dbus session bus is not available, or not compiled in */ if(no_dbus) continue; #ifdef APP_SYNC_DBUS else if(usb_moded_dbus_app_launch(data->launch) != 0) goto error; #endif /* APP_SYNC_DBUS */ } } } return(0); error: log_warning("Error launching a service!\n"); return(1); }
/* @return 0 on succes, 1 if there is a failure */ int activate_sync(const char *mode) { GList *iter; int count = 0, count2 = 0; log_debug("activate sync"); /* Bump tag, see enumerate_usb() */ ++sync_tag; gettimeofday(&sync_tv, 0); if( sync_list == 0 ) { log_debug("No sync list! Enumerating\n"); enumerate_usb(NULL); return 0; } /* set list to inactive, mark other modes as active already */ for( iter = sync_list; iter; iter = g_list_next(iter) ) { struct list_elem *data = iter->data; count++; if(!strcmp(data->mode, mode)) data->active = 0; else { count2++; data->active = 1; } } /* if the number of active modes is equal to the number of existing modes we enumerate immediately */ if(count == count2) { log_debug("Nothing to launch.\n"); enumerate_usb(NULL); return(0); } #ifdef APP_SYNC_DBUS /* check dbus initialisation, skip dbus activated services if this fails */ if(!usb_moded_app_sync_init()) { log_debug("dbus setup failed => skipping dbus launched apps \n"); no_dbus = 1; } #endif /* APP_SYNC_DBUS */ /* start timer */ log_debug("Starting appsync timer\n"); g_timeout_add_seconds(2, enumerate_usb, NULL); /* go through list and launch apps */ for( iter = sync_list; iter; iter = g_list_next(iter) ) { struct list_elem *data = iter->data; if(!strcmp(mode, data->mode)) { /* launch items marked as post, will be launched after usb is up */ if(data->post) { mark_active(data->name); continue; } log_debug("launching app %s\n", data->name); if(data->systemd) { if(!systemd_control_service(data->name, SYSTEMD_START)) mark_active(data->name); else goto error; } #ifdef UPSTART else if(data->upstart) { if(!upstart_control_job(data->name, UPSTART_START)) mark_active(data->name); else goto error; } #endif /* UPSTART */ else if(data->launch) { /* skipping if dbus session bus is not available, or not compiled in */ if(no_dbus) mark_active(data->name); #ifdef APP_SYNC_DBUS else if(!usb_moded_dbus_app_launch(data->launch)) mark_active(data->name); else goto error; #endif /* APP_SYNC_DBUS */ } } } return(0); error: log_warning("Error launching a service!\n"); return(1); }
int activate_sync(const char *mode) { GList *iter; int count = 0, count2 = 0; log_debug("activate sync"); /* Bump tag, see enumerate_usb() */ ++sync_tag; gettimeofday(&sync_tv, 0); if( sync_list == 0 ) { enumerate_usb(NULL); return 0; } /* set list to inactive, mark other modes as active already */ for( iter = sync_list; iter; iter = g_list_next(iter) ) { struct list_elem *data = iter->data; count++; if(!strcmp(data->mode, mode)) data->active = 0; else { count2++; data->active = 1; } } /* if the number of active modes is equal to the number of existing modes we enumerate immediately */ if(count == count2) { log_debug("Nothing to launch.\n"); enumerate_usb(NULL); return(1); } /* add dbus filter. Use session bus for ready method call? */ if(!usb_moded_app_sync_init()) { log_debug("dbus setup failed => activate immediately \n"); enumerate_usb(NULL); return(1); } /* start timer */ log_debug("Starting appsync timer\n"); g_timeout_add_seconds(2, enumerate_usb, NULL); /* go through list and launch apps */ for( iter = sync_list; iter; iter = g_list_next(iter) ) { struct list_elem *data = iter->data; if(!strcmp(mode, data->mode)) { log_debug("launching app %s\n", data->launch); #ifdef UPSTART if(data->upstart) { if(!upstart_control_job(data->name, UPSTART_START)) mark_active(data->name); } else #endif /* UPSTART */ usb_moded_dbus_app_launch(data->launch); } } return(0); }
/* @return 0 on succes, 1 if there is a failure */ int activate_sync(const char *mode) { GList *iter; int count = 0; log_debug("activate sync"); /* Get start of activation timestamp */ gettimeofday(&sync_tv, 0); if( sync_list == 0 ) { log_debug("No sync list! Enumerating\n"); enumerate_usb(); return 0; } /* Count apps that need to be activated for this mode and * mark them as currently inactive */ for( iter = sync_list; iter; iter = g_list_next(iter) ) { struct list_elem *data = iter->data; if(!strcmp(data->mode, mode)) { ++count; data->state = APP_STATE_INACTIVE; } else { data->state = APP_STATE_DONTCARE; } } /* If there is nothing to activate, enumerate immediately */ if(count <= 0) { log_debug("Nothing to launch.\n"); enumerate_usb(); return(0); } #ifdef APP_SYNC_DBUS /* check dbus initialisation, skip dbus activated services if this fails */ if(!usb_moded_app_sync_init()) { log_debug("dbus setup failed => skipping dbus launched apps \n"); no_dbus = 1; } #endif /* APP_SYNC_DBUS */ /* start timer */ start_enumerate_usb_timer(); /* go through list and launch apps */ for( iter = sync_list; iter; iter = g_list_next(iter) ) { struct list_elem *data = iter->data; if(!strcmp(mode, data->mode)) { /* do not launch items marked as post, will be launched after usb is up */ if(data->post) { continue; } log_debug("launching pre-enum-app %s\n", data->name); if(data->systemd) { if(!systemd_control_service(data->name, SYSTEMD_START)) mark_active(data->name, 0); else goto error; } else if(data->launch) { /* skipping if dbus session bus is not available, or not compiled in */ if(no_dbus) mark_active(data->name, 0); #ifdef APP_SYNC_DBUS else if(!usb_moded_dbus_app_launch(data->launch)) mark_active(data->name, 0); else goto error; #endif /* APP_SYNC_DBUS */ } } } return(0); error: log_warning("Error launching a service!\n"); return(1); }