<commit_before>#include "e.h"

/* local subsystem functions */
#ifdef HAVE_EDBUS
static void _e_msgbus_request_name_cb(void *data, DBusMessage *msg, DBusError *err);

static DBusMessage* _e_msgbus_core_restart_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_core_shutdown_cb(E_DBus_Object *obj, DBusMessage *msg);

static DBusMessage* _e_msgbus_module_load_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_unload_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_enable_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_disable_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_list_cb(E_DBus_Object *obj, DBusMessage *msg);

static DBusMessage* _e_msgbus_profile_set_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_get_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_list_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_add_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_delete_cb(E_DBus_Object *obj, DBusMessage *msg);
#endif

/* local subsystem globals */
static E_Msgbus_Data *_e_msgbus_data = NULL;

/* externally accessible functions */
EAPI int
e_msgbus_init(void)
{
#ifdef HAVE_EDBUS
   E_DBus_Interface *iface;

   _e_msgbus_data = E_NEW(E_Msgbus_Data, 1);

   e_dbus_init();

   _e_msgbus_data->conn = e_dbus_bus_get(DBUS_BUS_SESSION);
   if (!_e_msgbus_data->conn)
     {
	printf("WARNING: Cannot get DBUS_BUS_SESSION\n");
	return 0;
     }
   e_dbus_request_name(_e_msgbus_data->conn, "org.enlighenment.wm.service", 0, _e_msgbus_request_name_cb, NULL);
   _e_msgbus_data->obj = e_dbus_object_add(_e_msgbus_data->conn, "/org/enlightenment/wm/RemoteObject", NULL);

   iface = e_dbus_interface_new("org.enlightenment.wm.Core");
   if (!iface)
     {
	printf("WARNING: Cannot add org.enlightenment.wm.Core interface\n");
	return 0;
     }
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
 
   /* Hardcore methods */
   e_dbus_interface_method_add(iface, "Restart", "", "", _e_msgbus_core_restart_cb);
   e_dbus_interface_method_add(iface, "Shutdown", "", "", _e_msgbus_core_shutdown_cb);
  
   iface = e_dbus_interface_new("org.enlightenment.wm.Module");
   if (!iface)
     {
	printf("WARNING: Cannot add org.enlightenment.wm.Module interface\n");
	return 0;
     }
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);

   /* Module methods */
   e_dbus_interface_method_add(iface, "Load", "s", "", _e_msgbus_module_load_cb);
   e_dbus_interface_method_add(iface, "Unload", "s", "", _e_msgbus_module_unload_cb);
   e_dbus_interface_method_add(iface, "Enable", "s", "", _e_msgbus_module_enable_cb);
   e_dbus_interface_method_add(iface, "Disable", "s", "", _e_msgbus_module_disable_cb);
   e_dbus_interface_method_add(iface, "List", "", "a(si)", _e_msgbus_module_list_cb);

   iface = e_dbus_interface_new("org.enlightenment.wm.Profile");
   if (!iface)
     {
	printf("WARNING: Cannot add org.enlightenment.wm.Profile interface\n");
	return 0;
     }
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);

   /* Profile methods */
   e_dbus_interface_method_add(iface, "Set", "s", "", _e_msgbus_profile_set_cb);
   e_dbus_interface_method_add(iface, "Get", "", "s", _e_msgbus_profile_get_cb);
   e_dbus_interface_method_add(iface, "List", "", "as", _e_msgbus_profile_list_cb);
   e_dbus_interface_method_add(iface, "Add", "s", "", _e_msgbus_profile_add_cb);
   e_dbus_interface_method_add(iface, "Delete", "s", "", _e_msgbus_profile_delete_cb);


#endif   
   return 1;
}

EAPI int
e_msgbus_shutdown(void)
{
#ifdef HAVE_EDBUS
   if (_e_msgbus_data->obj)
     {
        e_dbus_object_free(_e_msgbus_data->obj);
     }
   if (_e_msgbus_data->conn)
     {
        e_dbus_connection_close(_e_msgbus_data->conn);
     }
   e_dbus_shutdown();

   E_FREE(_e_msgbus_data);
   _e_msgbus_data = NULL;
#endif
   return 1;
}

