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