Hello,

I've some problems with ecore_main_fd_handler_add(). In my application
a pipe is used to synchronize the asynchronous data generation thread
and the GUI. It works great in 8 of 10 app running cases. In 2 of 10
cases I start the application but the callback function from
ecore_main_fd_handler_add() is never called, no matter how much bytes I
throw into the pipe.

Before I start to debug the ecore functions I hope someone could look
over my code and help me to find the bug (if existing).

Here is the code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <Edje.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include <gps.h>



Ecore_Evas *ee;
Evas *evas;

Evas_Object *o_bg;
Evas_Object *o_edje;
Evas_Object *poly;

pthread_t gps_thread;
pthread_mutex_t gps_mutex = PTHREAD_MUTEX_INITIALIZER;

void resize_cb(Ecore_Evas *ee);
void print_help (char *app_name);
void gps_callback (struct gps_data_t *gps_data, char *buf,  size_t len,
int level);

int _fd_dp_active(void *data, Ecore_Fd_Handler *fdh);
void dispatcher_init ();
void dispatcher_signal ();

struct _Dispatcher
{
  int fd_read;
  int fd_write;
  void *data;
  Ecore_Fd_Handler *fd_handler;
  // callback function??
};

typedef struct _Dispatcher Dispatcher;

Dispatcher dp;
char edje_signal[13+3]; // holds up to 999 images; should be enough;

int main(int argc, char **argv)
{
  Evas_Object *o;
  int edje_w = 240;
  int edje_h = 240;
  char *theme;
  struct stat stat_buf;
  bool theme_default;
  char theme_default_name[] = "../data/empass.edj";
  struct gps_data_t *gpsData;
  
  switch (argc)
  {
  case 1:
    theme_default = !stat (theme_default_name, &stat_buf);
    if (theme_default)
      theme = theme_default_name;
    else
      print_help (argv[0]);
    break;
  case 2:
    theme = argv[1];
    break;
  default:
    print_help (argv[0]);
    break;
  }

  gpsData = gps_open ("localhost", "2947");

  if (gpsData)
  {
    gps_query (gpsData, "rw\n");
    gps_query (gpsData, "j=1\n");

    gps_set_callback (gpsData, &gps_callback, &gps_thread);
  }
  else
  {
    fprintf (stderr, "Warning: running without gpsd support!\n");
  }

  if (!ecore_init ())
  {
    fprintf (stderr, "Error while initializing Ecore!\n");
    exit (1);
  }
  
  ecore_app_args_set(argc, (const char **)argv);
 
  if (!ecore_evas_init ())
  {
    fprintf (stderr, "Error while initializing Ecore_Evas!\n");
    exit (1);
  }

  if (!edje_init())
  {
    fprintf (stderr, "Error while initializing Evas!\n");
    exit (1);
  }

  dispatcher_init ();

  // TODO: warum geht Xrender auf dem Latop nicht?
   /*if
(ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_XRENDER_X11))
ee = ecore_evas_xrender_x11_new(NULL, 0, 0, 0, edje_w, edje_h); else
    {*/
  if
(ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_X11))
ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, edje_w, edje_h); //}
  if (!ee)
  {
    if
(ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_FB))
ee = ecore_evas_fb_new(NULL, 270, edje_w, edje_h); if (!ee)
      ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, edje_w, edje_h);
    if (!ee)
    {
      fprintf(stderr, "Cannot create Canvas!\n");
      exit(-1);
    }
  }

  ecore_evas_shaped_set (ee, 1);
  ecore_evas_title_set (ee, "empass");

  //ecore_evas_borderless_set(ee, 1);
  ecore_evas_sticky_set(ee, 1);

  evas = ecore_evas_get(ee);
  evas_image_cache_set(evas, 8192 * 1024);
  evas_font_cache_set(evas, 512 * 1024);

  o = evas_object_rectangle_add(evas);
  evas_object_move(o, 0, 0);
  evas_object_resize(o, edje_w, edje_h);

  evas_object_color_set(o, 0, 0, 0, 0);
  evas_object_focus_set(o, 1);

  evas_object_show(o);
  o_bg = o;

  o = edje_object_add(evas);

  edje_object_file_set(o, theme, "main");
  evas_object_move(o, 0, 0);
  evas_object_resize(o, edje_w, edje_h);

  evas_object_show(o);
  o_edje = o;

  ecore_evas_callback_resize_set(ee, resize_cb);
  ecore_evas_show(ee);

  ecore_main_loop_begin();

  edje_shutdown();
  ecore_evas_shutdown();
  ecore_shutdown();

  return 0;
}

void dispatcher_init ()
{
  int fd[2];

   /* Create the file descriptors */
  if (pipe(fd) == 0) 
  {
    dp.fd_read = fd[0];
    dp.fd_write = fd[1];
    fcntl(dp.fd_read, F_SETFL, O_NONBLOCK);
    dp.fd_handler = ecore_main_fd_handler_add (dp.fd_read,
                                               ECORE_FD_READ,
                                               _fd_dp_active,
                                               &dp,
                                               NULL, NULL);
    ecore_main_fd_handler_active_set(dp.fd_handler, ECORE_FD_READ);
  }
  else
  {
    fprintf (stderr, "pipe() failed\n");
    exit (1);
  }
}

int _fd_dp_active (void *data, Ecore_Fd_Handler *fdh)
{
  int fd;
  int len;
  char buf[1];
  char edje_signal_local[13+3];
  unsigned char *frame_data;
  Dispatcher *dp;

  printf ("asynchronous data arrived\n");

  dp = data;
  fd = ecore_main_fd_handler_fd_get(fdh);

  // reads all events and use only one
  while (read (fd, buf, sizeof (buf)) > 0);

  pthread_mutex_lock (&gps_mutex);
  strncpy (edje_signal_local, edje_signal, 13+3);
  pthread_mutex_unlock (&gps_mutex);
 
  edje_object_signal_emit (o_edje, edje_signal_local, "degree");

  return 1;
}

void dispatcher_signal ()
{
  write(dp.fd_write, "1", 2);
}

void gps_callback (struct gps_data_t *gps_data, char *buf,  size_t len,
int level) {
  struct gps_fix_t *gps_fix;
  double track;
  int track_part;
  char *gps_buf[2];

  gps_fix = &gps_data->fix;
  track = gps_fix->track;

  // test if track != NaN

  track_part = (int) ceil (track); // use round()  

  // TODO: only update if new GPS position and direction!

  // dangerous -> use sprintf and length check later!
  pthread_mutex_lock (&gps_mutex);
  sprintf (edje_signal, "signal_degree%.3d", track_part);
  pthread_mutex_unlock (&gps_mutex);

  printf ("degree: %s\n", edje_signal);
    
  dispatcher_signal ();

  printf ("Track: %f\n", track);
}

void print_help (char *app_name)
{
  printf("Usage: %s <default.edj>\n", app_name);
  exit(-1);
}

void resize_cb(Ecore_Evas *ee)
{
  Evas_Coord x, y, w, h;

  ecore_evas_geometry_get (ee, &x, &y, &w, &h);

  if (w < h)
  {
    evas_object_resize(o_bg, w, w);
    evas_object_resize(o_edje, w, w);
  }
  else
  {
    evas_object_resize(o_bg, h, h);
    evas_object_resize(o_edje, h, h);
  }
}


regards
Andreas

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to