EAPI void
e_msgbus_interface_attach(E_DBus_Interface *iface)
{
#ifdef HAVE_EDBUS
   if (!_e_msgbus_data->obj) return;
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
#endif
}

EAPI void
e_msgbus_interface_detach(E_DBus_Interface *iface)
{
#ifdef HAVE_EDBUS
   if (!_e_msgbus_data->obj) return;
   e_dbus_object_interface_detach(_e_msgbus_data->obj, iface);
#endif
}

#ifdef HAVE_EDBUS
static void
_e_msgbus_request_name_cb(void *data, DBusMessage *msg, DBusError *err)
{
//TODO Handle Errors
}

/* Core Handlers */
static DBusMessage* 
_e_msgbus_core_restart_cb(E_DBus_Object *obj, DBusMessage *msg)
{
   restart = 1;
   ecore_main_loop_quit();

    return dbus_message_new_method_return(msg);
}

static DBusMessage* 
_e_msgbus_core_shutdown_cb(E_DBus_Object *obj, DBusMessage *msg)
{
   if (!e_util_immortal_check()) ecore_main_loop_quit();
 
   return dbus_message_new_method_return(msg);
}

/* Modules Handlers */
static DBusMessage* 
_e_msgbus_module_load_cb(E_DBus_Object *obj, DBusMessage *msg)
{
   DBusMessageIter iter;
   char *module;
   
   dbus_message_iter_init(msg, &iter);
   dbus_message_iter_get_basic(&iter, &module);
   
   if (!e_module_find(module)) 
     {
	e_module_new(module);
	e_config_save_queue();
     }

   return dbus_message_new_method_return(msg);
}
<commit_msg>formatting<commit_after>#include "e.h"

/* local subsystem functions */
#ifdef HAVE_EDBUS
static void _e_msgbus_request_name_cb(void *data, DBusMessage *msg, DBusError *err);

static DBusMessage* _e_msgbus_core_restart_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_core_shutdown_cb(E_DBus_Object *obj, DBusMessage *msg);

static DBusMessage* _e_msgbus_module_load_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_unload_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_enable_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_disable_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_module_list_cb(E_DBus_Object *obj, DBusMessage *msg);

static DBusMessage* _e_msgbus_profile_set_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_get_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_list_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_add_cb(E_DBus_Object *obj, DBusMessage *msg);
static DBusMessage* _e_msgbus_profile_delete_cb(E_DBus_Object *obj, DBusMessage *msg);
#endif

/* local subsystem globals */
static E_Msgbus_Data *_e_msgbus_data = NULL;

