packaging: examples packaged under message-port-examples.
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Wed, 30 Oct 2013 11:37:47 +0000 (13:37 +0200)
committerAmarnath Valluri <amarnath.valluri@linux.intel.com>
Wed, 20 Aug 2014 06:45:09 +0000 (09:45 +0300)
Few debug issues fixed in example code.

examples/Makefile.am
examples/test-app.c
examples/test-app.cpp
packaging/message-port.spec

index cc39af4..e937d78 100644 (file)
@@ -1,3 +1,4 @@
+if BUILD_EXAMPLES
 bin_PROGRAMS = msgport-example-app msgport-example-app-cpp
 
 msgport_example_app_SOURCES = test-app.c 
@@ -7,4 +8,4 @@ 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) $(DLOG_LIBS)
 msgport_example_app_cpp_CXXFLAGS  = -I../lib/ -I ../ $(GLIB_CFLAGS) $(BUNDLE_CFLAGS) $(DLOG_CFLAGS)
-
+endif
index 392e623..2dcef13 100644 (file)
@@ -26,7 +26,6 @@
 #include <stdlib.h>
 #include <message-port.h>
 #include <bundle.h>
-#include "common/log.h"
 
 GMainLoop *__loop = NULL;
 
@@ -35,14 +34,14 @@ static void _dump_data (const char *key, const int type, const bundle_keyval_t *
     gchar *val = NULL;
     size_t size;
     bundle_keyval_get_basic_val ((bundle_keyval_t*)kv, (void**)&val, &size);
-    DBG ("       %s - %s", key, val);
+    g_message ("       %s - %s", key, val);
 }
 
 void (_on_child_got_message)(int port_id, const char* remote_app_id, const char* remote_port, gboolean trusted_message, bundle* data)
 {
     gchar *name = NULL;
     messageport_get_local_port_name (port_id, &name),
-    DBG ("CHILD: GOT MESSAGE at prot '%s' FROM :'%s' - '%s", name,
+    g_message ("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);
@@ -57,7 +56,7 @@ void (_on_parent_got_message)(int port_id, const char* remote_app_id, const char
     gboolean found = FALSE;
     bundle *b = NULL;
     messageport_get_local_port_name (port_id, &name),
-    DBG ("PARENT: GOT MESSAGE at prot %s FROM :'%s' - '%s", name,
+    g_message ("PARENT: 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);
 
@@ -68,25 +67,25 @@ void (_on_parent_got_message)(int port_id, const char* remote_app_id, const char
     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) {
-        WARN ("PARENT: Could not found remote port (%d)", res);
+        g_warning ("PARENT: Could not found remote port (%d)", res);
         exit (-1);
     }
 
-    DBG ("PARENT: Found remote prot");
+    g_message ("PARENT: Found remote prot");
 
     bundle *reply = bundle_create ();
 
     bundle_add (reply, "Results", "GOT_IT");
 
-    DBG ("PARENT: Sending reply ....");
+    g_message ("PARENT: Sending 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)
     {
-        WARN ("PARENT: Faile to send message to server : %d", res);
+        g_warning ("PARENT: Faile to send message to server : %d", res);
     }
-    else DBG ("PARENT: Data sent successfully");
+    else g_message ("PARENT: Data sent successfully");
     g_main_loop_quit (__loop);
 
 }
@@ -101,7 +100,7 @@ int _register_test_port (const gchar *port_name, messageport_message_cb cb)
         g_free (name);
     }
     else {
-        WARN ("Failed to register port : %d", port_id);
+        g_warning ("Failed to register port : %d", port_id);
     }
     return port_id;
 }
@@ -114,29 +113,29 @@ int main (int argc, char *argv[])
     child_pid = fork ();
     
     if (child_pid < 0) {
-        ERR ("Failed to fork ");
+        g_error ("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);
        if (port_id < 0) {
-           WARN ("PARENT: Exiting...");
+           g_warning ("PARENT: Exiting...");
            exit (-1);
        }
        else {
-           DBG ("PARENT ; registered port %d", port_id);
+           g_message ("PARENT ; registered port %d", port_id);
        }
     }
     else {
         /* child process */
         int port_id = _register_test_port ("test_child_port", _on_child_got_message);
         if (port_id < 0) {
-           WARN ("CHILD: Exiting...");
+           g_warning ("CHILD: Exiting...");
            exit (-1);
         }
-        else DBG ("CHILD ; registered port %d", port_id);
+        else g_message ("CHILD ; registered port %d", port_id);
 
-        DBG("CHILD: Waiting for sometime to get server port ready....");
+        g_message("CHILD: Waiting for sometime to get server port ready....");
         /* sleep sometime till server port is ready */
         sleep (3);
 
@@ -145,11 +144,11 @@ int main (int argc, char *argv[])
         messageport_error_e res = messageport_check_trusted_remote_port (parent_app_id, "test_parent_port", &found);
 
         if (!found) {
-            WARN ("CHILD : Could not found remote port (%d)", res);
+            g_warning ("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");
+        g_message ("CHILD : Found remote prot..., sending data to remote port (%s:%s)", parent_app_id, "test_parent_port");
 
         bundle *b = bundle_create ();
         bundle_add (b, "Name", "Amarnath");
@@ -159,17 +158,17 @@ int main (int argc, char *argv[])
         bundle_free (b);
         if (res != MESSAGEPORT_ERROR_NONE)
         {
-            WARN ("CHILD: Fail to send message to server : %d", res);
+            g_warning ("CHILD: Fail to send message to server : %d", res);
             exit (-1);
         }
-        else DBG ("CHILD : Data sent successfully");
+        else g_message ("CHILD : Data sent successfully");
     }
 
     g_main_loop_run (__loop);
 
     g_main_loop_unref (__loop);
 
-    DBG ("TEST RSULT : SUCCESS");
+    g_message ("TEST RSULT : SUCCESS");
 
     return 0;
 }
index e0de72d..f8c9451 100644 (file)
@@ -66,6 +66,18 @@ public:
         return true;
     }
 
+    const std::string& name () {
+        return m_name;
+    }
+
+    bool isTrusted () {
+        return m_trusted;
+    }
+
+    int id () {
+        return m_port_id;
+    }
+
 private:
     std::string m_name;
     bool        m_trusted;
@@ -78,7 +90,10 @@ int main (int argc, const char *argv[])
 
     LocalPort port1 ("test_port1", false);
 
-    port1.Register ();
+    if (port1.Register () != true) {
+        cerr << "Failed to register local message port";
+    }
+    else cout << "Registered local message port : " << port1.name() << ", Id: "<< port1.id();
 
     g_main_loop_run (m_loop);
 
index 44741c7..1a96bea 100644 (file)
@@ -42,6 +42,18 @@ Requires:   lib%{name} = %{version}-%{release}
 %description -n lib%{name}-devel
 Development files for message-port client library.
 
+%if %{build_examples} == 1
+
+%package -n %{name}-examples
+Summary: Sample code examples for messageport
+Group: Development/Libraries
+Requires: lib%{name} = %{version}-%{release}
+
+%description -n %{name}-examples
+Example applications using message port.
+
+%endif
+
 
 %prep
 %setup -q -n %{name}-%{version}
@@ -85,10 +97,11 @@ make %{?_smp_mflags}
 #libmessage-port-devel
 %files -n lib%{name}-devel
 %defattr(-,root,root,-)
+%{_libdir}/pkgconfig/%{name}.pc
+%{_includedir}/*.h
+
 %if %{build_examples} == 1
+%files -n %{name}-examples
 %{_bindir}/msgport-example-app
 %{_bindir}/msgport-example-app-cpp
 %endif
-%{_libdir}/pkgconfig/%{name}.pc
-%{_includedir}/*.h
-