1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * Copyright (C) 2013 Intel Corporation.
6 * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <message-port.h>
33 static void OnMessage (int id, const char *r_app, const char *r_port, bool r_is_trusted, bundle *data)
35 cout << "Message received" << endl;
39 LocalPort (const std::string &name, bool is_trusted)
40 : m_name (name), m_trusted(is_trusted) { }
44 res = m_trusted ? messageport_register_trusted_local_port (m_name.c_str(), OnMessage)
45 : messageport_register_local_port (m_name.c_str(), OnMessage);
48 cerr << "Failed to register port '"<< m_name << "'";
55 bool SendMessage (const std::string &app_id, const std::string &port_name, bool is_trusted, bundle *data)
57 messageport_error_e res ;
59 res = is_trusted ? messageport_send_bidirectional_trusted_message (m_port_id, app_id.c_str(), port_name.c_str(), data)
60 : messageport_send_bidirectional_message (m_port_id, app_id.c_str(), port_name.c_str(), data);
62 cerr << "Fail to send bidirectional message to '" << app_id << "/" << port_name << ":" << res ;
69 const std::string& name () {
87 int main (int argc, const char *argv[])
89 GMainLoop *m_loop = g_main_loop_new (NULL, FALSE);
91 LocalPort port1 ("test_port1", false);
93 if (port1.Register () != true) {
94 cerr << "Failed to register local message port";
96 else cout << "Registered local message port : " << port1.name() << ", Id: "<< port1.id();
98 g_main_loop_run (m_loop);
100 g_main_loop_unref (m_loop);