Eina_Bool
_command_del(void *data,
             int type EINA_UNUSED,
             void *event)
{
   Command_Service *cs = data;
   Ecore_Exe_Event_Del *d = event;

   if (cs != ecore_exe_data_get(d->exe)) return EINA_TRUE;
   DBG("cs[%p] d[%p] gotham[%p] shotgun[%p]",
       cs, d, cs->services->gotham, cs->services->gotham->shotgun);

   DBG("Sending answer :\n%s", eina_strbuf_string_get(cs->buf));

   DBG("cs->jid[%s] cs->services->gotham->alfred->jid[%s]",
       cs->jid, cs->services->gotham->alfred->jid);

   if (strncmp(cs->jid, cs->services->gotham->alfred->jid, strlen(cs->services->gotham->alfred->jid)))
     shotgun_message_send(cs->services->gotham->shotgun,
                          cs->jid, eina_strbuf_string_get(cs->buf),
                          SHOTGUN_MESSAGE_STATUS_ACTIVE, EINA_TRUE);
   else
     module_json_answer(".service", "", EINA_TRUE, eina_strbuf_string_get(cs->buf),
                        cs->services->gotham, cs->jid);

   _command_service_free(cs);
   return EINA_TRUE;
}
Eina_Bool
_command_data(void *data,
              int type EINA_UNUSED,
              void *event)
{
   Command_Service *cs = data;
   Ecore_Exe_Event_Data *d = (Ecore_Exe_Event_Data *)event;

   if (cs != ecore_exe_data_get(d->exe)) return EINA_TRUE;
   DBG("cs[%p]", cs);

   eina_strbuf_append_length(cs->buf, d->data, d->size);
   return EINA_TRUE;
}
void AudioModel::executableDone(Ecore_Exe_Event_Del *event)
{
    if (!event) return;
    PlayerInfoData *data = reinterpret_cast<PlayerInfoData *>(ecore_exe_data_get(event->exe));
    if (!data) return;
    if (data->thumb_exe != event->exe) return;

    PlayerInfo_signal sig;
    sig.connect(data->callback);
    Params p;
    p.Add("filename", data->cover_fname);
    sig.emit(p);

    delete data;
}
Eina_Bool
_command_error(void *data,
               int type EINA_UNUSED,
               void *event)
{
   Command_Service *cs = data;
   Ecore_Exe_Event_Del *d = event;

   if (cs != ecore_exe_data_get(d->exe)) return EINA_TRUE;

   DBG("cs[%p] d[%p]", cs, d);
   ERR("Execution error");

   _command_service_free(cs);
   return EINA_TRUE;
}
Beispiel #5
0
Eina_Bool
_alert_command_error(void *data,
                     int type EINA_UNUSED,
                     void *event)
{
   Module_Alert_Command *mac = data;
   Ecore_Exe_Event_Del *del = event;

   if (mac != ecore_exe_data_get(del->exe)) return EINA_TRUE;

   DBG("mac[%p] del[%p]", mac, del);

   ERR("Execution error");

   _alert_command_clean(mac);
   return EINA_TRUE;
}
Beispiel #6
0
/**
 * Handle exiting exe.
 *
 * It is called when the exe's exit.
 * The exe itself is free'd after this returns.
 *
 * @param   data the pointer you passed to ecore_event_handler_add().
 * @param   type the type you passed to ecore_event_handler_add().
 * @param   ev a pointer to the relevant event structure.
 * @return  1 to continue processing this event, 0 to not process this event any further.
 * @ingroup Emu_Module_Exe_Group
 */
static int
_emu_cb_exe_del(void *data, int type, void *ev)
{
   Ecore_Exe_Event_Del *event;
   Emu_Face *emu_face;

   emu_face = data;
   event = ev;
   if ((emu_face->exe == event->exe) && (ecore_exe_data_get(event->exe) == emu_face))
     {  /* This is the event we are interested in. */
        emu_face->exe = NULL;

        printf("EMU CLIENT DEL - \n");
        return 0;
     }

   return 1;
}
Beispiel #7
0
Eina_Bool
_alert_command_data(void *data,
                    int type EINA_UNUSED,
                    void *event)
{
   Module_Alert_Command *mac = data;
   Ecore_Exe_Event_Data *d = (Ecore_Exe_Event_Data *)event;
   char *p;

   if (mac != ecore_exe_data_get(d->exe)) return EINA_TRUE;

   DBG("mac[%p] d[%p]", mac, d);

   p = d->data + d->size - 1;
   eina_strbuf_append_length(mac->buf, d->data, *p == '\n' ? d->size-1 : d->size);

   return EINA_TRUE;
}
Beispiel #8
0
Eina_Bool
_alert_command_del(void *data,
                   int type EINA_UNUSED,
                   void *event)
{
   Module_Alert_Command *mac = data;
   Ecore_Exe_Event_Del *del = event;
   const char *val;

   if (mac != ecore_exe_data_get(del->exe)) return EINA_TRUE;

   DBG("mac[%p] del[%p]", mac, del);

   val = gotham_citizen_var_get(mac->gotham->me, mac->command->name);
   DBG("val[%s] value[%s]", val, eina_strbuf_string_get(mac->buf));

   if (!val) goto set_var;

   if (strcmp(val, eina_strbuf_string_get(mac->buf)))
     {
        Eina_Strbuf *buf = eina_strbuf_new();
        EINA_SAFETY_ON_NULL_GOTO(buf, clean_mac);

        eina_strbuf_append_printf(buf, ".notification send %s Variable '%s' changed from '%s' to '%s'",
                                  strlen(mac->command->notification) ? mac->command->notification : "dev",
                                  mac->command->name, val,
                                  eina_strbuf_string_get(mac->buf));
        gotham_citizen_send(mac->gotham->alfred, eina_strbuf_string_get(buf));
        eina_strbuf_free(buf);
     }

set_var:
   gotham_citizen_var_set(mac->gotham->me, mac->command->name, eina_strbuf_string_get(mac->buf));

clean_mac:
   _alert_command_clean(mac);
   return EINA_TRUE;
}
Beispiel #9
0
/**
 * Process received data.
 *
 * It is called when there is data from exe's.
 *
 * @param   data the pointer you passed to ecore_event_handler_add().
 * @param   type the type you passed to ecore_event_handler_add().
 * @param   ev a pointer to the relevant event structure.
 * @return  1 to continue processing this event, 0 to not process this event any further.
 * @ingroup Emu_Module_Exe_Group
 */
