forked from enlightenment/efl
eeze_scanner: add monitor (client)
In order to test eeze_scanner it's handful to have a client to monitor for broadcasted events.
This commit is contained in:
parent
9effe44d8b
commit
211eb3f00a
|
@ -126,7 +126,8 @@ bin_PROGRAMS += \
|
|||
bin/eeze/eeze_mount \
|
||||
bin/eeze/eeze_umount \
|
||||
bin/eeze/eeze_disk_ls \
|
||||
bin/eeze/eeze_scanner
|
||||
bin/eeze/eeze_scanner \
|
||||
bin/eeze/eeze_scanner_monitor
|
||||
|
||||
bin_eeze_eeze_mount_SOURCES = bin/eeze/eeze_mount.c
|
||||
bin_eeze_eeze_mount_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EEZE_CFLAGS@
|
||||
|
@ -150,6 +151,13 @@ bin_eeze_eeze_scanner_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EEZE_CFLAGS@
|
|||
bin_eeze_eeze_scanner_LDADD = @USE_EEZE_LIBS@
|
||||
bin_eeze_eeze_scanner_DEPENDENCIES = @USE_EEZE_INTERNAL_LIBS@
|
||||
|
||||
bin_eeze_eeze_scanner_monitor_SOURCES = \
|
||||
bin/eeze/eeze_scanner_monitor.c \
|
||||
bin/eeze/eeze_scanner_monitor.h
|
||||
bin_eeze_eeze_scanner_monitor_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EEZE_CFLAGS@
|
||||
bin_eeze_eeze_scanner_monitor_LDADD = @USE_EEZE_LIBS@
|
||||
bin_eeze_eeze_scanner_monitor_DEPENDENCIES = @USE_EEZE_INTERNAL_LIBS@
|
||||
|
||||
setuid_root_mode = a=rx,u+xs
|
||||
|
||||
EFL_INSTALL_EXEC_HOOK+=chmod $(setuid_root_mode) $(DESTDIR)$(bindir)/eeze_scanner$(EXEEXT) || true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/eeze_disk_ls
|
||||
/eeze_mount
|
||||
/eeze_scanner
|
||||
/eeze_scanner_monitor
|
||||
/eeze_sensor_test
|
||||
/eeze_udev_test
|
||||
/eeze_umount
|
||||
|
|
|
@ -0,0 +1,220 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#define EFL_BETA_API_SUPPORT 1
|
||||
#define EFL_EO_API_SUPPORT 1
|
||||
#include <Eet.h>
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Con.h>
|
||||
#include "eeze_scanner.h"
|
||||
|
||||
static Eet_Data_Descriptor *edd;
|
||||
|
||||
static int retval = EXIT_SUCCESS;
|
||||
|
||||
static Eina_Bool
|
||||
_eet_read(const void *eet_data, size_t size, void *user_data EINA_UNUSED)
|
||||
{
|
||||
Eeze_Scanner_Event *ev = eet_data_descriptor_decode(edd, eet_data, size);
|
||||
|
||||
if (!ev)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not decode event!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (ev->type)
|
||||
{
|
||||
case EEZE_SCANNER_EVENT_TYPE_ADD:
|
||||
printf("ADD ");
|
||||
break;
|
||||
case EEZE_SCANNER_EVENT_TYPE_REMOVE:
|
||||
printf("DEL ");
|
||||
break;
|
||||
case EEZE_SCANNER_EVENT_TYPE_CHANGE:
|
||||
printf("CHG ");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "ERROR: unknown event type %d\n", ev->type);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (ev->volume)
|
||||
printf("VOLUME ");
|
||||
|
||||
printf("'%s'\n", ev->device);
|
||||
free(ev);
|
||||
|
||||
return EINA_TRUE;
|
||||
|
||||
error:
|
||||
retval = EXIT_FAILURE;
|
||||
ecore_main_loop_quit();
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eet_write(const void *eet_data EINA_UNUSED, size_t size EINA_UNUSED, void *user_data EINA_UNUSED)
|
||||
{
|
||||
fprintf(stderr, "ERROR: should not write data!\n");
|
||||
retval = EXIT_FAILURE;
|
||||
ecore_main_loop_quit();
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_on_data(void *data, const Efl_Event *event)
|
||||
{
|
||||
Eet_Connection *ec = data;
|
||||
Eo *dialer = event->object;
|
||||
Eina_Slice slice;
|
||||
|
||||
if (!efl_io_buffered_stream_slice_get(dialer, &slice))
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not get buffered stream slice\n");
|
||||
goto error;
|
||||
}
|
||||
if (slice.len == 0) return;
|
||||
|
||||
if (eet_connection_received(ec, slice.mem, slice.len) != 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: received invalid data\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
efl_io_buffered_stream_discard(dialer, slice.len);
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
retval = EXIT_FAILURE;
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_finished(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_error(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
Eo *dialer = event->object;
|
||||
Eina_Error *perr = event->info;
|
||||
|
||||
fprintf(stderr, "ERROR: error communicating to %s: %s\n",
|
||||
efl_net_dialer_address_dial_get(dialer),
|
||||
eina_error_msg_get(*perr));
|
||||
retval = EXIT_FAILURE;
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
|
||||
{
|
||||
Eet_Data_Descriptor_Class eddc;
|
||||
Eo *loop;
|
||||
char *path;
|
||||
Eo *dialer;
|
||||
Eet_Connection *ec;
|
||||
Eina_Error err;
|
||||
|
||||
ecore_app_no_system_modules();
|
||||
|
||||
eina_init();
|
||||
ecore_init();
|
||||
eet_init();
|
||||
ecore_con_init();
|
||||
|
||||
if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "eeze_scanner_event", sizeof(Eeze_Scanner_Event)))
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create eet data descriptor!\n");
|
||||
retval = EXIT_FAILURE;
|
||||
goto error_edd;
|
||||
}
|
||||
edd = eet_data_descriptor_stream_new(&eddc);
|
||||
if (!edd)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create eet data descriptor!\n");
|
||||
retval = EXIT_FAILURE;
|
||||
goto error_edd;
|
||||
}
|
||||
#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eeze_Scanner_Event, #MEMBER, MEMBER, EET_T_##TYPE)
|
||||
DAT(device, INLINED_STRING);
|
||||
DAT(type, UINT);
|
||||
DAT(volume, UCHAR);
|
||||
#undef DAT
|
||||
|
||||
path = ecore_con_local_path_new(EINA_TRUE, "eeze_scanner", 0);
|
||||
if (!path)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not get local communication path\n");
|
||||
retval = EXIT_FAILURE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
loop = ecore_main_loop_get();
|
||||
|
||||
#ifdef EFL_NET_DIALER_UNIX_CLASS
|
||||
dialer = efl_add(EFL_NET_DIALER_SIMPLE_CLASS, loop,
|
||||
efl_net_dialer_simple_inner_class_set(efl_added, EFL_NET_DIALER_UNIX_CLASS));
|
||||
#else
|
||||
fprintf(stderr, "ERROR: your platform doesn't support Efl.Net.Dialer.Unix\n");
|
||||
#endif
|
||||
if (!dialer)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create communication dialer\n");
|
||||
retval = EXIT_FAILURE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
ec = eet_connection_new(_eet_read, _eet_write, dialer);
|
||||
if (!ec)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create Eet_Connection\n");
|
||||
retval = EXIT_FAILURE;
|
||||
goto end;
|
||||
}
|
||||
efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_SLICE_CHANGED, _on_data, ec);
|
||||
|
||||
|
||||
efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_ERROR, _error, NULL);
|
||||
efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_READ_FINISHED, _finished, NULL);
|
||||
|
||||
err = efl_net_dialer_dial(dialer, path);
|
||||
if (err)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not connect '%s': %s\n", path, eina_error_msg_get(err));
|
||||
retval = EXIT_FAILURE;
|
||||
goto end_dial;
|
||||
}
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
end_dial:
|
||||
if (!efl_io_closer_closed_get(dialer))
|
||||
efl_io_closer_close(dialer);
|
||||
|
||||
efl_event_callback_del(dialer, EFL_IO_BUFFERED_STREAM_EVENT_SLICE_CHANGED, _on_data, ec);
|
||||
eet_connection_close(ec, NULL);
|
||||
ec = NULL;
|
||||
|
||||
end:
|
||||
efl_del(dialer);
|
||||
dialer = NULL;
|
||||
|
||||
free(path);
|
||||
path = NULL;
|
||||
|
||||
eet_data_descriptor_free(edd);
|
||||
edd = NULL;
|
||||
|
||||
error_edd:
|
||||
ecore_con_shutdown();
|
||||
eet_shutdown();
|
||||
ecore_shutdown();
|
||||
eina_shutdown();
|
||||
return retval;
|
||||
}
|
Loading…
Reference in New Issue