Diff of /trunk/src/geotoad.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 207 by harbaum, Tue Nov 24 14:02:35 2009 UTC revision 208 by harbaum, Tue Nov 24 15:21:22 2009 UTC
# Line 68  typedef struct { Line 68  typedef struct {
68    
69    GtkWidget *username, *password, *filename;    GtkWidget *username, *password, *filename;
70    GtkWidget *lat, *lon, *dst;    GtkWidget *lat, *lon, *dst;
71    
72      int use_cnt;
73    
74  } gt_context_t;  } gt_context_t;
75    
# Line 76  static void arg_free(gpointer data, gpoi Line 78  static void arg_free(gpointer data, gpoi
78  }  }
79    
80  static void context_free(gt_context_t *context) {  static void context_free(gt_context_t *context) {
81    //  printf("freeing context\n");    context->use_cnt--;
82    
83      if(context->use_cnt > 0)
84        printf("still in use by %d, keeping context\n", context->use_cnt);
85      else {
86        printf("freeing context\n");
87    
88    if(context->info) g_free(context->info);      if(context->info) g_free(context->info);
89    
90    g_ptr_array_foreach(context->argv, arg_free, NULL);      g_ptr_array_foreach(context->argv, arg_free, NULL);
91    g_ptr_array_free (context->argv, TRUE);      g_ptr_array_free (context->argv, TRUE);
92    
93    g_free(context);      g_free(context);
94      }
95  }  }
96    
97  static void appendf(struct log_s *log, char *colname,  static void appendf(struct log_s *log, char *colname,
# Line 211  static FILE *gt_popen(gt_context_t *cont Line 219  static FILE *gt_popen(gt_context_t *cont
219    
220      /* this printf will actually be redirected through the pipe */      /* this printf will actually be redirected through the pipe */
221      printf("Error: Failed to execute!\n");      printf("Error: Failed to execute!\n");
222        context_free(context);
223        exit(0);
224    } else {         /* we're having major problems... */    } else {         /* we're having major problems... */
225      close(p[0]);      close(p[0]);
226      close(p[1]);      close(p[1]);
227    
228      /* this printf will actually be redirected through the pipe */      /* this printf will actually be redirected through the pipe??? No! */
229      printf("Error: Failed to fork!\n");      printf("Error: Failed to fork!\n");
230    }    }
231    
# Line 235  static gpointer thread_worker(gt_context Line 245  static gpointer thread_worker(gt_context
245    
246    fh = gt_popen(context, (char**)(context->argv->pdata),"r", &context->pid);    fh = gt_popen(context, (char**)(context->argv->pdata),"r", &context->pid);
247    if(!fh) {    if(!fh) {
248      append_parentf(context, COLOR_ERR, _("Failed to run GeoToad"));      printf("fail free\n");
249        context_free(context);
250        //    g_thread_exit(NULL);
251      return NULL;      return NULL;
252    }    }
253    
254      /* the client is running */
255      printf("client inc use_cnt\n");
256      context->use_cnt++;
257    
258    /* switch to line buffered mode */    /* switch to line buffered mode */
259    if(setvbuf(fh, NULL, _IOLBF, 0))    if(setvbuf(fh, NULL, _IOLBF, 0))
260      perror("setvbuf(_IOLBF)");      perror("setvbuf(_IOLBF)");
# Line 261  static gpointer thread_worker(gt_context Line 277  static gpointer thread_worker(gt_context
277    g_io_channel_unref(gh);    g_io_channel_unref(gh);
278    pclose(fh);    pclose(fh);
279    append_parentf(context, COLOR_SYSTEM, "Job done!");    append_parentf(context, COLOR_SYSTEM, "Job done!");
280    
281    g_thread_exit(NULL);    /* TODO: this happens on the copy!!!! */;
282      printf("client context free = %d\n", context->use_cnt);
283    context_free(context);    context_free(context);
284    
285      //  g_thread_exit(NULL);
286    return NULL;    return NULL;
287  }  }
288    
# Line 282  static void run(gt_context_t *context) { Line 300  static void run(gt_context_t *context) {
300    
301    /* build list of arguments to call geotoad */    /* build list of arguments to call geotoad */
302    context->argv = g_ptr_array_new();    context->argv = g_ptr_array_new();
303    g_ptr_array_add (context->argv, g_strdup_printf(GEOTOAD));    g_ptr_array_add (context->argv, g_strdup_printf(GEOTOAD "a"));
304    g_ascii_dtostr(str, sizeof(str), context->appdata->gt.distance);    g_ascii_dtostr(str, sizeof(str), context->appdata->gt.distance);
305    g_ptr_array_add (context->argv, g_strdup_printf("--distanceMax=%s", str));    g_ptr_array_add (context->argv, g_strdup_printf("--distanceMax=%s", str));
306    g_ptr_array_add (context->argv, g_strdup_printf("--output=%s", context->appdata->gt.filename));    g_ptr_array_add (context->argv, g_strdup_printf("--output=%s", context->appdata->gt.filename));
# Line 591  void geotoad(appdata_t *appdata) { Line 609  void geotoad(appdata_t *appdata) {
609    
610    gt_context_t *context = g_new0(gt_context_t, 1);    gt_context_t *context = g_new0(gt_context_t, 1);
611    context->appdata = appdata;    context->appdata = appdata;
612      context->use_cnt++;          // parent still uses this
613    
614    context->update_mutex = g_mutex_new();    context->update_mutex = g_mutex_new();
615    context->update_cond = g_cond_new();    context->update_cond = g_cond_new();
# Line 600  void geotoad(appdata_t *appdata) { Line 619  void geotoad(appdata_t *appdata) {
619    
620    if(gui_setup(context))    if(gui_setup(context))
621      gui_run(context);      gui_run(context);
622    
623      printf("main context free\n");
624      context_free(context);
625  }  }
626    
627  gboolean geotoad_available(void) {  gboolean geotoad_available(void) {

Legend:
Removed from v.207  
changed lines
  Added in v.208