static int
_emu_cb_exe_data(void *data, int type, void *ev)
{
   Ecore_Exe_Event_Data *event;
   Emu_Face *emu_face;

   event = ev;
   emu_face = data;
   if ((emu_face->exe == event->exe) && (ecore_exe_data_get(event->exe) == emu_face))
     {                          /* This is the event we are interested in. */
        char *data;

        /* Copy new data to the end of the old data. */
        emu_face->data = realloc(emu_face->data, emu_face->size + event->size);
        data = emu_face->data;
        memcpy(&data[emu_face->size], event->data, event->size);
        emu_face->size += event->size;

        if (event->lines)
          {
             int old_size = 0;
             int new_size;

             /* Find out how many lines there are and make room for the new lines. */
             if (emu_face->lines)
                for (old_size = 0; emu_face->lines[old_size].line != NULL; old_size++)
                   ;
             for (new_size = 0; event->lines[new_size].line != NULL; new_size++)
                ;
             emu_face->lines = realloc(emu_face->lines, (old_size + new_size + 1) * sizeof(Ecore_Exe_Event_Data_Line));
             if (emu_face->lines)
               {
                  int i;
                  int looking = TRUE;
                  char *name = NULL;

                  /* Copy the new sizes to the end. */
                  for (i = 0; event->lines[i].line != NULL; i++)
                    {
                       emu_face->lines[old_size].size = event->lines[i].size;
                       emu_face->lines[old_size].line = NULL;
                       old_size++;
                    }
                  old_size = 0;
                  new_size = 0;
                  /* Scan through all the lines. */
                  for (i = 0; new_size < emu_face->size; i++)
                    {
                       int j;

                       /* Create new line pointer. */
                       emu_face->lines[i].line = &data[new_size];
                       new_size += emu_face->lines[i].size + 1;
                       /* Look for commands. */
                       if (looking)
                         {
                            for (j = 0; _commands[j][0] != '\0'; j++)
                              {
                                 if (strncasecmp(emu_face->lines[i].line, _commands[j], strlen(_commands[j])) == 0)
                                   {    /* Found the beginning of a command. */
                                      char *s;

                                      s = &(emu_face->lines[i].line[strlen(_commands[j])]);
                                      if ((s[0] == '\0') || isspace(s[0]))
                                        {       /* Double check that it wasn't part of a word. */
                                           if (isspace(s[0]))
                                              name = &s[1];
                                           old_size = i;
                                           looking = FALSE;
                                           break;
                                        }
                                   }
                              }
                         }
                       else
                         {
                            if (strcasecmp(emu_face->lines[i].line, "end") == 0)
                              { /* Found a command. */
                                 if ((i - old_size) > 1)        /* Ignore this if there is no data. */
                                    _emu_parse_command(emu_face, j / 2, name, old_size + 1, i - 1);
                                 looking = TRUE;
                                 name = NULL;
                                 old_size = i;
                              }
                         }
                    }

                  if (old_size) /* FIXME: A circular buffer might be a better choice. */
                    {           /* Valid emu commands were found and processed, remove them. */
                       old_size++;
                       new_size = 0;
                       /* Remave old data. */
                       for (i = 0; i < old_size; i++)
                          new_size += emu_face->lines[i].size + 1;
                       memmove(emu_face->data, &data[new_size], emu_face->size - new_size);
                       emu_face->size -= new_size;
                       /* Adjust lines accordingly. */
                       new_size = 0;
                       for (i = old_size; new_size < emu_face->size; i++)
                         {
                            emu_face->lines[i - old_size].line = &data[new_size];
                            emu_face->lines[i - old_size].size = emu_face->lines[i].size;
                            new_size += emu_face->lines[i].size + 1;
                         }
                       emu_face->lines[i - old_size].line = NULL;
                    }
               }
          }
        else
          {
             /* This is just for testing purposes, and should never happen. */
             data = event->data;
             data[event->size - 1] = '\0';
             printf("EMU CLIENT DATA - %s\n", data);
          }

        return 0;
     }

   return 1;
}