Changeset 2462
- Timestamp:
- 08/17/07 15:48:42 (1 year ago)
- Files:
-
- plugins/opie-sync/src/opie_sync.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/opie-sync/src/opie_sync.c
r2450 r2462 138 138 } 139 139 140 static osync_bool _connectDevice(OpiePluginEnv *env, OSyncError **error) 140 141 /** 142 * If QCop is enabled, connect to the the QCop bridge on the remote device and 143 * signal that a sync is starting 144 */ 145 static osync_bool device_connect(OpiePluginEnv *env, OSyncError **error) 141 146 { 142 147 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, error); 143 char* errmsg = NULL; 144 145 if (env->qcopconn) 146 { 148 149 if (env->qcopconn) { 147 150 osync_trace(TRACE_EXIT, "%s: Already connected", __func__); 148 151 return TRUE; 149 152 } 150 153 151 /* Connect to QCopBridgeServer to lock GUI and get root path */ 152 if ( env->use_qcop ) 153 { 154 if ( env->use_qcop ) { 155 /* Connect to QCopBridgeServer to lock GUI and get root path */ 154 156 osync_trace(TRACE_INTERNAL, "qcop_connect"); 155 157 env->qcopconn = qcop_connect(env->url, 156 158 env->username, 157 159 env->password); 158 if (env->qcopconn->result) 159 { 160 qcop_start_sync(env->qcopconn, &sync_cancelled); 161 if (!env->qcopconn->result) 162 { 163 osync_trace(TRACE_INTERNAL, "qcop_start_sync_failed"); 164 errmsg = g_strdup(env->qcopconn->resultmsg); 165 qcop_stop_sync(env->qcopconn); 166 qcop_freeqconn(env->qcopconn); 167 env->qcopconn = NULL; 168 osync_error_set(error, OSYNC_ERROR_GENERIC, errmsg); 169 goto error; 170 } 171 } 172 else 173 { 174 osync_trace(TRACE_INTERNAL, "QCop connection failed"); 175 errmsg = g_strdup(env->qcopconn->resultmsg); 176 qcop_freeqconn(env->qcopconn); 160 if(!env->qcopconn->result) { 161 char *errmsg = g_strdup_printf("qcop_connect failed: %s", env->qcopconn->resultmsg); 162 osync_error_set(error, OSYNC_ERROR_GENERIC, errmsg); 163 g_free(errmsg); 164 goto error; 165 } 166 167 qcop_start_sync(env->qcopconn, &sync_cancelled); 168 if(!env->qcopconn->result) { 169 char *errmsg = g_strdup_printf("qcop_start_sync_failed: %s", env->qcopconn->resultmsg); 170 osync_error_set(error, OSYNC_ERROR_GENERIC, errmsg); 171 g_free(errmsg); 172 qcop_stop_sync(env->qcopconn); 173 goto error; 174 } 175 176 } 177 178 osync_trace(TRACE_EXIT, "%s", __func__); 179 return TRUE; 180 181 error: 182 if(env->qcopconn) { 183 qcop_freeqconn(env->qcopconn); 184 env->qcopconn = NULL; 185 } 186 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 187 return FALSE; 188 } 189 190 /** 191 * If QCop is enabled & connected, signal that syncing has finished 192 */ 193 static osync_bool device_disconnect(OpiePluginEnv *env, OSyncError **error) 194 { 195 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, error); 196 197 if(env->qcopconn) { 198 qcop_stop_sync(env->qcopconn); 199 if (!env->qcopconn->result) { 200 char *errmsg = g_strdup_printf("qcop_stop_sync_failed: %s", env->qcopconn->resultmsg); 201 osync_error_set(error, OSYNC_ERROR_GENERIC, errmsg); 202 g_free(errmsg); 203 qcop_disconnect(env->qcopconn); /* frees qcopconn */ 177 204 env->qcopconn = NULL; 178 osync_error_set(error, OSYNC_ERROR_GENERIC, errmsg);179 205 goto error; 180 206 } 207 else { 208 qcop_disconnect(env->qcopconn); /* frees qcopconn */ 209 env->qcopconn = NULL; 210 } 181 211 } 182 212 183 213 osync_trace(TRACE_EXIT, "%s", __func__); 184 214 return TRUE; 185 215 186 216 error: 187 217 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); … … 189 219 } 190 220 191 void _disconnectDevice(OpiePluginEnv *env)192 {193 if(env->qcopconn)194 {195 qcop_stop_sync(env->qcopconn);196 if (!env->qcopconn->result)197 {198 osync_trace(TRACE_INTERNAL, env->qcopconn->resultmsg);199 }200 qcop_disconnect(env->qcopconn); /* frees qcopconn */201 env->qcopconn = NULL;202 }203 }204 221 205 222 static void connect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) … … 215 232 if(!env->plugin_env->connected) { 216 233 /* We only want to connect once per session */ 217 if (!_connectDevice(env->plugin_env, &error)) { 234 235 if (!device_connect(env->plugin_env, &error)) { 218 236 g_mutex_unlock(env->plugin_env->plugin_mutex); 219 237 goto error; … … 234 252 /* failed */ 235 253 char *errmsg; 236 if(env->plugin_env->qcopconn) 237 { 238 qcop_stop_sync(env->plugin_env->qcopconn); 239 if(!env->plugin_env->qcopconn->result) 240 { 241 osync_trace(TRACE_INTERNAL, "qcop_stop_sync_failed"); 242 char *errmsg = g_strdup(env->plugin_env->qcopconn->resultmsg); 243 qcop_freeqconn(env->plugin_env->qcopconn); 244 env->plugin_env->qcopconn = NULL; 245 osync_error_set(&error, OSYNC_ERROR_GENERIC, errmsg); 246 goto error; 247 } 248 qcop_disconnect(env->plugin_env->qcopconn); 249 env->plugin_env->qcopconn = NULL; 250 } 254 device_disconnect(env->plugin_env, &error); 251 255 errmsg = g_strdup_printf("Failed to load data from device %s", env->plugin_env->url); 252 256 osync_error_set(&error, OSYNC_ERROR_GENERIC, errmsg); … … 643 647 } 644 648 645 _disconnectDevice(env); 649 OSyncError *error = NULL; 650 device_disconnect(env, &error); 646 651 647 652 comms_shutdown();
