[--enable-examples example applications],
[enable_examples=$enable_examples], [enable_examples=no])
AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$enable_examples" = "xyes"])
+if test "x$enable_examples" = "xyes"; then
+ AC_PROG_CXX
+fi
# Checks for header files.
AC_CHECK_HEADERS([string.h])
-bin_PROGRAMS = msgport-example-app
+bin_PROGRAMS = msgport-example-app msgport-example-app-cpp
msgport_example_app_SOURCES = test-app.c
-
msgport_example_app_LDADD = ../lib/libmessage-port.la $(GLIB_LIBS) $(BUNDLE_LIBS)
-
msgport_example_app_CPPFLAGS = -I../lib/ -I ../ $(GLIB_CFLAGS) $(BUNDLE_CFLAGS)
+msgport_example_app_cpp_SOURCES = test-app.cpp
+msgport_example_app_cpp_LDADD = ../lib/libmessage-port.la $(GLIB_LIBS) $(BUNDLE_LIBS)
+msgport_example_app_cpp_CXXFLAGS = -I../lib/ -I ../ $(GLIB_CFLAGS) $(BUNDLE_CFLAGS)
+
{
gchar *name = NULL;
messageport_get_local_port_name (port_id, &name),
- DBG ("CHILD: GOT MESSAGE at prot %s FROM :'%s' - '%s", name,
+ DBG ("CHILD: GOT MESSAGE at prot '%s' FROM :'%s' - '%s", name,
remote_app_id ? remote_app_id : "unknwon app", remote_port ? remote_port : "unknwon");
g_free (name);
g_assert (data);
messageport_error_e res = trusted_message ? messageport_check_trusted_remote_port (remote_app_id, remote_port, &found)
: messageport_check_remote_port (remote_app_id, remote_port, &found);
if (!found) {
- DBG ("PARENT: Could not found remote port (%d)", res);
+ WARN ("PARENT: Could not found remote port (%d)", res);
exit (-1);
}
bundle_add (reply, "Results", "GOT_IT");
DBG ("PARENT: Sending reply ....");
- res = messageport_send_message (remote_app_id, remote_port, reply);
+ res = trusted_message ? messageport_send_trusted_message (remote_app_id, remote_port, reply)
+ : messageport_send_message (remote_app_id, remote_port, reply);
bundle_free (reply);
if (res != MESSAGEPORT_ERROR_NONE)
{
- DBG ("PARENT: Faile to send message to server : %d", res);
+ WARN ("PARENT: Faile to send message to server : %d", res);
}
else DBG ("PARENT: Data sent successfully");
+ g_main_loop_quit (__loop);
}
g_free (name);
}
else {
- DBG ("Failed to register port : %d", port_id);
+ WARN ("Failed to register port : %d", port_id);
}
return port_id;
}
child_pid = fork ();
if (child_pid < 0) {
- g_error ("Failed to fork ");
+ ERR ("Failed to fork ");
}
else if (child_pid > 0) {
/* prent process : server port */
int port_id = _register_test_port ("test_parent_port", _on_parent_got_message);
- DBG ("PARENT ; registered port %d", port_id);
-
+ if (port_id < 0) {
+ WARN ("PARENT: Exiting...");
+ exit (-1);
+ }
+ else {
+ DBG ("PARENT ; registered port %d", port_id);
+ }
}
else {
/* child process */
int port_id = _register_test_port ("test_child_port", _on_child_got_message);
- DBG ("CHILD ; registered port %d", port_id);
+ if (port_id < 0) {
+ WARN ("CHILD: Exiting...");
+ exit (-1);
+ }
+ else DBG ("CHILD ; registered port %d", port_id);
+
+ DBG("CHILD: Waiting for sometime to get server port ready....");
/* sleep sometime till server port is ready */
- sleep (5);
+ sleep (3);
+
gchar *parent_app_id = g_strdup_printf ("%d", getppid());
gboolean found;
messageport_error_e res = messageport_check_trusted_remote_port (parent_app_id, "test_parent_port", &found);
if (!found) {
- DBG ("CHILD : Could not found remote port (%d)", res);
- return -1;
+ WARN ("CHILD : Could not found remote port (%d)", res);
+ exit(-1);
}
DBG ("CHILD : Found remote prot..., sending data to remote port (%s:%s)", parent_app_id, "test_parent_port");
bundle_free (b);
if (res != MESSAGEPORT_ERROR_NONE)
{
- DBG ("CHILD: Fail to send message to server : %d", res);
+ WARN ("CHILD: Fail to send message to server : %d", res);
+ exit (-1);
}
else DBG ("CHILD : Data sent successfully");
}
g_main_loop_unref (__loop);
+ DBG ("TEST RSULT : SUCCESS");
+
return 0;
}
--- /dev/null
+#include <message-port.h>
+#include <bundle.h>
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+class LocalPort {
+protected:
+ static void OnMessage (int id, const char *r_app, const char *r_port, bool r_is_trusted, bundle *data)
+ {
+ cout << "Message received" << endl;
+ }
+
+public:
+ LocalPort (const std::string &name, bool is_trusted)
+ : m_name (name), m_trusted(is_trusted) { }
+
+ bool Register () {
+ int res ;
+ res = m_trusted ? messageport_register_trusted_local_port (m_name.c_str(), OnMessage)
+ : messageport_register_local_port (m_name.c_str(), OnMessage);
+
+ if (res < 0) {
+ cerr << "Failed to register port '"<< m_name << "'";
+ return false;
+ }
+
+ return true;
+ }
+
+ bool SendMessage (const std::string &app_id, const std::string &port_name, bool is_trusted, bundle *data)
+ {
+ messageport_error_e res ;
+
+ res = is_trusted ? messageport_send_bidirectional_trusted_message (m_port_id, app_id.c_str(), port_name.c_str(), data)
+ : messageport_send_bidirectional_message (m_port_id, app_id.c_str(), port_name.c_str(), data);
+ if (res < 0) {
+ cerr << "Fail to send bidirectional message to '" << app_id << "/" << port_name << ":" << res ;
+ return false;
+ }
+
+ return true;
+ }
+
+private:
+ std::string m_name;
+ bool m_trusted;
+ int m_port_id;
+};
+
+int main (int argc, const char *argv[])
+{
+ GMainLoop *m_loop = g_main_loop_new (NULL, FALSE);
+
+ LocalPort port1 ("test_port1", false);
+
+ port1.Register ();
+
+ g_main_loop_run (m_loop);
+
+ g_main_loop_unref (m_loop);
+
+ return 0;
+}
+
#include <bundle.h>
#include <glib.h>
+#ifndef __cplusplus
+typedef gboolean bool;
+#endif
+
G_BEGIN_DECLS
/**
* @remarks @a data must be released with bundle_free() by you
* @remark @a remote_app_id and @a remote_port will be set if the remote application sends a bidirectional message, otherwise they are NULL.
*/
-typedef void (*messageport_message_cb)(int id, const char* remote_app_id, const char* remote_port, gboolean trusted_message, bundle* data);
+typedef void (*messageport_message_cb)(int id, const char* remote_app_id, const char* remote_port, bool trusted_message, bundle* data);
/**
* @brief Registers the local message port. @n
* @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
*/
EXPORT_API messageport_error_e
-messageport_check_remote_port(const char* remote_app_id, const char *remote_port, gboolean *exist);
+messageport_check_remote_port(const char* remote_app_id, const char *remote_port, bool *exist);
/**
* @brief Checks if the trusted message port of a remote application is registered.
* @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
*/
EXPORT_API messageport_error_e
-messageport_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, gboolean *exist);
+messageport_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, bool *exist);
/**
* @brief Sends a message to the message port of a remote application.
* @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
*/
EXPORT_API messageport_error_e
-messageport_check_trusted_local_port(int id, gboolean *is_trusted);
+messageport_check_trusted_local_port(int id, bool *is_trusted);
G_END_DECLS
%defattr(-,root,root,-)
%if %{build_examples} == 1
%{_bindir}/msgport-example-app
+%{_bindir}/msgport-example-app-cpp
%endif
%{_libdir}/pkgconfig/%{name}.pc
%{_includedir}/*.h