Skip to content

Commit

Permalink
[mms-engine] Added getVersion D-Bus API
Browse files Browse the repository at this point in the history
Allows applications to determine which version of mms-engine is installed.
  • Loading branch information
monich committed Jul 16, 2014
1 parent 374ba41 commit 9eaae2e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
15 changes: 6 additions & 9 deletions mms-engine/main.c
Expand Up @@ -160,7 +160,7 @@ mms_app_parse_options(
gboolean ok;
GError* error = NULL;
gboolean session_bus = FALSE;
#ifdef MMS_ENGINE_VERSION
#ifdef MMS_VERSION_STRING
gboolean print_version = FALSE;
#endif
gboolean log_modules = FALSE;
Expand Down Expand Up @@ -213,7 +213,7 @@ mms_app_parse_options(
"Set log level (repeatable)", "[MODULE:]LEVEL" },
{ "log-modules", 0, 0, G_OPTION_ARG_NONE, &log_modules,
"List available log modules", NULL },
#ifdef MMS_ENGINE_VERSION
#ifdef MMS_VERSION_STRING
{ "version", 0, 0, G_OPTION_ARG_NONE, &print_version,
"Print program version and exit", NULL },
#endif
Expand Down Expand Up @@ -242,18 +242,15 @@ mms_app_parse_options(
}
*result = RET_OK;
return FALSE;
#ifdef MMS_ENGINE_VERSION
# define MMS_STRING__(x) #x
# define MMS_STRING_(x) MMS_STRING__(x)
# define MMS_VERVION_STRING MMS_STRING_(MMS_ENGINE_VERSION)
#ifdef MMS_VERSION_STRING
} else if (print_version) {
printf("MMS engine %s\n", MMS_VERVION_STRING);
printf("MMS engine %s\n", MMS_VERSION_STRING);
*result = RET_OK;
return FALSE;
#endif
} else {
#ifdef MMS_ENGINE_VERSION
MMS_INFO("Version %s starting", MMS_VERVION_STRING);
#ifdef MMS_VERSION_STRING
MMS_INFO("Version %s starting", MMS_VERSION_STRING);
#else
MMS_INFO("Starting");
#endif
Expand Down
31 changes: 31 additions & 0 deletions mms-engine/mms_engine.c
Expand Up @@ -45,6 +45,7 @@ struct mms_engine {
gulong cancel_signal_id;
gulong set_log_level_signal_id;
gulong set_log_type_signal_id;
gulong get_version_signal_id;
};

typedef GObjectClass MMSEngineClass;
Expand Down Expand Up @@ -385,6 +386,32 @@ mms_engine_handle_set_log_type(
return TRUE;
}

/* org.nemomobile.MmsEngine.getVersion */
static
gboolean
mms_engine_handle_get_version(
OrgNemomobileMmsEngine* proxy,
GDBusMethodInvocation* call,
MMSEngine* engine)
{
#ifdef MMS_VERSION_STRING
int v1 = 0, v2 = 0, v3 = 0;
char* s = g_malloc(strlen(MMS_VERSION_STRING)+1);
s[0] = 0;
if (sscanf(MMS_VERSION_STRING, "%d.%d.%d%s", &v1, &v2, &v3, s) < 3) {
MMS_WARN_("unable to parse version %s", MMS_VERSION_STRING);
} else {
MMS_DEBUG_("version %d.%d.%d%s", v1, v2, v3, s);
}
org_nemomobile_mms_engine_complete_get_version(proxy, call, v1, v2, v3, s);
g_free(s);
#else
MMS_DEBUG_("oops");
org_nemomobile_mms_engine_complete_get_version(proxy, call, 0, 0, 0, "");
#endif
return TRUE;
}

MMSEngine*
mms_engine_new(
const MMSConfig* config,
Expand Down Expand Up @@ -459,6 +486,9 @@ mms_engine_new(
mms->set_log_type_signal_id =
g_signal_connect(mms->proxy, "handle-set-log-type",
G_CALLBACK(mms_engine_handle_set_log_type), mms);
mms->get_version_signal_id =
g_signal_connect(mms->proxy, "handle-get-version",
G_CALLBACK(mms_engine_handle_get_version), mms);

return mms;
}
Expand Down Expand Up @@ -580,6 +610,7 @@ mms_engine_dispose(
g_signal_handler_disconnect(e->proxy, e->cancel_signal_id);
g_signal_handler_disconnect(e->proxy, e->set_log_level_signal_id);
g_signal_handler_disconnect(e->proxy, e->set_log_type_signal_id);
g_signal_handler_disconnect(e->proxy, e->get_version_signal_id);
g_object_unref(e->proxy);
e->proxy = NULL;
}
Expand Down
6 changes: 6 additions & 0 deletions mms-engine/mms_engine.h
Expand Up @@ -18,6 +18,12 @@
#include <gio/gio.h>
#include "mms_settings.h"

#ifdef MMS_ENGINE_VERSION
# define MMS_STRING__(x) #x
# define MMS_STRING_(x) MMS_STRING__(x)
# define MMS_VERSION_STRING MMS_STRING_(MMS_ENGINE_VERSION)
#endif

#define MMS_APP_LOG_PREFIX "mms-engine"

#define MMS_ENGINE_SERVICE "org.nemomobile.MmsEngine"
Expand Down
8 changes: 8 additions & 0 deletions mms-engine/org.nemomobile.MmsEngine.xml
Expand Up @@ -198,5 +198,13 @@
<arg type="s" name="type" direction="in"/>
</method>

<!-- Since 1.0.22 -->
<method name="getVersion">
<arg type="i" name="major" direction="out"/>
<arg type="i" name="minor" direction="out"/>
<arg type="i" name="micro" direction="out"/>
<arg type="s" name="suffix" direction="out"/>
</method>

</interface>
</node>

0 comments on commit 9eaae2e

Please sign in to comment.