/* externally accessible functions */
EAPI int
e_msgbus_init(void)
{
#ifdef HAVE_EDBUS
   E_DBus_Interface *iface;

   _e_msgbus_data = E_NEW(E_Msgbus_Data, 1);

   e_dbus_init();

   _e_msgbus_data->conn = e_dbus_bus_get(DBUS_BUS_SESSION);
   if (!_e_msgbus_data->conn)
     {
	printf("WARNING: Cannot get DBUS_BUS_SESSION\n");
	return 0;
     }
   e_dbus_request_name(_e_msgbus_data->conn, "org.enlighenment.wm.service", 0, _e_msgbus_request_name_cb, NULL);
   _e_msgbus_data->obj = e_dbus_object_add(_e_msgbus_data->conn, "/org/enlightenment/wm/RemoteObject", NULL);

   iface = e_dbus_interface_new("org.enlightenment.wm.Core");
   if (!iface)
     {
	printf("WARNING: Cannot add org.enlightenment.wm.Core interface\n");
	return 0;
     }
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
 
   /* Hardcore methods */
   e_dbus_interface_method_add(iface, "Restart", "", "", _e_msgbus_core_restart_cb);
   e_dbus_interface_method_add(iface, "Shutdown", "", "", _e_msgbus_core_shutdown_cb);
  
   iface = e_dbus_interface_new("org.enlightenment.wm.Module");
   if (!iface)
     {
	printf("WARNING: Cannot add org.enlightenment.wm.Module interface\n");
	return 0;
     }
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);

   /* Module methods */
   e_dbus_interface_method_add(iface, "Load", "s", "", _e_msgbus_module_load_cb);
   e_dbus_interface_method_add(iface, "Unload", "s", "", _e_msgbus_module_unload_cb);
   e_dbus_interface_method_add(iface, "Enable", "s", "", _e_msgbus_module_enable_cb);
   e_dbus_interface_method_add(iface, "Disable", "s", "", _e_msgbus_module_disable_cb);
   e_dbus_interface_method_add(iface, "List", "", "a(si)", _e_msgbus_module_list_cb);

   iface = e_dbus_interface_new("org.enlightenment.wm.Profile");
   if (!iface)
     {
	printf("WARNING: Cannot add org.enlightenment.wm.Profile interface\n");
	return 0;
     }
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);

   /* Profile methods */
   e_dbus_interface_method_add(iface, "Set", "s", "", _e_msgbus_profile_set_cb);
   e_dbus_interface_method_add(iface, "Get", "", "s", _e_msgbus_profile_get_cb);
   e_dbus_interface_method_add(iface, "List", "", "as", _e_msgbus_profile_list_cb);
   e_dbus_interface_method_add(iface, "Add", "s", "", _e_msgbus_profile_add_cb);
   e_dbus_interface_method_add(iface, "Delete", "s", "", _e_msgbus_profile_delete_cb);


#endif   
   return 1;
}

EAPI int
e_msgbus_shutdown(void)
{
#ifdef HAVE_EDBUS
   if (_e_msgbus_data->obj)
     {
        e_dbus_object_free(_e_msgbus_data->obj);
     }
   if (_e_msgbus_data->conn)
     {
        e_dbus_connection_close(_e_msgbus_data->conn);
     }
   e_dbus_shutdown();

   E_FREE(_e_msgbus_data);
   _e_msgbus_data = NULL;
#endif
   return 1;
}

EAPI void
e_msgbus_interface_attach(E_DBus_Interface *iface)
{
#ifdef HAVE_EDBUS
   if (!_e_msgbus_data->obj) return;
   e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
#endif
}

EAPI void
e_msgbus_interface_detach(E_DBus_Interface *iface)
{
#ifdef HAVE_EDBUS
   if (!_e_msgbus_data->obj) return;
   e_dbus_object_interface_detach(_e_msgbus_data->obj, iface);
#endif
}

#ifdef HAVE_EDBUS
static void
_e_msgbus_request_name_cb(void *data, DBusMessage *msg, DBusError *err)
{
//TODO Handle Errors
}

/* Core Handlers */
static DBusMessage* 
_e_msgbus_core_restart_cb(E_DBus_Object *obj, DBusMessage *msg)
{
   restart = 1;
   ecore_main_loop_quit();

   return dbus_message_new_method_return(msg);
}

static DBusMessage* 
_e_msgbus_core_shutdown_cb(E_DBus_Object *obj, DBusMessage *msg)
{
   if (!e_util_immortal_check()) ecore_main_loop_quit();
 
   return dbus_message_new_method_return(msg);
}

/* Modules Handlers */
static DBusMessage* 
_e_msgbus_module_load_cb(E_DBus_Object *obj, DBusMessage *msg)
{
   DBusMessageIter iter;
   char *module;
   
   dbus_message_iter_init(msg, &iter);
   dbus_message_iter_get_basic(&iter, &module);
   
   if (!e_module_find(module)) 
     {
	e_module_new(module);
	e_config_save_queue();
     }

   return dbus_message_new_method_return(msg);
}

{'fraction_non_alphanumeric': 0.11527647610121837, 'fraction_numerical': 0.0016869728209934396, 'mean_word_length': 6.029644268774703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1830829', 'n_tokens_mistral': 4296, 'n_tokens_neox': 4233, 'n_words': 654}