daemon initial implementation
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Wed, 9 Oct 2013 11:07:43 +0000 (14:07 +0300)
committerAmarnath Valluri <amarnath.valluri@linux.intel.com>
Wed, 9 Oct 2013 11:08:04 +0000 (14:08 +0300)
30 files changed:
AUTHORS [new file with mode: 0644]
COPYING [new symlink]
ChangeLog [new file with mode: 0644]
INSTALL [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
autogen.sh [new file with mode: 0755]
configure.ac [new file with mode: 0644]
daemon/Makefile.am [new file with mode: 0644]
daemon/dbus-manager-doc-gen-org.tizen.messageport.Manager.xml [new file with mode: 0644]
daemon/dbus-manager.c [new file with mode: 0644]
daemon/dbus-manager.h [new file with mode: 0644]
daemon/dbus-server.c [new file with mode: 0644]
daemon/dbus-server.h [new file with mode: 0644]
daemon/dbus-service.c [new file with mode: 0644]
daemon/dbus-service.h [new file with mode: 0644]
daemon/main.c [new file with mode: 0644]
daemon/manager.c [new file with mode: 0644]
daemon/manager.h [new file with mode: 0644]
daemon/org.tizen.messageport.Manager.xml [new file with mode: 0644]
daemon/org.tizen.messageport.Service.xml [new file with mode: 0644]
daemon/server-socket.c [new file with mode: 0644]
daemon/server-socket.h [new file with mode: 0644]
daemon/service.c [new file with mode: 0644]
daemon/service.h [new file with mode: 0644]
lib/message-port.c [new file with mode: 0644]
lib/message-port.h [new file with mode: 0644]
lib/msgport-manager.c [new file with mode: 0644]
lib/msgport-manager.h [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/COPYING b/COPYING
new file mode 120000 (symlink)
index 0000000..6168a39
--- /dev/null
+++ b/COPYING
@@ -0,0 +1 @@
+/usr/share/automake-1.11/COPYING
\ No newline at end of file
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..a1e89e1
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,370 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994-1996, 1999-2002, 2004-2011 Free Software Foundation,
+Inc.
+
+   Copying and distribution of this file, with or without modification,
+are permitted in any medium without royalty provided the copyright
+notice and this notice are preserved.  This file is offered as-is,
+without warranty of any kind.
+
+Basic Installation
+==================
+
+   Briefly, the shell commands `./configure; make; make install' should
+configure, build, and install this package.  The following
+more-detailed instructions are generic; see the `README' file for
+instructions specific to this package.  Some packages provide this
+`INSTALL' file but do not implement all of the features documented
+below.  The lack of an optional feature in a given package is not
+necessarily a bug.  More recommendations for GNU packages can be found
+in *note Makefile Conventions: (standards)Makefile Conventions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You need `configure.ac' if
+you want to change it or regenerate `configure' using a newer version
+of `autoconf'.
+
+   The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.
+
+     Running `configure' might take a while.  While running, it prints
+     some messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package, generally using the just-built uninstalled binaries.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.  When installing into a prefix owned by root, it is
+     recommended that the package be configured and built as a regular
+     user, and only the `make install' phase executed with root
+     privileges.
+
+  5. Optionally, type `make installcheck' to repeat any self-tests, but
+     this time using the binaries in their final installed location.
+     This target does not install anything.  Running this target as a
+     regular user, particularly if the prior `make install' required
+     root privileges, verifies that the installation completed
+     correctly.
+
+  6. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+  7. Often, you can also type `make uninstall' to remove the installed
+     files again.  In practice, not all packages have tested that
+     uninstallation works correctly, even though it is required by the
+     GNU Coding Standards.
+
+  8. Some packages, particularly those that use Automake, provide `make
+     distcheck', which can by used by developers to test that all other
+     targets like `make install' and `make uninstall' work correctly.
+     This target is generally not run by end users.
+
+Compilers and Options
+=====================
+
+   Some systems require unusual options for compilation or linking that
+the `configure' script does not know about.  Run `./configure --help'
+for details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c99 CFLAGS=-g LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+   You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you can use GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.  This
+is known as a "VPATH" build.
+
+   With a non-GNU `make', it is safer to compile the package for one
+architecture at a time in the source code directory.  After you have
+installed the package for one architecture, use `make distclean' before
+reconfiguring for another architecture.
+
+   On MacOS X 10.5 and later systems, you can create libraries and
+executables that work on multiple system types--known as "fat" or
+"universal" binaries--by specifying multiple `-arch' options to the
+compiler but only a single `-arch' option to the preprocessor.  Like
+this:
+
+     ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+                 CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+                 CPP="gcc -E" CXXCPP="g++ -E"
+
+   This is not guaranteed to produce working output in all cases, you
+may have to build one architecture at a time and combine the results
+using the `lipo' tool if you have problems.
+
+Installation Names
+==================
+
+   By default, `make install' installs the package's commands under
+`/usr/local/bin', include files under `/usr/local/include', etc.  You
+can specify an installation prefix other than `/usr/local' by giving
+`configure' the option `--prefix=PREFIX', where PREFIX must be an
+absolute file name.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
+PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.  In general, the
+default for these options is expressed in terms of `${prefix}', so that
+specifying just `--prefix' will affect all of the other directory
+specifications that were not explicitly provided.
+
+   The most portable way to affect installation locations is to pass the
+correct locations to `configure'; however, many packages provide one or
+both of the following shortcuts of passing variable assignments to the
+`make install' command line to change installation locations without
+having to reconfigure or recompile.
+
+   The first method involves providing an override variable for each
+affected directory.  For example, `make install
+prefix=/alternate/directory' will choose an alternate location for all
+directory configuration variables that were expressed in terms of
+`${prefix}'.  Any directories that were specified during `configure',
+but not in terms of `${prefix}', must each be overridden at install
+time for the entire installation to be relocated.  The approach of
+makefile variable overrides for each directory variable is required by
+the GNU Coding Standards, and ideally causes no recompilation.
+However, some platforms have known limitations with the semantics of
+shared libraries that end up requiring recompilation when using this
+method, particularly noticeable in packages that use GNU Libtool.
+
+   The second method involves providing the `DESTDIR' variable.  For
+example, `make install DESTDIR=/alternate/directory' will prepend
+`/alternate/directory' before all installation names.  The approach of
+`DESTDIR' overrides is not required by the GNU Coding Standards, and
+does not work on platforms that have drive letters.  On the other hand,
+it does better at avoiding recompilation issues, and works well even
+when some directory options were not specified in terms of `${prefix}'
+at `configure' time.
+
+Optional Features
+=================
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+   Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+   Some packages offer the ability to configure how verbose the
+execution of `make' will be.  For these packages, running `./configure
+--enable-silent-rules' sets the default to minimal output, which can be
+overridden with `make V=1'; while running `./configure
+--disable-silent-rules' sets the default to verbose, which can be
+overridden with `make V=0'.
+
+Particular systems
+==================
+
+   On HP-UX, the default C compiler is not ANSI C compatible.  If GNU
+CC is not installed, it is recommended to use the following options in
+order to use an ANSI C compiler:
+
+     ./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
+
+and if that doesn't work, install pre-built binaries of GCC for HP-UX.
+
+   HP-UX `make' updates targets which have the same time stamps as
+their prerequisites, which makes it generally unusable when shipped
+generated files such as `configure' are involved.  Use GNU `make'
+instead.
+
+   On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
+parse its `<wchar.h>' header file.  The option `-nodtk' can be used as
+a workaround.  If GNU CC is not installed, it is therefore recommended
+to try
+
+     ./configure CC="cc"
+
+and if that doesn't work, try
+
+     ./configure CC="cc -nodtk"
+
+   On Solaris, don't put `/usr/ucb' early in your `PATH'.  This
+directory contains several dysfunctional programs; working variants of
+these programs are available in `/usr/bin'.  So, if you need `/usr/ucb'
+in your `PATH', put it _after_ `/usr/bin'.
+
+   On Haiku, software installed for all users goes in `/boot/common',
+not `/usr/local'.  It is recommended to use the following options:
+
+     ./configure --prefix=/boot/common
+
+Specifying the System Type
+==========================
+
+   There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on.  Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS
+     KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the option `--target=TYPE' to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+   If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+   Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+Unfortunately, this technique does not work for `CONFIG_SHELL' due to
+an Autoconf bug.  Until the bug is fixed you can use this workaround:
+
+     CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+`configure' Invocation
+======================
+
+   `configure' recognizes the following options to control how it
+operates.
+
+`--help'
+`-h'
+     Print a summary of all of the options to `configure', and exit.
+
+`--help=short'
+`--help=recursive'
+     Print a summary of the options unique to this package's
+     `configure', and exit.  The `short' variant lists options used
+     only in the top level, while the `recursive' variant lists options
+     also present in any nested packages.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`--prefix=DIR'
+     Use DIR as the installation prefix.  *note Installation Names::
+     for more details, including other options available for fine-tuning
+     the installation locations.
+
+`--no-create'
+`-n'
+     Run the configure checks, but stop before creating any output
+     files.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..05f0939
--- /dev/null
@@ -0,0 +1,3 @@
+SUBDIRS = daemon
+
+ACLOCAL_AMFLAGS = -I m4
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..019025b
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh -e
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+mkdir -p m4
+aclocal #-I m4 
+autoheader 
+autoconf 
+automake --add-missing --copy
+autoreconf --install --force
+. $srcdir/configure "$@"
+
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..65250fb
--- /dev/null
@@ -0,0 +1,33 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.60])
+AC_INIT([message-port], [0.0.1], [], [], [])
+AC_CONFIG_SRCDIR([daemon/main.c])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE([1.11 nostdinc silent-rules subdir-objects tar-pax -Wno-portability])
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for libraries.
+PKG_CHECK_MODULES([MESSAGEPORT],
+                  [glib-2.0 >= 2.30
+                   gio-2.0
+                   gio-unix-2.0])
+AC_SUBST(MESSAGEPORT_CFLAGS)
+AC_SUBST(MESSAGEPORT_LIBS)
+
+# Checks for header files.
+AC_CHECK_HEADERS([string.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+
+AC_OUTPUT([
+Makefile
+daemon/Makefile])
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
new file mode 100644 (file)
index 0000000..57c1854
--- /dev/null
@@ -0,0 +1,43 @@
+bin_PROGRAMS = messageportd
+NULL = 
+
+dbus-manager-glue.c dbus-maanager-glue.h : org.tizen.messageport.Manager.xml
+       gdbus-codegen                                \
+        --interface-prefix org.tizen.messageport \
+        --c-namespace      MsgPort_Dbus_Glue     \
+        --generate-c-code  dbus-manager-glue     \
+        $<
+
+dbus-service-glue.c dbus-service-glue.h : org.tizen.messageport.Service.xml
+       gdbus-codegen                                \
+        --interface-prefix org.tizen.messageport \
+        --c-namespace      MsgPort_Dbus_Glue     \
+        --generate-c-code  dbus-service-glue     \
+        $<
+
+messageportd_SOURCES = \
+    dbus-manager-glue.h \
+    dbus-manager-glue.c \
+    dubs-service-glue.h \
+    dbus-service-glue.c \
+    dbus-service.h \
+    dbus-service.c \
+    dbus-manager.h \
+    dbus-manager.c \
+    dbus-server.h \
+    dbus-server.c \
+    service.h \
+    service.c \
+    manager.h \
+    manager.c \
+    main.c \
+    $(NULL)
+
+messageportd_CPPFLAGS = \
+    -I$(top_builddir) \
+    $(MESSAGEPORT_CFLAGS)
+
+messageportd_LDADD = \
+    $(MESSAGEPORT_LIBS)
+
+CLEANFILES = 
diff --git a/daemon/dbus-manager-doc-gen-org.tizen.messageport.Manager.xml b/daemon/dbus-manager-doc-gen-org.tizen.messageport.Manager.xml
new file mode 100644 (file)
index 0000000..48622e1
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
+]>
+<refentry id="gdbus-org.tizen.messageport.Manager">
+  <refmeta>    <refentrytitle role="top_of_page" id="gdbus-interface-org-tizen-messageport-Manager.top_of_page">org.tizen.messageport.Manager</refentrytitle>
+  <indexterm zone="gdbus-interface-org-tizen-messageport-Manager.top_of_page"><primary sortas=".Manager">org.tizen.messageport.Manager</primary></indexterm>
+  </refmeta>  <refnamediv>    <refname>org.tizen.messageport.Manager</refname>    <refpurpose></refpurpose>  </refnamediv>  <refsynopsisdiv role="synopsis">
+    <title role="synopsis.title">Methods</title>
+    <synopsis>
+<link linkend="gdbus-method-org-tizen-messageport-Manager.registerService">registerService</link> (IN  s appId,
+                 IN  s port,
+                 OUT s socketURL);
+<link linkend="gdbus-method-org-tizen-messageport-Manager.connectService">connectService</link>  (IN  s remoteAppId,
+                 IN  s port);
+</synopsis>
+  </refsynopsisdiv>
+<refsect1 role="desc" id="gdbus-interface-org-tizen-messageport-Manager">
+  <title role="desc.title">Description</title>
+  <para></para>
+</refsect1>
+<refsect1 role="details" id="gdbus-methods-org.tizen.messageport.Manager">
+  <title role="details.title">Method Details</title>
+<refsect2 role="method" id="gdbus-method-org-tizen-messageport-Manager.registerService">
+  <title>The registerService() method</title>
+  <indexterm zone="gdbus-method-org-tizen-messageport-Manager.registerService"><primary sortas=".Manager.registerService">org.tizen.messageport.Manager.registerService()</primary></indexterm>
+<programlisting>
+registerService (IN  s appId,
+                 IN  s port,
+                 OUT s socketURL);
+</programlisting>
+<para></para>
+<variablelist role="params">
+<varlistentry>
+  <term><literal>IN s <parameter>appId</parameter></literal>:</term>
+  <listitem><para></para></listitem>
+</varlistentry>
+<varlistentry>
+  <term><literal>IN s <parameter>port</parameter></literal>:</term>
+  <listitem><para></para></listitem>
+</varlistentry>
+<varlistentry>
+  <term><literal>OUT s <parameter>socketURL</parameter></literal>:</term>
+  <listitem><para></para></listitem>
+</varlistentry>
+</variablelist>
+</refsect2>
+<refsect2 role="method" id="gdbus-method-org-tizen-messageport-Manager.connectService">
+  <title>The connectService() method</title>
+  <indexterm zone="gdbus-method-org-tizen-messageport-Manager.connectService"><primary sortas=".Manager.connectService">org.tizen.messageport.Manager.connectService()</primary></indexterm>
+<programlisting>
+connectService (IN  s remoteAppId,
+                IN  s port);
+</programlisting>
+<para></para>
+<variablelist role="params">
+<varlistentry>
+  <term><literal>IN s <parameter>remoteAppId</parameter></literal>:</term>
+  <listitem><para></para></listitem>
+</varlistentry>
+<varlistentry>
+  <term><literal>IN s <parameter>port</parameter></literal>:</term>
+  <listitem><para></para></listitem>
+</varlistentry>
+</variablelist>
+</refsect2>
+</refsect1>
+</refentry>
+
diff --git a/daemon/dbus-manager.c b/daemon/dbus-manager.c
new file mode 100644 (file)
index 0000000..a754595
--- /dev/null
@@ -0,0 +1,262 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "dbus-manager.h"
+#include "dbus-manager-glue.h"
+#include "dbus-service-glue.h"
+#include "dbus-service.h"
+#include "dbus-server.h"
+#include "manager.h"
+#include "common/log.h"
+
+G_DEFINE_TYPE (MsgPortDbusManager, msgport_dbus_manager, G_TYPE_OBJECT)
+
+#define MSGPORT_DBUS_MANAGER_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSGPORT_TYPE_DBUS_MANAGER, MsgPortDbusManagerPrivate)
+
+struct _MsgPortDbusManagerPrivate {
+    MsgPortDbusGlueManager *dbus_skeleton;
+    GDBusConnection        *connection;
+    MsgPortManager         *manager;
+    MsgPortDbusServer      *server;
+    gchar                  *app_id;
+};
+
+
+static void
+_dbus_manager_finalize (GObject *self)
+{
+    //MsgPortDbusManager *manager = MSGPORT_DBUS_MANAGER (self);
+
+    G_OBJECT_CLASS (msgport_dbus_manager_parent_class)->finalize (self);
+}
+
+static void
+_dbus_manager_dispose (GObject *self)
+{
+    MsgPortDbusManager *dbus_mgr = MSGPORT_DBUS_MANAGER (self);
+
+    DBG ("Unexporting dbus manager %p on connection %p", dbus_mgr, dbus_mgr->priv->connection);
+    if (dbus_mgr->priv->dbus_skeleton) {
+        g_dbus_interface_skeleton_unexport (
+                G_DBUS_INTERFACE_SKELETON (dbus_mgr->priv->dbus_skeleton));
+        g_clear_object (&dbus_mgr->priv->dbus_skeleton);
+    }
+
+    g_clear_object (&dbus_mgr->priv->connection);
+
+    /* unregister all services owned by this connection */
+    msgport_manager_unregister_services (dbus_mgr->priv->manager, dbus_mgr);
+
+    g_clear_object (&dbus_mgr->priv->manager);
+
+    G_OBJECT_CLASS (msgport_dbus_manager_parent_class)->dispose (self);
+}
+
+
+static gboolean
+_dbus_manager_handle_register_service (
+    MsgPortDbusManager    *dbus_mgr,
+    GDBusMethodInvocation *invocation,
+    const gchar           *port_name,
+    gboolean               is_trusted,
+    gpointer               userdata)
+{
+    GError *error = NULL;
+    MsgPortDbusService *dbus_service = NULL;
+    g_return_val_if_fail (dbus_mgr &&  MSGPORT_IS_DBUS_MANAGER (dbus_mgr), FALSE);
+
+    dbus_service = msgport_manager_register_service (
+            dbus_mgr->priv->manager, dbus_mgr, 
+            port_name, is_trusted, &error);
+
+    if (error) {
+        g_dbus_method_invocation_take_error (invocation, error);
+    }
+    else {
+        msgport_dbus_glue_manager_complete_register_service (
+                dbus_mgr->priv->dbus_skeleton, invocation, 
+                msgport_dbus_service_get_object_path(dbus_service));
+    }
+
+    return TRUE;
+}
+
+static gboolean
+_dbus_manager_handle_check_for_remote_service (
+    MsgPortDbusManager    *dbus_mgr,
+    GDBusMethodInvocation *invocation,
+    const gchar    *remote_app_id,
+    const gchar    *remote_port_name,
+    gboolean        is_trusted,
+    gpointer        userdata)
+{
+    GError *error = NULL;
+    MsgPortDbusService *dbus_service = NULL;
+    MsgPortDbusManager *remote_dbus_manager = NULL;
+
+    g_return_val_if_fail (dbus_mgr && MSGPORT_IS_MANAGER (dbus_mgr), FALSE);
+
+    remote_dbus_manager = msgport_dbus_server_get_dbus_manager_by_app_id (
+                dbus_mgr->priv->server, remote_app_id);
+
+    dbus_service = msgport_manager_get_service (dbus_mgr->priv->manager, 
+            remote_dbus_manager, remote_port_name, is_trusted, &error);
+
+    if (error) {
+        g_dbus_method_invocation_take_error (invocation, error);
+    }
+    else {
+        msgport_dbus_glue_manager_complete_check_for_remote_service (
+                dbus_mgr->priv->dbus_skeleton, invocation, 
+                msgport_dbus_service_get_object_path (dbus_service));
+    }
+
+    return TRUE;
+}
+
+static gboolean
+_dbus_manager_handle_send_message (
+    MsgPortDbusManager    *dbus_mgr,
+    GDBusMethodInvocation *invocation,
+    const gchar           *remote_service_path,
+    GVariant              *data,
+    gpointer               userdata)
+{
+    GError *error = NULL;
+    MsgPortDbusService *dbus_service = 0;
+
+    g_return_val_if_fail (dbus_mgr && MSGPORT_IS_DBUS_MANAGER (dbus_mgr), FALSE);
+
+    dbus_service = msgport_manager_get_service_by_path (dbus_mgr->priv->manager,
+                            remote_service_path, &error);
+
+    if (dbus_service){
+        msgport_dbus_service_send_message (dbus_service, data, NULL);
+    }
+    else if(error) {
+        g_dbus_method_invocation_take_error (invocation, error);
+    }
+
+    return TRUE;
+}
+
+static void
+msgport_dbus_manager_init (MsgPortDbusManager *self)
+{
+    MsgPortDbusManagerPrivate *priv = MSGPORT_DBUS_MANAGER_GET_PRIV (self);
+
+    priv->dbus_skeleton = msgport_dbus_glue_manager_skeleton_new ();
+    priv->manager = msgport_manager_new ();
+
+    g_signal_connect_swapped (priv->dbus_skeleton, "handle-register-service",
+                G_CALLBACK (_dbus_manager_handle_register_service), (gpointer)self);
+    g_signal_connect_swapped (priv->dbus_skeleton, "handle-check-for-remote-service",
+                G_CALLBACK (_dbus_manager_handle_check_for_remote_service), (gpointer)self);
+    g_signal_connect_swapped (priv->dbus_skeleton, "handle-send-message",
+                G_CALLBACK (_dbus_manager_handle_send_message), (gpointer)self);
+
+    self->priv = priv;
+}
+
+static void
+msgport_dbus_manager_class_init (MsgPortDbusManagerClass *klass)
+{
+    GObjectClass *gklass = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private (klass, sizeof(MsgPortDbusManagerPrivate));
+
+    gklass->finalize = _dbus_manager_finalize;
+    gklass->dispose = _dbus_manager_dispose;
+}
+
+static gchar *
+_get_app_id_from_connection (GDBusConnection *connection)
+{
+    gchar *str_cred = NULL;
+    GCredentials *cred = g_dbus_connection_get_peer_credentials (connection);
+
+    g_return_val_if_fail (cred != NULL, NULL);
+
+    str_cred = g_credentials_to_string (cred);
+    DBG ("Client Credentials : %s", str_cred);
+    g_free (str_cred);
+
+    return g_strdup_printf ("%d", g_credentials_get_unix_pid(cred, NULL));
+}
+
+MsgPortDbusManager *
+msgport_dbus_manager_new (
+    GDBusConnection *connection,
+    MsgPortDbusServer *server,
+    MsgPortManager *manager)
+{
+    MsgPortDbusManager *dbus_mgr = NULL;
+    GError *error = NULL;
+
+    dbus_mgr = MSGPORT_DBUS_MANAGER (g_object_new (MSGPORT_TYPE_DBUS_MANAGER, NULL));
+    if (!dbus_mgr) return NULL;
+
+    if (!g_dbus_interface_skeleton_export (
+            G_DBUS_INTERFACE_SKELETON (dbus_mgr->priv->dbus_skeleton),
+            connection,
+            "/",
+            &error)) {
+        g_print ("Failed to export dbus object on connection %p : %s",
+                    connection, error->message);
+        g_error_free (error);
+        g_object_unref (dbus_mgr);
+        return NULL;
+    }
+    dbus_mgr->priv->connection = g_object_ref (connection);
+    dbus_mgr->priv->manager = g_object_ref (manager);
+    dbus_mgr->priv->server = server;
+    dbus_mgr->priv->app_id =  _get_app_id_from_connection (connection);
+
+    return dbus_mgr;
+}
+
+MsgPortManager *
+msgport_dbus_manager_get_manager (MsgPortDbusManager *dbus_manager)
+{
+    g_return_val_if_fail (dbus_manager && MSGPORT_IS_DBUS_MANAGER (dbus_manager), NULL);
+
+    return dbus_manager->priv->manager;
+}
+
+GDBusConnection *
+msgport_dbus_manager_get_connection (MsgPortDbusManager *dbus_manager)
+{
+    g_return_val_if_fail (dbus_manager && MSGPORT_IS_DBUS_MANAGER (dbus_manager), NULL);
+
+    return dbus_manager->priv->connection;
+}
+
+const gchar *
+msgport_dbus_manager_get_app_id (MsgPortDbusManager *dbus_manager)
+{
+    g_return_val_if_fail (dbus_manager && MSGPORT_IS_DBUS_MANAGER (dbus_manager), NULL);
+
+    return (const gchar *)dbus_manager->priv->app_id;
+}
+
diff --git a/daemon/dbus-manager.h b/daemon/dbus-manager.h
new file mode 100644 (file)
index 0000000..9a4e222
--- /dev/null
@@ -0,0 +1,76 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _MSGPORT_DBUS_MANAGER_H
+#define _MSGPORT_DBUS_MANAGER_H
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MSGPORT_TYPE_DBUS_MANAGER (msgport_dbus_manager_get_type())
+#define MSGPORT_DBUS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MSGPORT_TYPE_DBUS_MANAGER, MsgPortDbusManager))
+#define MSGPORT_DBUS_MANAGER_CLASS(obj)  (G_TYPE_CHECK_CLASS_CAST((kls), MSGPORT_TYPE_DBUS_MANAGER, MsgPortDbusManagerClass))
+#define MSGPORT_IS_DBUS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MSGPORT_TYPE_DBUS_MANAGER))
+#define MSGPORT_IS_DBUS_MANAGER_CLASS(kls) (G_TYPE_CHECK_CLASS_TYPE((kls), MSGPORT_TYPE_DBUS_MANAGER))
+
+typedef struct _MsgPortDbusManager MsgPortDbusManager;
+typedef struct _MsgPortDbusManagerClass MsgPortDbusManagerClass;
+typedef struct _MsgPortDbusManagerPrivate MsgPortDbusManagerPrivate;
+
+typedef struct _MsgPortManager MsgPortManager;
+typedef struct _MsgPortDbusServer MsgPortDbusServer;
+
+struct _MsgPortDbusManager
+{
+    GObject parent;
+
+    /* private */
+    MsgPortDbusManagerPrivate *priv;
+};
+
+struct _MsgPortDbusManagerClass
+{
+    GObjectClass parenet_class;
+};
+
+GType msgport_dbus_manager_get_type (void);
+
+MsgPortDbusManager *
+msgport_dbus_manager_new (GDBusConnection *connection, MsgPortDbusServer *server, MsgPortManager *manager);
+
+MsgPortManager *
+msgport_dbus_manager_get_manager (MsgPortDbusManager *dbus_manager);
+
+GDBusConnection *
+msgport_dbus_manager_get_connection (MsgPortDbusManager *dbus_manager);
+
+const gchar *
+msgport_dbus_manager_get_app_id (MsgPortDbusManager *dbus_manager);
+
+G_END_DECLS
+
+#endif /* _MSGPORT_DBUS_MANAER_H */
+
diff --git a/daemon/dbus-server.c b/daemon/dbus-server.c
new file mode 100644 (file)
index 0000000..eaa755e
--- /dev/null
@@ -0,0 +1,325 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include <errno.h>
+#include <string.h>
+#include <gio/gio.h>
+#include <glib/gstdio.h>
+
+#include "config.h"
+#include "common/log.h"
+#include "dbus-server.h"
+#include "dbus-manager.h"
+#include "manager.h"
+
+
+G_DEFINE_TYPE (MsgPortDbusServer, msgport_dbus_server, G_TYPE_OBJECT)
+
+
+#define MSGPORT_DBUS_SERVER_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSGPORT_TYPE_DBUS_SERVER, MsgPortDbusServerPrivate)
+
+#ifndef MSGPORT_DBUS_ADDRESS
+#   define MSGPORT_DBUS_ADDRESS "unix:path=%s/.message_port"
+#endif /* MSGPORT_DBUS_ADDRESS */
+
+enum
+{
+    PROP_0,
+
+    PROP_ADDRESS,
+    N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES];
+
+struct _MsgPortDbusServerPrivate
+{
+    GDBusServer    *bus_server;
+    gchar          *address;
+    MsgPortManager *manager;
+    GHashTable     *dbus_managers; /* {GDBusConnection,MsgPortDbusManager} */
+};
+
+static void _on_connection_closed (GDBusConnection *connection,
+                       gboolean         remote_peer_vanished,
+                       GError          *error,
+                       gpointer         user_data);
+
+static void
+_set_property (GObject *object,
+        guint property_id,
+        const GValue *value, GParamSpec *pspec)
+{
+    MsgPortDbusServer *self = MSGPORT_DBUS_SERVER (object);
+
+    switch (property_id) {
+        case PROP_ADDRESS: {
+            self->priv->address = g_value_dup_string (value);
+            break;
+        }
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+_get_property (GObject *object,
+        guint property_id,
+        GValue *value, 
+        GParamSpec *pspec)
+{
+    MsgPortDbusServer *self = MSGPORT_DBUS_SERVER (object);
+
+    switch (property_id) {
+        case PROP_ADDRESS: {
+            g_value_set_string (value, g_dbus_server_get_client_address (
+                    self->priv->bus_server));
+            break;
+        }
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+_clear_watchers(gpointer connection, gpointer auth_service, gpointer userdata)
+{
+    g_signal_handlers_disconnect_by_func (connection, _on_connection_closed, userdata);
+}
+
+static void
+_dispose (GObject *object)
+{
+    MsgPortDbusServer *self = MSGPORT_DBUS_SERVER (object);
+
+    if (self->priv->bus_server) {
+        if (g_dbus_server_is_active (self->priv->bus_server))
+            g_dbus_server_stop (self->priv->bus_server);
+        g_object_unref (self->priv->bus_server);
+        self->priv->bus_server = NULL;
+    }
+
+    if (self->priv->dbus_managers) {
+        g_hash_table_foreach (self->priv->dbus_managers, _clear_watchers, self);
+        g_hash_table_unref (self->priv->dbus_managers);
+        self->priv->dbus_managers = NULL;
+    }
+
+    G_OBJECT_CLASS (msgport_dbus_server_parent_class)->dispose (object);
+}
+
+static void
+_finalize (GObject *object)
+{
+    MsgPortDbusServer *self = MSGPORT_DBUS_SERVER (object);
+    if (self->priv->address && g_str_has_prefix (self->priv->address, "unix:path=")) {
+        const gchar *path = g_strstr_len(self->priv->address, -1, "unix:path=") + 10;
+        if (path) { 
+            g_unlink (path);
+        }
+        g_free (self->priv->address);
+        self->priv->address = NULL;
+    }
+
+    G_OBJECT_CLASS (msgport_dbus_server_parent_class)->finalize (object);
+}
+
+static void
+msgport_dbus_server_class_init (MsgPortDbusServerClass *klass)
+{
+    GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+    g_type_class_add_private (object_class, sizeof (MsgPortDbusServerPrivate));
+
+    object_class->get_property = _get_property;
+    object_class->set_property = _set_property;
+    object_class->dispose = _dispose;
+    object_class->finalize = _finalize;
+
+    properties[PROP_ADDRESS] = g_param_spec_string ("address",
+                                                    "server address",
+                                                    "Server socket address",
+                                                    NULL,
+                                                    G_PARAM_READWRITE | 
+                                                    G_PARAM_CONSTRUCT_ONLY | 
+                                                    G_PARAM_STATIC_STRINGS);
+
+    g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+msgport_dbus_server_init (MsgPortDbusServer *self)
+{
+    self->priv = MSGPORT_DBUS_SERVER_GET_PRIV(self);
+    self->priv->bus_server = NULL;
+    self->priv->address = NULL;
+
+    self->priv->manager = msgport_manager_new ();
+    self->priv->dbus_managers = g_hash_table_new_full (
+        g_direct_hash, g_direct_equal, NULL, g_object_unref);
+}
+
+const gchar *
+msgport_dbus_server_get_address (MsgPortDbusServer *server)
+{
+    g_return_val_if_fail (server || MSGPORT_IS_DBUS_SERVER (server), NULL);
+
+    return g_dbus_server_get_client_address (server->priv->bus_server);
+}
+
+static void
+_on_connection_closed (GDBusConnection *connection,
+                       gboolean         remote_peer_vanished,
+                       GError          *error,
+                       gpointer         user_data)
+{
+    MsgPortDbusServer *server = MSGPORT_DBUS_SERVER (user_data);
+
+    g_signal_handlers_disconnect_by_func (connection, _on_connection_closed, user_data);
+    DBG("dbus connection(%p) closed (peer vanished : %d) : %s",
+            connection, remote_peer_vanished, error ? error->message : "unknwon reason");
+
+    g_hash_table_remove (server->priv->dbus_managers, connection);
+}
+
+void
+msgport_dbus_server_start_dbus_manager_for_connection (
+    MsgPortDbusServer *server,
+    GDBusConnection *connection)
+{
+    MsgPortDbusManager *dbus_manager = NULL;
+
+    DBG("Starting dbus manager on connection %p", connection);
+
+    dbus_manager = msgport_dbus_manager_new (
+        connection, server, server->priv->manager);
+
+    g_hash_table_insert (server->priv->dbus_managers, connection, dbus_manager);
+
+    g_signal_connect (connection, "closed", G_CALLBACK(_on_connection_closed), server);
+}
+
+static gboolean
+_on_client_request (GDBusServer *dbus_server, GDBusConnection *connection, gpointer userdata)
+{
+    MsgPortDbusServer *server = MSGPORT_DBUS_SERVER(userdata);
+
+    if (!server) {
+        ERR ("memory corruption");
+        return TRUE;
+    }
+
+    msgport_dbus_server_start_dbus_manager_for_connection (server, connection);
+
+    return TRUE;
+}
+
+MsgPortDbusServer * msgport_dbus_server_new_with_address (const gchar *address)
+{
+    GError *err = NULL;
+    gchar *guid = 0;
+    const gchar *file_path = NULL;
+    MsgPortDbusServer *server = MSGPORT_DBUS_SERVER (
+        g_object_new (MSGPORT_TYPE_DBUS_SERVER, "address", address, NULL));
+
+    if (!server) return NULL;
+
+    if (g_str_has_prefix(address, "unix:path=")) {
+        file_path = g_strstr_len (address, -1, "unix:path=") + 10;
+
+        if (g_file_test(file_path, G_FILE_TEST_EXISTS)) {
+            g_unlink (file_path);
+        }
+        else {
+            gchar *base_path = g_path_get_dirname (file_path);
+            if (g_mkdir_with_parents (base_path, S_IRUSR | S_IWUSR | S_IXUSR) == -1) {
+                WARN ("Could not create '%s', error: %s", base_path, strerror(errno));
+            }
+            g_free (base_path);
+        }
+    }
+
+    guid = g_dbus_generate_guid ();
+
+    server->priv->bus_server = g_dbus_server_new_sync (server->priv->address,
+            G_DBUS_SERVER_FLAGS_NONE, guid, NULL, NULL, &err);
+
+    g_free (guid);
+
+    if (!server->priv->bus_server) {
+        ERR ("failed to start server at address '%s':%s", server->priv->address,
+                 err->message);
+        g_error_free (err);
+        
+        g_object_unref (server);
+     
+        return NULL;
+    }
+
+    g_signal_connect (server->priv->bus_server, "new-connection", G_CALLBACK(_on_client_request), server);
+
+    g_dbus_server_start (server->priv->bus_server);
+
+    if (file_path)
+        g_chmod (file_path, S_IRUSR | S_IWUSR);
+
+    return server;
+}
+
+MsgPortDbusServer *
+msgport_dbus_server_new () {
+       MsgPortDbusServer *server = NULL;
+       gchar *address = g_strdup_printf (MSGPORT_DBUS_ADDRESS, g_get_user_runtime_dir());
+
+    server = msgport_dbus_server_new_with_address (address);
+    g_free (address);
+
+    return server ;
+}
+
+MsgPortManager *
+msgport_dbus_server_get_manager (MsgPortDbusServer *server)
+{
+    g_return_val_if_fail (server && MSGPORT_IS_DBUS_SERVER (server), NULL);
+
+    return server->priv->manager;
+}
+
+static gboolean
+_find_dbus_manager_by_app_id (
+    GDBusConnection *key,
+    MsgPortDbusManager *value,
+    const gchar *app_id_to_find)
+{
+    return !g_strcmp0 (msgport_dbus_manager_get_app_id (value), app_id_to_find);
+}
+
+MsgPortDbusManager *
+msgport_dbus_server_get_dbus_manager_by_app_id (MsgPortDbusServer *server, const gchar *app_id)
+{
+    g_return_val_if_fail (server && MSGPORT_IS_DBUS_SERVER (server), NULL);
+
+    return (MsgPortDbusManager *)g_hash_table_find (server->priv->dbus_managers,
+            (GHRFunc)_find_dbus_manager_by_app_id, (gpointer)app_id);
+}
+
diff --git a/daemon/dbus-server.h b/daemon/dbus-server.h
new file mode 100644 (file)
index 0000000..b6420da
--- /dev/null
@@ -0,0 +1,73 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef __MSGPORT_DBUS_SERVER_H_
+#define __MSGPORT_DBUS_SERVER_H_
+
+#include <config.h>
+#include <glib.h>
+#include <glib-object.h>
+//#include "manager.h"
+
+G_BEGIN_DECLS
+
+#define MSGPORT_TYPE_DBUS_SERVER            (msgport_dbus_server_get_type())
+#define MSGPORT_DBUS_SERVER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), MSGPORT_TYPE_DBUS_SERVER, MsgPortDbusServer))
+#define MSGPORT_DBUS_SERVER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), MSGPORT_TYPE_DBUS_SERVER, MsgPortDbusServerClass))
+#define MSGPORT_IS_DBUS_SERVER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), MSGPORT_TYPE_DBUS_SERVER))
+#define MSGPORT_IS_DBUS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MSGPORT_TYPE_DBUS_SERVER))
+#define MSGPORT_DBUS_SERVER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), MSGPORT_TYPE_DBUS_SERVER, MsgPortDbusServerClass))
+
+typedef struct _MsgPortManager MsgPortManager;
+typedef struct _MsgPortDbusManager MsgPortDbusManager;
+typedef struct _MsgPortDbusServer MsgPortDbusServer;
+typedef struct _MsgPortDbusServerClass MsgPortDbusServerClass;
+typedef struct _MsgPortDbusServerPrivate MsgPortDbusServerPrivate;
+
+struct _MsgPortDbusServer
+{
+    GObject parent;
+
+    /* priv */
+    MsgPortDbusServerPrivate *priv;
+};
+
+struct _MsgPortDbusServerClass
+{
+    GObjectClass parent_class;
+};
+
+GType msgport_dbus_server_get_type();
+
+const gchar *
+msgport_dbus_server_get_address (MsgPortDbusServer *server) G_GNUC_CONST;
+
+MsgPortDbusServer * msgport_dbus_server_new ();
+
+MsgPortManager    * msgport_dbus_server_get_manager (MsgPortDbusServer *server);
+
+MsgPortDbusManager *
+msgport_dbus_server_get_dbus_manager_by_app_id (MsgPortDbusServer *server, const gchar *app_id);
+
+#endif /* __MSGPORT_DBUS_SERVER_H_ */
diff --git a/daemon/dbus-service.c b/daemon/dbus-service.c
new file mode 100644 (file)
index 0000000..b2423cb
--- /dev/null
@@ -0,0 +1,258 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "dbus-service.h"
+#include "dbus-service-glue.h"
+#include "manager.h"
+#include "common/log.h"
+
+G_DEFINE_TYPE (MsgPortDbusService, msgport_dbus_service, G_TYPE_OBJECT)
+
+#define MSGPORT_DBUS_SERVICE_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSGPORT_TYPE_DBUS_SERVICE, MsgPortDbusServicePrivate)
+
+struct _MsgPortDbusServicePrivate {
+    MsgPortDbusManager *owner;
+    MsgPortDbusGlueService *dbus_skeleton;
+    MsgPortService *service;
+    gchar *object_path;
+};
+
+
+static void
+_dbus_service_finalize (GObject *self)
+{
+    MsgPortDbusService *dbus_service = MSGPORT_DBUS_SERVICE (self);
+
+    if (dbus_service->priv->object_path) {
+        g_free (dbus_service->priv->object_path);
+        dbus_service->priv->object_path = NULL;
+    }
+
+    G_OBJECT_CLASS (msgport_dbus_service_parent_class)->finalize (self);
+}
+
+static void
+_dbus_service_dispose (GObject *self)
+{
+    MsgPortDbusService *dbus_service = MSGPORT_DBUS_SERVICE (self);
+    DBG ("Unregistering service '%s'", 
+        msgport_service_get_port_name (dbus_service->priv->service));
+    if (dbus_service->priv->dbus_skeleton) {
+        g_dbus_interface_skeleton_unexport (
+                G_DBUS_INTERFACE_SKELETON (dbus_service->priv->dbus_skeleton));
+        g_clear_object (&dbus_service->priv->dbus_skeleton);
+    }
+
+    g_clear_object (&dbus_service->priv->service);
+
+//    g_clear_object (&dbus_service->priv->owner);
+
+    G_OBJECT_CLASS (msgport_dbus_service_parent_class)->dispose (self);
+}
+
+
+static gboolean
+_dbus_service_handle_send_message (
+    MsgPortDbusService    *dbus_service,
+    GDBusMethodInvocation *invocation,
+    const gchar           *remote_service_path,
+    GVariant              *data,
+    gpointer               userdata)
+{
+    MsgPortDbusService *peer_dbus_service = NULL;
+    MsgPortManager *manager = NULL;
+    GError *error;
+    g_return_val_if_fail (dbus_service &&  MSGPORT_IS_DBUS_SERVICE (dbus_service), FALSE);
+
+    manager = msgport_dbus_manager_get_manager (dbus_service->priv->owner);
+    peer_dbus_service = msgport_manager_get_service_by_path (manager, remote_service_path, &error);
+    if (!peer_dbus_service) {
+        /* FIXME: return ENOTFOUND error */
+        g_dbus_method_invocation_take_error (invocation, error);
+    }
+    else {
+        msgport_dbus_service_send_message (peer_dbus_service, data,
+                dbus_service->priv->object_path);
+        msgport_dbus_glue_service_complete_send_message (
+                dbus_service->priv->dbus_skeleton, invocation);
+    }
+
+    return TRUE;
+}
+
+static gboolean
+_dbus_service_handle_unregister (
+    MsgPortDbusService    *dbus_service,
+    GDBusMethodInvocation *invocation,
+    gpointer               userdata)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), FALSE);
+
+    /* FIXME unregister */
+    return TRUE;
+}
+
+static gboolean
+_dbus_service_handle_get_properties (
+    MsgPortDbusService    *dbus_service,
+    GDBusMethodInvocation *invocation,
+    gpointer               userdata)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), FALSE);
+
+    msgport_dbus_glue_service_complete_get_properties (
+            dbus_service->priv->dbus_skeleton,
+            invocation,
+            msgport_service_to_variant (dbus_service->priv->service));
+
+    return TRUE;
+}
+
+static void
+msgport_dbus_service_init (MsgPortDbusService *self)
+{
+    MsgPortDbusServicePrivate *priv = MSGPORT_DBUS_SERVICE_GET_PRIV (self);
+
+    priv->dbus_skeleton = msgport_dbus_glue_service_skeleton_new ();
+    priv->service = NULL;
+    priv->owner = NULL;
+
+    g_signal_connect_swapped (priv->dbus_skeleton, "handle-send-message",
+                G_CALLBACK (_dbus_service_handle_send_message), (gpointer)self);
+    g_signal_connect_swapped (priv->dbus_skeleton, "handle-unregister",
+                G_CALLBACK (_dbus_service_handle_unregister), (gpointer)self);
+    g_signal_connect_swapped (priv->dbus_skeleton, "handle-get-properties",
+                G_CALLBACK (_dbus_service_handle_get_properties), (gpointer)self);
+
+    self->priv = priv;
+}
+
+static void
+msgport_dbus_service_class_init (MsgPortDbusServiceClass *klass)
+{
+    GObjectClass *gklass = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private (klass, sizeof(MsgPortDbusServicePrivate));
+
+    gklass->finalize = _dbus_service_finalize;
+    gklass->dispose = _dbus_service_dispose;
+}
+
+MsgPortDbusService *
+msgport_dbus_service_new (MsgPortDbusManager *owner, const gchar *name, gboolean is_trusted)
+{
+    static guint object_conter = 0;
+    MsgPortDbusService *dbus_service = NULL;
+    GDBusConnection *connection = NULL;
+    gchar *object_path = 0;
+
+    GError *error = NULL;
+
+    connection = msgport_dbus_manager_get_connection (owner),
+    dbus_service = MSGPORT_DBUS_SERVICE (g_object_new (MSGPORT_TYPE_DBUS_SERVICE, NULL));
+    if (!dbus_service) return NULL;
+
+    /* FIXME: better way of path creation */
+    object_path = g_strdup_printf ("/%u", ++object_conter); 
+    if (!g_dbus_interface_skeleton_export (
+            G_DBUS_INTERFACE_SKELETON (dbus_service->priv->dbus_skeleton),
+            connection,
+            object_path,
+            &error)) {
+        g_print ("Failed to export dbus object on connection %p : %s",
+                    connection, error->message);
+        g_error_free (error);
+        g_object_unref (dbus_service);
+        g_free (object_path);
+        return NULL;
+    }
+    dbus_service->priv->owner = /*g_object_ref*/ (owner);
+    dbus_service->priv->object_path = object_path;
+    dbus_service->priv->service = msgport_service_new (
+            msgport_dbus_manager_get_app_id (owner), name, is_trusted);
+
+    g_assert (dbus_service->priv->service);
+    g_assert (MSGPORT_IS_SERVICE (dbus_service->priv->service));
+
+    return dbus_service;
+}
+
+const gchar *
+msgport_dbus_service_get_object_path (MsgPortDbusService *dbus_service)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), NULL);
+
+    return (const gchar *)dbus_service->priv->object_path ;
+}
+
+GDBusConnection *
+msgport_dbus_service_get_connection (MsgPortDbusService *dbus_service)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), NULL);
+
+    return msgport_dbus_manager_get_connection (dbus_service->priv->owner);
+}
+
+MsgPortService *
+msgport_dbus_service_get_service (MsgPortDbusService *dbus_service)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), NULL);
+
+    return dbus_service->priv->service;
+}
+
+MsgPortDbusManager *
+msgport_dbus_service_get_owner (MsgPortDbusService *dbus_service)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), NULL);
+
+    return dbus_service->priv->owner;
+}
+
+const gchar *
+msgport_dbus_service_get_port_name (MsgPortDbusService *dbus_service)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), NULL);
+
+    return msgport_service_get_port_name (dbus_service->priv->service);
+}
+
+gboolean
+msgport_dbus_service_get_is_trusted (MsgPortDbusService *dbus_service)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), FALSE);
+
+    return msgport_service_get_is_trusted (dbus_service->priv->service);
+}
+
+gboolean
+msgport_dbus_service_send_message (MsgPortDbusService *dbus_service, GVariant *data, const gchar *from)
+{
+    g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), FALSE);
+
+    msgport_dbus_glue_service_emit_on_message (dbus_service->priv->dbus_skeleton, data, from);
+    
+    return TRUE;
+}
+
diff --git a/daemon/dbus-service.h b/daemon/dbus-service.h
new file mode 100644 (file)
index 0000000..abd440e
--- /dev/null
@@ -0,0 +1,92 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _MSGPORT_DBUS_SERVICE_H
+#define _MSGPORT_DBUS_SERVICE_H
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib-object.h>
+#include "service.h"
+#include "dbus-manager.h"
+
+G_BEGIN_DECLS
+
+#define MSGPORT_TYPE_DBUS_SERVICE (msgport_dbus_service_get_type())
+#define MSGPORT_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MSGPORT_TYPE_DBUS_SERVICE, MsgPortDbusService))
+#define MSGPORT_DBUS_SERVICE_CLASS(obj)  (G_TYPE_CHECK_CLASS_CAST((kls), MSGPORT_TYPE_DBUS_SERVICE, MsgPortDbusServiceClass))
+#define MSGPORT_IS_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MSGPORT_TYPE_DBUS_SERVICE))
+#define MSGPORT_IS_DBUS_SERVICE_CLASS(kls) (G_TYPE_CHECK_CLASS_TYPE((kls), MSGPORT_TYPE_DBUS_SERVICE))
+
+typedef struct _MsgPortDbusService MsgPortDbusService;
+typedef struct _MsgPortDbusServiceClass MsgPortDbusServiceClass;
+typedef struct _MsgPortDbusServicePrivate MsgPortDbusServicePrivate;
+
+struct _MsgPortDbusService
+{
+    GObject parent;
+
+    /* private */
+    MsgPortDbusServicePrivate *priv;
+};
+
+struct _MsgPortDbusServiceClass
+{
+    GObjectClass parenet_class;
+};
+
+GType msgport_dbus_service_get_type (void);
+
+MsgPortDbusService *
+msgport_dbus_service_new (MsgPortDbusManager *owner, const gchar *name, gboolean is_trusted);
+
+const gchar *
+msgport_dbus_service_get_object_path (MsgPortDbusService *dbus_service);
+
+GDBusConnection *
+msgport_dbus_service_get_connection (MsgPortDbusService *dbus_service);
+
+MsgPortService *
+msgport_dbus_service_get_service (MsgPortDbusService *dbus_service);
+
+MsgPortDbusManager *
+msgport_dbus_service_get_owner (MsgPortDbusService *dbus_service);
+
+const gchar *
+msgport_dbus_service_get_app_id (MsgPortDbusService *dbus_service);
+
+const gchar *
+msgport_dbus_service_get_port_name (MsgPortDbusService *dbus_service);
+
+gboolean
+msgport_dbus_service_get_is_trusted (MsgPortDbusService *dbus_service);
+
+gboolean
+msgport_dbus_service_send_message (MsgPortDbusService *dbus_service,
+                                   GVariant *data,
+                                   const gchar *from);
+
+G_END_DECLS
+
+#endif /* _MSGPORT_DBUS_SERVICE_H */
+
diff --git a/daemon/main.c b/daemon/main.c
new file mode 100644 (file)
index 0000000..f784e2c
--- /dev/null
@@ -0,0 +1,37 @@
+#include <glib.h>
+#include "common/log.h"
+#include "dbus-server.h"
+
+static gboolean
+_on_unix_signal (gpointer data)
+{
+    g_main_loop_quit ((GMainLoop*)data);
+
+    return FALSE;
+}
+
+int main (int argc, char *argv[])
+{
+    GMainLoop *main_loop = NULL;
+    MsgPortDbusServer *server = NULL;
+
+#if !GLIB_CHECK_VERSION (2, 36, 0)
+    g_type_init (&argc, &argv);
+#endif
+
+    main_loop = g_main_loop_new (NULL, FALSE);
+
+    server = msgport_dbus_server_new();
+
+    DBG ("server started at : %s", msgport_dbus_server_get_address (server));
+
+    g_unix_signal_add (SIGTERM, _on_unix_signal, main_loop);
+    g_unix_signal_add (SIGINT, _on_unix_signal, main_loop);
+
+    g_main_loop_run (main_loop);
+
+    g_object_unref (server);
+    g_main_loop_unref (main_loop);
+
+    DBG("Clean close");
+}
diff --git a/daemon/manager.c b/daemon/manager.c
new file mode 100644 (file)
index 0000000..a860819
--- /dev/null
@@ -0,0 +1,281 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "manager.h"
+#include "common/log.h"
+#include "dbus-manager.h"
+#include "dbus-service.h"
+
+G_DEFINE_TYPE (MsgPortManager, msgport_manager, G_TYPE_OBJECT)
+
+#define MSGPORT_MANAGER_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSGPORT_TYPE_MANAGER, MsgPortManagerPrivate)
+
+struct _MsgPortManagerPrivate {
+    /*
+     * Key : const gchar * - object_path of the service
+     * Value : MsgPortDbusService * (transfe full)
+     */
+    GHashTable *path_service_map; /* {object_path,MsgPortDbusService} */
+
+    /*
+     * Holds services owned by a client 
+     * Key : MsgPortDbusManager *
+     * Value : GList<MsgPortDbusService *> (tranfer none)
+     */
+    GHashTable *owner_service_map; /* {app_id,GList[MsgPortDbusService]} */
+};
+
+static void
+_manager_finalize (GObject *self)
+{
+    //MsgPortManager *manager = MSGPORT_MANAGER (self);
+
+    G_OBJECT_CLASS (msgport_manager_parent_class)->finalize (self);
+}
+
+static void
+_manager_dispose (GObject *self)
+{
+    MsgPortManager *manager = MSGPORT_MANAGER (self);
+
+    g_hash_table_unref (manager->priv->owner_service_map);
+    manager->priv->owner_service_map = NULL;
+
+    g_hash_table_unref (manager->priv->path_service_map);
+    manager->priv->path_service_map = NULL;
+
+    G_OBJECT_CLASS (msgport_manager_parent_class)->dispose (self);
+}
+
+static void
+msgport_manager_init (MsgPortManager *self)
+{
+    MsgPortManagerPrivate *priv = MSGPORT_MANAGER_GET_PRIV (self);
+
+    priv->path_service_map = g_hash_table_new_full (
+                g_str_hash, g_str_equal, NULL, g_object_unref);
+    priv->owner_service_map = g_hash_table_new_full (
+                g_direct_hash, g_direct_equal, 
+                NULL, (GDestroyNotify) g_list_free);
+
+    self->priv = priv;
+}
+
+static void
+msgport_manager_class_init (MsgPortManagerClass *klass)
+{
+    GObjectClass *gklass = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private (klass, sizeof(MsgPortManagerPrivate));
+
+    gklass->finalize = _manager_finalize;
+    gklass->dispose = _manager_dispose;
+}
+
+MsgPortManager *
+msgport_manager_new ()
+{
+    static GObject *manager = NULL;
+
+    if (!manager) {
+        manager =  g_object_new (MSGPORT_TYPE_MANAGER, NULL);
+        g_object_add_weak_pointer (manager, (gpointer *)&manager);
+
+        return MSGPORT_MANAGER (manager);
+    }
+
+    return MSGPORT_MANAGER (g_object_ref (manager));
+}
+
+MsgPortDbusService *
+msgport_manager_register_service (
+    MsgPortManager     *manager,
+    MsgPortDbusManager *owner,
+    const gchar        *port_name,
+    gboolean            is_trusted,
+    GError            **error)
+{
+    GList   *service_list  = NULL; /* services list by app_id */
+    gboolean was_empty = TRUE;
+    MsgPortDbusService *dbus_service = NULL;
+
+    g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), NULL);
+    g_return_val_if_fail (owner && MSGPORT_IS_DBUS_MANAGER (owner), NULL);
+
+    if ((service_list = (GList *)g_hash_table_lookup (manager->priv->owner_service_map, owner)) != NULL) {
+        GList *list = NULL;
+
+        for (list = service_list; list != NULL; list = list->next) {
+            MsgPortDbusService *dbus_service = (MsgPortDbusService *)list->data;
+
+            if ( !g_strcmp0 (port_name, msgport_dbus_service_get_port_name (dbus_service))) {
+                /* FIXME: return EALREADY error */
+                return NULL;
+            }
+        }
+    }
+
+    was_empty = (service_list == NULL);
+
+    dbus_service = msgport_dbus_service_new (owner, port_name, is_trusted);
+    /* cache newly created service */
+    g_hash_table_insert (manager->priv->path_service_map, 
+        (gpointer)msgport_dbus_service_get_object_path (dbus_service),
+        (gpointer)dbus_service);
+
+    /* append to list of services */
+    service_list = g_list_append (service_list, dbus_service);
+    if (was_empty) {
+        g_hash_table_insert (manager->priv->owner_service_map, owner, service_list);
+    }
+
+    return dbus_service;
+}
+
+MsgPortDbusService *
+msgport_manager_get_service (
+    MsgPortManager      *manager,
+    MsgPortDbusManager  *owner,
+    const gchar         *remote_port_name,
+    gboolean             is_trusted,
+    GError             **error)
+{
+    GList *service_list = NULL;
+    g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), NULL);
+
+    service_list = g_hash_table_lookup (manager->priv->owner_service_map, owner);
+    while (service_list != NULL) {
+        MsgPortDbusService *dbus_service = MSGPORT_DBUS_SERVICE (service_list->data);
+
+        if ( !g_strcmp0 (remote_port_name, msgport_dbus_service_get_port_name (dbus_service)) && 
+             is_trusted == msgport_dbus_service_get_is_trusted (dbus_service)) {
+            return dbus_service ;
+        }
+
+        service_list = service_list->next;
+    }
+
+    /* FIXME: return ENOTFOUND */
+    return NULL;
+}
+
+MsgPortDbusService *
+msgport_manager_get_service_by_path (
+    MsgPortManager *manager,
+    const gchar    *service_object_path,
+    GError        **error)
+{
+    MsgPortDbusService *dbus_service = NULL;
+    g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), NULL);
+
+    dbus_service = g_hash_table_lookup (manager->priv->path_service_map, service_object_path);
+
+    if (!dbus_service) {
+        /* FIXME: return ENOTFOUND error */
+    }
+
+    return dbus_service;
+}
+
+static void
+_unref_dbus_manager_cb (gpointer data, gpointer user_data)
+{
+    MsgPortDbusService *service = MSGPORT_DBUS_SERVICE (data);
+    MsgPortManager *manager = MSGPORT_MANAGER (user_data);
+    const gchar *object_path = NULL;
+    
+    g_assert (manager);
+    g_assert (service);
+    object_path = msgport_dbus_service_get_object_path (service);
+
+    DBG ("Unregistering service %s:%s(%s)", 
+        msgport_dbus_manager_get_app_id (msgport_dbus_service_get_owner (service)),
+        msgport_dbus_service_get_port_name (service),
+        object_path);
+    /* remove the service from object_path:service map,
+     * as its being unregisted */
+    g_hash_table_remove (manager->priv->path_service_map, object_path);
+}
+
+/*
+ * unregister all the services owned by a client
+ */
+gboolean
+msgport_manager_unregister_services (
+    MsgPortManager     *manager,
+    MsgPortDbusManager *owner)
+{
+DBG("{");
+    GList *service_list = NULL;
+    g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), FALSE);
+
+    /* fetch sevice list owned by the client */
+    service_list = g_hash_table_lookup (manager->priv->owner_service_map, owner);
+    if (!service_list) {
+        DBG("   No service found");
+        return FALSE;
+    }
+
+    /* remove all the service from the list */
+    g_list_foreach (service_list, _unref_dbus_manager_cb, manager);
+    g_hash_table_remove (manager->priv->owner_service_map, owner);
+DBG("}");
+    return TRUE;
+}
+
+/*
+ * unregister a signle service for given object path
+ */
+gboolean
+msgport_manager_unregister_service (
+    MsgPortManager *manager,
+    const gchar *service_object_path)
+{
+    MsgPortDbusService *service = NULL;
+    MsgPortDbusManager *owner = NULL;
+    GList *service_list = NULL, *new_service_list = NULL;
+    g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), FALSE);
+DBG ("{");
+    service = g_hash_table_lookup (manager->priv->path_service_map, service_object_path);
+
+    if (!service) return FALSE;
+
+    owner = msgport_dbus_service_get_owner (service);
+
+    service_list = g_hash_table_lookup (manager->priv->owner_service_map, owner);
+
+    /* remove service from services list owned by the 'owner'*/
+    new_service_list = g_list_remove (service_list, service);
+    if (new_service_list != service_list) {
+        g_hash_table_steal (manager->priv->owner_service_map, owner);
+        /* update the new list on this owner */
+        g_hash_table_insert (manager->priv->owner_service_map, owner, new_service_list);
+    }
+
+    /* remove from the object_path:servcie table */
+    g_hash_table_remove (manager->priv->path_service_map, service_object_path);
+DBG("}");
+    return TRUE;
+}
+
diff --git a/daemon/manager.h b/daemon/manager.h
new file mode 100644 (file)
index 0000000..28c6610
--- /dev/null
@@ -0,0 +1,88 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _MSGPORT_MANAGER_H
+#define _MSGPORT_MANAGER_H
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define MSGPORT_TYPE_MANAGER (msgport_manager_get_type())
+#define MSGPORT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MSGPORT_TYPE_MANAGER, MsgPortManager))
+#define MSGPORT_MANAGER_CLASS(obj)  (G_TYPE_CHECK_CLASS_CAST((kls), MSGPORT_TYPE_MANAGER, MsgPortManagerClass))
+#define MSGPORT_IS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MSGPORT_TYPE_MANAGER))
+#define MSGPORT_IS_MANAGER_CLASS(kls) (G_TYPE_CHECK_CLASS_TYPE((kls), MSGPORT_TYPE_MANAGER))
+
+typedef struct _MsgPortManager MsgPortManager;
+typedef struct _MsgPortManagerClass MsgPortManagerClass;
+typedef struct _MsgPortManagerPrivate MsgPortManagerPrivate;
+
+typedef struct _MsgPortDbusManager MsgPortDbusManager;
+typedef struct _MsgPortDbusService MsgPortDbusService;
+
+struct _MsgPortManager
+{
+    GObject parent;
+
+    /* private */
+    MsgPortManagerPrivate *priv;
+};
+
+struct _MsgPortManagerClass
+{
+    GObjectClass parenet_class;
+};
+
+GType msgport_manager_get_type (void);
+
+MsgPortManager *
+msgport_manager_new ();
+
+MsgPortDbusService *
+msgport_manager_register_service (
+    MsgPortManager     *manager,
+    MsgPortDbusManager *owner,
+    const gchar        *port_name,
+    gboolean            is_trusted,
+    GError            **error_out);
+
+MsgPortDbusService *
+msgport_manager_get_service (
+    MsgPortManager     *manager,
+    MsgPortDbusManager *owner,
+    const gchar        *remote_port_name,
+    gboolean            is_trusted,
+    GError            **error_out);
+
+MsgPortDbusService *
+msgport_manager_get_service_by_path (
+    MsgPortManager *manager,
+    const gchar    *object_path,
+    GError        **error_out);
+
+G_END_DECLS
+
+#endif /* _MSGPORT_MANAER_H */
+
diff --git a/daemon/org.tizen.messageport.Manager.xml b/daemon/org.tizen.messageport.Manager.xml
new file mode 100644 (file)
index 0000000..c3027da
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+  <interface name="org.tizen.messageport.Manager">
+    <method name="registerService">
+      <arg name="port" type="s" direction="in"/>
+      <arg name="is_trusted" type="b" direction="in"/>
+      <arg name="object_path" type="o" direction="out"/>
+    </method>
+    <method name="checkForRemoteService">
+      <arg name="remote_app_id" type="s" direction="in"/>
+      <arg name="remote_port" type="s" direction="in"/>
+      <arg name="is_trusted" type="b" direction="in"/>
+      <arg name="remote_port_path" type="o" direction="out"/>
+    </method>
+    <method name="sendMessage">
+      <arg name="remote_port_path" type="o" direction="in"/>
+      <arg name="data" type="a{sv}" direction="in"/>
+    </method>
+  </interface>
+</node>
diff --git a/daemon/org.tizen.messageport.Service.xml b/daemon/org.tizen.messageport.Service.xml
new file mode 100644 (file)
index 0000000..406af98
--- /dev/null
@@ -0,0 +1,17 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+  <interface name="org.tizen.messageport.Service">
+    <method name="getProperties">
+      <arg name="properties" type="a{sv}" direction="out"/>
+    </method>
+    <method name="unregister"/>
+    <method name="sendMessage">
+      <arg name="remote_service_path" type="o" direction="in"/>
+      <arg name="data" type="a{sv}" direction="in"/>
+    </method>
+    <signal name="onMessage">
+      <arg name="data" type="a{sv}"/>
+      <arg name="remote_service_path" type="o"/>
+    </signal>
+  </interface>
+</node>
diff --git a/daemon/server-socket.c b/daemon/server-socket.c
new file mode 100644 (file)
index 0000000..82e22fe
--- /dev/null
@@ -0,0 +1,205 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "server-socket.h"
+#include "libwebsockets.h"
+#include "priv-libwebsockets.h"
+
+G_DEFINE_TYPE (MsgPortServerSocket, msgport_server_socket, G_TYPE_OBJECT)
+
+#define MSGPORT_SERVER_SOCKET_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSGPORT_TYPE_SERVER_SOCKET, MsgPortServerSocketPrivate)
+
+struct _MsgPortServerSocketPrivate {
+    GMainLoop *ml;
+    struct libwebsocket_context *context;
+};
+
+
+static void
+_server_socket_finalize (GObject *self)
+{
+    MsgPortServerSocket *socket = MSGPORT_SERVER_SOCKET (self);
+
+    if (socket->priv->context) {
+        libwebsocket_context_destroy (socket->priv->context);
+        socket->priv->context = NULL;
+    }
+
+    G_OBJECT_CLASS (msgport_server_socket_parent_class)->finalize (self);
+}
+
+static void
+_server_socket_dispose (GObject *self)
+{
+    G_OBJECT_CLASS (msgport_server_socket_parent_class)->dispose (self);
+}
+
+static void
+msgport_server_socket_init (MsgPortServerSocket *self)
+{
+    MsgPortServerSocketPrivate *priv = MSGPORT_SERVER_SOCKET_GET_PRIV (self);
+
+    self->priv = priv;
+}
+
+static void
+msgport_server_socket_class_init (MsgPortServerSocketClass *klass)
+{
+    GObjectClass *gklass = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private (klass, sizeof(MsgPortServerSocketPrivate));
+
+    gklass->finalize = _server_socket_finalize;
+    gklass->dispose = _server_socket_dispose;
+}
+
+struct MsgPortCallbackData {
+    MsgPortServerSocket *self;
+    struct libwebsocket_context *wsctx;
+};
+
+static gboolean 
+_fd_event (
+    GIOChannel *source,
+    GIOCondition condition,
+    gpointer data)
+{
+    struct pollfd pollfd ;
+    static libwebsocket_context *wsctx = (struct libwebsocket_context *)data;
+
+    pollfd.fd = g_io_channel_get_unix_fd (source);
+    pollfd.events = condition; // FIXME: convert to poll events ??
+    pollfd.revents = ; // FIXME: what it should ?? 
+
+    libwebsocket_service_fd (wsctx, pollfd);
+};
+
+static void
+_add_fd_to_main_loop (
+    MsgPortServerSocket *socket,
+    int fd,
+    int events)
+{
+    if (socket->priv->ml) {
+        GIOChannel *io = g_io_channel_unix_new (fd);
+        g_io_add_watch (io, events, _fd_event, socket);
+    }
+
+
+static int
+_http_callback (
+    struct libwebsocket_context       *context,
+    struct libwebsocket               *wsi,
+    enum libwebsocket_callback_reasons reason,
+    void  *user,
+    void  *in, 
+    size_t len)
+{
+    switch (reason) {
+        case LWS_CALLBACK_HTTP:
+        /* client connected */
+        break;
+
+        default:
+        g_print ("%s reason %d\n", __FUNCTION_NAME__, reason);
+    }
+
+    return 0;
+}
+
+static int
+_msgport_callback (
+    struct libwebsocket_context       *context,
+    struct libwebsocket               *wsi,
+    enum libwebsocket_callback_reasons reason,
+    void  *user,
+    void  *in, 
+    size_t len)
+{
+    switch (reason) {
+        case LWS_CALLBACK_ESTABLISHED:
+        break;
+
+        default;
+        g_print ("%s reason %d\n", __FUNCTION_NAME__, reason);
+    }
+
+    return 0;
+}
+
+
+
+MsgPortServerSocket *
+msgport_server_socket_new (GMainLoop *ml)
+{
+    struct lws_context_creation_info info;
+    static struct libwebsocket_protocols protocols[] = {
+        /* first protocol must always be HTTP handler */
+        { "http-only",   _http_callback,    sizeof (void *), 0, },
+        { "messge-port", _msgport_callback, sizeof (void *), 0, },
+        { NULL, NULL, 0, 0 }
+    };
+
+    MsgPortServerSocket *socket = NULL;
+
+    socket = MSGPORT_SERVER_SOCKET (g_object_new (MSGPORT_TYPE_SERVER_SOCKET, NULL));
+    if (!socket) return NULL;
+
+    info.port = 9000;
+    info.iface = NULL;
+    info.protocols = protocols;
+    info.extensions = libwebsocket_get_internal_extensions();
+    info.ssl_cert_filepath = NULL;
+    info.ssl_private_key_filepath = NULL;
+    info.ssl_cipher_list = NULL;
+    /* FIXME: set socket permessions */
+    info.gid = -1; info.uid = -1;
+    info.options = 0;
+    info.user = socket;
+    info.ka_time = 0;
+    info.ka_probes = 0;
+    info.ka_interval = 0;
+
+    socket->priv->context = libwebsocket_create_context (&info);
+    socket->priv->ml = g_main_loop_ref (ml);
+}
+
+gboolean
+msgport_server_socket_start (MsgPortServerSocket *socket)
+{
+    g_return_val_if_fail (socket && MSGPORT_IS_SERVER_SOCKET (socket), FALSE);
+
+    if (!socket->priv->ml) {
+        /* run libwesocket loop if no super mainloop */
+        while (1) {
+            libwebsocket_service (socket->priv.>context, 50);
+        }
+    }
+    else {
+        /* integrate to super mainloop */
+    }
+
+    return TRUE;
+}
+
diff --git a/daemon/server-socket.h b/daemon/server-socket.h
new file mode 100644 (file)
index 0000000..bef5542
--- /dev/null
@@ -0,0 +1,66 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _MSGPORT_SERVER_SOCKET_H
+#define _MSGPORT_SERVER_SOCKET_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MSGPORT_TYPE_SERVER_SOCKET (msgport_server_socket_get_type())
+#define MSGPORT_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MSGPORT_TYPE_SERVER_SOCKET, MsgPortServerSocket))
+#define MSGPORT_SERVER_SOCKET_CLASS(obj)  (G_TYPE_CHECK_CLASS_CAST((kls), MSGPORT_TYPE_SERVER_SOCKET, MsgPortServerSocketClass))
+#define MSGPORT_IS_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MSGPORT_TYPE_SERVER_SOCKET))
+#define MSGPORT_IS_SERVER_SOCKET_CLASS(kls) (G_TYPE_CHECK_CLASS_TYPE((kls), MSGPORT_TYPE_SERVER_SOCKET))
+
+typedef struct _MsgPortServerSocket MsgPortServerSocket;
+typedef struct _MsgPortServerSocketClass MsgPortServerSocketClass;
+typedef struct _MsgPortServerSocketPrivate MsgPortServerSocketPrivate;
+
+struct _MsgPortServerSocket
+{
+    GObject parent;
+
+    /* private */
+    MsgPortServerSocketPrivate *priv;
+};
+
+struct _MsgPortServerSocketClass
+{
+    GObjectClass parenet_class;
+};
+
+GType msgport_server_socket_get_type (void);
+
+MsgPortServerSocket *
+msgport_server_socket_new ();
+
+gboolean
+msgport_server_socket_start ();
+
+G_END_DECLS
+
+#endif /* _MSGPORT_SERVER_SOCKET_H */
+
diff --git a/daemon/service.c b/daemon/service.c
new file mode 100644 (file)
index 0000000..2c88a48
--- /dev/null
@@ -0,0 +1,138 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "service.h"
+#include "common/log.h"
+
+G_DEFINE_TYPE (MsgPortService, msgport_service, G_TYPE_OBJECT)
+
+#define MSGPORT_SERVICE_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSGPORT_TYPE_SERVICE, MsgPortServicePrivate)
+
+struct _MsgPortServicePrivate {
+    gchar           *app_id;
+    gchar           *port_name;
+    gboolean         is_trusted;
+};
+
+static void
+_service_finalize (GObject *self)
+{
+    MsgPortService *service = MSGPORT_SERVICE (self);
+
+    g_free (service->priv->app_id);
+    g_free (service->priv->port_name);
+
+    G_OBJECT_CLASS (msgport_service_parent_class)->finalize (self);
+}
+
+static void
+_service_dispose (GObject *self)
+{
+    //MsgPortService *service = MSGPORT_SERVICE (self);
+
+    G_OBJECT_CLASS (msgport_service_parent_class)->dispose (self);
+}
+
+static void
+msgport_service_init (MsgPortService *self)
+{
+    MsgPortServicePrivate *priv = MSGPORT_SERVICE_GET_PRIV (self);
+
+    priv->app_id = NULL;
+    priv->port_name = NULL;
+    priv->is_trusted = FALSE;
+
+    self->priv = priv;
+}
+
+static void
+msgport_service_class_init (MsgPortServiceClass *klass)
+{
+    GObjectClass *gklass = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private (klass, sizeof(MsgPortServicePrivate));
+
+    gklass->finalize = _service_finalize;
+    gklass->dispose = _service_dispose;
+}
+
+MsgPortService *
+msgport_service_new (const gchar *app_id,
+                      const gchar *port,
+                      gboolean     is_trusted)
+{
+    MsgPortService *service = NULL;
+
+    service= MSGPORT_SERVICE (g_object_new (MSGPORT_TYPE_SERVICE, NULL));
+    if (!service) return NULL;
+
+    service->priv->app_id = g_strdup (app_id);
+    service->priv->port_name = g_strdup (port);
+    service->priv->is_trusted = is_trusted;
+
+    return service;
+}
+
+const gchar *
+msgport_service_get_app_id (MsgPortService *service)
+{
+    g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), NULL);
+    
+    return (const gchar *)service->priv->app_id;
+}
+
+const gchar *
+msgport_service_get_port_name (MsgPortService *service)
+{
+    g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), NULL);
+
+    return (const gchar *)service->priv->port_name;
+}
+
+gboolean
+msgport_service_get_is_trusted (MsgPortService *service)
+{
+    g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), FALSE);
+
+    return service->priv->is_trusted;
+}
+
+GVariant *
+msgport_service_to_variant (MsgPortService *service)
+{
+    GVariantBuilder v_builder;
+    g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), NULL);
+
+    g_variant_builder_init (&v_builder, G_VARIANT_TYPE_VARDICT);
+
+    g_variant_builder_add (&v_builder, "{sv}", "AappId",
+            g_variant_new_string (service->priv->app_id));
+    g_variant_builder_add (&v_builder, "{sv}", "PortName",
+            g_variant_new_string (service->priv->port_name));
+    g_variant_builder_add (&v_builder, "{sv}", "IsTrusted",
+            g_variant_new_boolean (service->priv->is_trusted));
+
+    return g_variant_builder_end (&v_builder);
+}
+
diff --git a/daemon/service.h b/daemon/service.h
new file mode 100644 (file)
index 0000000..87e0d9c
--- /dev/null
@@ -0,0 +1,76 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _MSGPORT_SERVICE_H
+#define _MSGPORT_SERVICE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MSGPORT_TYPE_SERVICE (msgport_service_get_type())
+#define MSGPORT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MSGPORT_TYPE_SERVICE, MsgPortService))
+#define MSGPORT_SERVICE_CLASS(obj)  (G_TYPE_CHECK_CLASS_CAST((kls), MSGPORT_TYPE_SERVICE, MsgPortServiceClass))
+#define MSGPORT_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MSGPORT_TYPE_SERVICE))
+#define MSGPORT_IS_SERVICE_CLASS(kls) (G_TYPE_CHECK_CLASS_TYPE((kls), MSGPORT_TYPE_SERVICE))
+
+typedef struct _MsgPortService MsgPortService;
+typedef struct _MsgPortServiceClass MsgPortServiceClass;
+typedef struct _MsgPortServicePrivate MsgPortServicePrivate;
+
+struct _MsgPortService
+{
+    GObject parent;
+
+    /* private */
+    MsgPortServicePrivate *priv;
+};
+
+struct _MsgPortServiceClass
+{
+    GObjectClass parenet_class;
+};
+
+GType msgport_service_get_type (void);
+
+MsgPortService *
+msgport_service_new (const gchar *app_id,
+                     const gchar *port,
+                     gboolean     is_trusted);
+
+const gchar *
+msgport_service_get_app_id (MsgPortService *service);
+
+const gchar *
+msgport_service_get_port_name (MsgPortService *service);
+
+gboolean
+msgport_service_get_is_trusted (MsgPortService *service);
+
+GVariant *
+msgport_service_to_variant (MsgPortService *service);
+
+G_END_DECLS
+
+#endif /* _MSGPORT_SERVICE_H */
+
diff --git a/lib/message-port.c b/lib/message-port.c
new file mode 100644 (file)
index 0000000..c2903ce
--- /dev/null
@@ -0,0 +1,100 @@
+#include "message-port.h"
+
+static int
+_messageport_register_port (const char *name, gboolean is_trusted, messageport_message_cb cb)
+{
+    (void) name;
+    (void) is_trusted;
+    (void) cb;
+
+    return MESSAGEPORT_ERROR_NONE;
+}
+
+static int
+_messageport_check_remote_port (const char *app_id, const char *port, gboolean is_trusted, gboolean *exists)
+{
+    (void) app_id;
+    (void) port;
+    (void) is_trusted;
+
+    if (exists) *exists = FALSE;
+
+    return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
+}
+
+static int
+_messageport_send_message (const char *app_id, const char *port, gboolean is_trusted, bundle *message)
+{
+    (void) app_id;
+    (void) port;
+    (void) is_trusted;
+    (void) message;
+
+    return MESSAGEPORT_ERROR_NONE;
+}
+
+static int
+_messageport_get_port_name (int port_id, gboolean is_trusted, gchar **name_out)
+{
+    (void) port_id;
+    (void) is_trusted;
+
+    if (name_out) **name_out = "";
+
+    return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
+}
+
+/*
+ * API
+ */
+
+int messageport_register_local_port(const char* local_port, messageport_message_cb callback)
+{
+    return _messageport_register_port (local_port, FALSE, callback);
+}
+
+int messageport_register_trusted_local_port (const char *local_port, messageport_message_cb callback)
+{
+    return _messageport_register_port (local_port, TRUE, callback);
+}
+
+int messageport_check_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
+{
+    return _messageport_check_remote_port (remote_app_id, port_name, FALSE, exists);
+}
+
+int messageport_check_trusted_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
+{
+    return _messageport_check_remote_port (remote_app_id, port_name, TRUE, exists);
+}
+
+int messageport_send_message (const char* remote_app_id, const char* remote_port, bundle* message)
+{
+    return _messageport_send_message (remote_app_id, remote_port, FALSE, message);
+}
+
+int messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message)
+{
+    return _messageport_send_message (remote_app_id, remote_port, TRUE, message);
+}
+
+int messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data)
+{
+    return _messageport_send_message (remote_app_id, remote_port, FALSE, data);
+}
+
+int messageport_send_bidirectional_trusted_message (int id, const char *remote_app_id, const char *remote_port, bundle *data)
+{
+    return _messageport_send_message (remote_app_id, remote_port, TRUE, data);
+}
+
+int messageport_get_local_port_name(int id, char **name)
+{
+    return _messageport_get_port_name (id, FALSE, name);
+}
+
+int messageport_check_trusted_local_port (int id, char **name)
+{
+    return _messageport_get_port_name (id, TRUE, name);
+}
+
diff --git a/lib/message-port.h b/lib/message-port.h
new file mode 100644 (file)
index 0000000..8d7bacc
--- /dev/null
@@ -0,0 +1,232 @@
+#ifndef __MESSAGE_PORT_H
+#define __MESSAGE_PORT_H
+
+#ifdef __GNUC__
+#   ifndef EXPORT_API
+#       define EXPORT_API __attribute__((visibility("default")))
+#   endif
+#else
+#   define EXPORT_API
+#endif
+
+#include <bundle.h>
+
+G_BEGIN_DECLS
+
+/**
+ * @brief Enumerations of error code for Application.
+ */
+typedef enum
+{
+    MESSAGEPORT_ERROR_NONE = 0, /**< Successful */
+    MESSAGEPORT_ERROR_IO_ERROR = -1,        /**< Internal I/O error */
+    MESSAGEPORT_ERROR_OUT_OF_MEMORY = -2,       /**< Out of memory */
+    MESSAGEPORT_ERROR_INVALID_PARAMETER = -3,   /**< Invalid parameter */
+    MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND = -4,       /**< The message port of the remote application is not found */
+    MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH = -5,   /**< The remote application is not signed with the same certificate */
+    MESSAGEPORT_ERROR_MAX_EXCEEDED = -6,    /**< The size of message has exceeded the maximum limit */
+} messageport_error_e;
+
+/**
+ * @brief   Called when a message is received from the remote application.
+ *
+ * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
+ * @param [in] remote_app_id The ID of the remote application which has sent this message
+ * @param [in] remote_port The name of the remote message port
+ * @param [in] trusted_message @c true if the trusted remote message port is ready to receive the response data
+ * @param [in] data the data passed from the remote application
+ * @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, bool trusted_message, bundle* data);
+
+/**
+ * @brief Registers the local message port. @n
+ * If the message port name is already registered, the previous message port id returns and the callback function is changed.
+ *
+ * @param [in] local_port the name of the local message port
+ * @param [in] callback The callback function to be called when a message is received
+ * @return A message port id on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ */
+EXPORT_API int messageport_register_local_port(const char* local_port, messageport_message_cb callback);
+
+/**
+ * @brief Registers the trusted local message port. @n
+ * If the message port name is already registered, the previous message port id returns and the callback function is changed. @n
+ * This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
+ *
+ * @param [in] local_port the name of the local message port
+ * @param [in] callback The callback function to be called when a message is received
+ * @return A message port id on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ */
+EXPORT_API int messageport_register_trusted_local_port(const char* local_port, messageport_message_cb callback);
+
+/**
+ * @brief Checks if the message port of a remote application is registered.
+ *
+ * @param [in] remote_app_id The ID of the remote application
+ * @param [in] remote_port the name of the remote message port
+ * @param [out] exist @c true if the message port of the remote application exists, otherwise @c false
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ */
+EXPORT_API int 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.
+ *
+ * @param [in] remote_app_id The ID of the remote application
+ * @param [in] remote_port the name of the remote message port
+ * @param [out] exist @c true if the message port of the remote application exists, otherwise @c false
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ */
+EXPORT_API int 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.
+ *
+ * @param [in] remote_app_id The ID of the remote application
+ * @param [in] remote_port the name of the remote message port
+ * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
+ * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ *
+ * @code
+ * #include <message-port.h>
+ *
+ * bundle *b = bundle_create();
+ * bundle_add(b, "key1", "value1");
+ * bundle_add(b, "key2", "value2");
+ *
+ * int ret = messageport_send_message("0123456789.BasicApp", "BasicAppPort", b);
+ *
+ * bundle_free(b);
+ * @endcode
+ */
+EXPORT_API int messageport_send_message(const char* remote_app_id, const char* remote_port, bundle* message);
+
+/**
+ * @brief Sends a trusted message to the message port of a remote application. @n
+ *  This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
+ *
+ * @param [in] remote_app_id The ID of the remote application
+ * @param [in] remote_port the name of the remote message port
+ * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
+ * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
+ * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ */
+EXPORT_API int messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message);
+
+/**
+ * @brief Sends a message to the message port of a remote application. This method is used for the bidirectional communication.
+ *
+ * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
+ * @param [in] remote_app_id The ID of the remote application
+ * @param [in] remote_port the name of the remote message port
+ * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
+ * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ *
+ * @code
+ * #include <message-port.h>
+ *
+ * static void
+ * OnMessageReceived(int id, const char* remote_app_id, const char* remote_port, bool trusted_port, bundle* data)
+ * {
+ * }
+ *
+ * int main(int argc, char *argv[])
+ * {
+ *   bundle *b = bundle_create();
+ *   bundle_add(b, "key1", "value1");
+ *   bundle_add(b, "key2", "value2");
+ *
+ *   int id = messageport_register_local_port("HelloPort", OnMessageReceived);
+ *
+ *   int ret = messageport_send_bidirectional_message(id, "0123456789.BasicApp", "BasicAppPort", b);
+ *
+ *   bundle_free(b);
+ * }
+ */
+EXPORT_API int messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
+
+/**
+ * @brief Sends a trusted message to the message port of a remote application. This method is used for the bidirectional communication.
+ *  This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
+ *
+ * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
+ * @param [in] remote_app_id The ID of the remote application
+ * @param [in] remote_port the name of the remote message port
+ * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
+ * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
+ * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
+ * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ */
+EXPORT_API int messageport_send_bidirectional_trusted_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
+
+/**
+ * @brief Gets the name of the local message port.
+ *
+ * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
+ * @param [out] name The name of the local message port
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @remarks @a name must be released with free() by you
+ */
+EXPORT_API int messageport_get_local_port_name(int id, char **name);
+
+/**
+ * @brief Checks if the local message port is trusted.
+ *
+ * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
+ * @param [out] @c true if the local message port is trusted
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ */
+EXPORT_API int messageport_check_trusted_local_port(int id, bool *trusted);
+
+
+G_EDN_DECLS
+
+#endif /* __MESSAGE_PORT_H */
diff --git a/lib/msgport-manager.c b/lib/msgport-manager.c
new file mode 100644 (file)
index 0000000..c4783a1
--- /dev/null
@@ -0,0 +1,118 @@
+#include "msgport-manager.h"
+#include "message-port.h"
+#include "common/log.h"
+#include "dbus-manager-glue.h"
+#include <gio/gio.h>
+
+struct _MsgPortManager
+{
+    MsgPortGlueManagerPorxy *proxy;
+    GHashTable *services; /* {gchar*:MsgPortService*} */
+    GList *local_service_list;
+    int n_local_services;
+};
+
+static MsgPortManager __manager;
+
+MsgPortManager * msgport_manager_new ()
+{
+    GError          *error = NULL;
+    GDBusConnection *connection = NULL;
+    MsgPortManager  *manager = g_slice_new0(MsgPortManager);
+    gchar           *bus_address = g_strdup_printf (MESSAGEPORT_BUS_ADDRESS, g_get_user_runtime_dir());
+
+    if (!manager) {
+        return NULL;
+    }
+
+    connection = g_dbus_connection_new_for_address_sync (bus_address,
+                                G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
+                                NULL, NULL, &error);
+
+    if (error) {
+        ERR ("Unable to get bus connection for address %s: %s", bus_address, error->message);
+        g_error_free (error);
+        goto fail;
+    }
+
+    manager->services = g_hash_table_new_full (g_str_hash, g_str_equal,
+                               g_free, (GDestroyNotify)g_object_unref);
+    manager->local_servcie_list = NULL;
+    manager->n_local_services = 0;
+    manager->proxy = msgport_dbus_glue_manager_proxy_new_sync (
+            connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, "/", NULL, &error);
+
+    if (!manager->proxy) {
+        ERR ("Unable to get manager proxy : %s", error->message);
+        g_error_free (error);
+        goto fail;
+    }
+
+    return manager;
+
+fail:
+    if (manager) msgport_manager_unref (manager);
+    return NULL;
+}
+
+MsgPortManager * msgport_get_manager () {
+    if (!__manager) 
+        __manager = magport_manager_new ();
+
+    return __manager;
+}
+
+int msgport_manager_register_service (MsgPortManager *manger, const gchar *port_name, gboolean is_trusted)
+{
+    GError *error = NULL;
+    g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), MESSAGEPORT_ERROR_IO_ERROR);
+
+    if (!port_name) return MESSAGEPORT_ERROR_INVALID_PARAMETER;
+
+    msgport_dbus_glue_manager_call_register_service_sync (manager->proxy,
+            port_name, is_trusted, &object_path, NULL, &error);
+
+    if (error) {
+        WARN ("unable to register service (%s): %s", port_name, error->message);
+        g_error_free (error);
+        return MESSAGEPORT_ERROR_IO_ERROR;
+    }
+
+    MsgPortService *service = msgport_service_new (
+            g_dbus_proxy_get_connection (G_DBUS_PROXY(manager->proxy)),
+            object_path, &error);
+    if (!service) {
+        WARN ("unable to get service proxy for path %s: %s", object_path, error->message);
+        g_error_free (error);
+        g_free (object_path);
+        return MESSAGEPORT_ERROR_IO_ERROR;
+    }
+
+    g_hash_table_insert (manager->services, object_path, service);
+    manager->local_service_list = g_list_append (manager->local_service_list, object_path);
+    manager->n_local_services++;
+
+    return manager->n_local_services;
+}
+
+MsgPortService *
+msgport_service_new (GDBusConnection *connection, const gchar *path, GError **error)
+{
+    MsgPortService *service = g_object_new (MSGPORT_TYPE_SERVICE, NULL);
+
+    if (!service) {
+        /* FIXME: return no merory error */
+        return NULL
+    }
+
+    service->proxy = msgport_dbus_glue_service_proxy_new_sync (connection,
+                g_dbus_proxy_get_connection (G_DBUS_PROXY(manager->proxy)),
+                G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, object_path, NULL, error);
+    if (!service->proxy) {
+        g_object_unref (service);
+        return NULL;
+    }
+
+    return service;
+}
+
diff --git a/lib/msgport-manager.h b/lib/msgport-manager.h
new file mode 100644 (file)
index 0000000..9125797
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __MSGPORT_MANAGER_H
+#define __MSGPORT_MANAGER_H
+
+typedef _MsgPortManager MsgPortManager;
+typedef _MsgPortService MsgPortService;
+
+MsgPortManager *
+msgport_get_manager ();
+
+int
+msgport_manager_register_port (MsgPortManager *manager, const gchar *port_name, gboolean is_trusted);
+
+int
+msgport_manager_unregister_port (MsgPortManager *manager, int port_id);
+
+int
+msgport_manager_get_port_id (MsgPortManager *manager, const gchar *remote_app_id, const gchar *port_name, gboolean is_trusted);
+
+
+
+#define /* __MSGPORT_MANAGER_PROXY_H */