2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
23 #include <dpl/assert.h>
24 #include <dpl/log/log.h>
25 #include <dpl/dbus/server.h>
30 ServerPtr Server::create(const std::string& address)
34 int flags = G_DBUS_SERVER_FLAGS_NONE |
35 G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
37 gchar* serverId = g_dbus_generate_guid();
39 GDBusServer* server = g_dbus_server_new_sync(
41 static_cast<GDBusServerFlags>(flags),
53 message = error->message;
57 ThrowMsg(DPL::Exception, "Error on server creation: " << message);
60 return ServerPtr(new Server(server));
63 Server::Server(GDBusServer* server)
70 if (g_dbus_server_is_active(m_server))
74 g_object_unref(m_server);
79 Assert(!g_dbus_server_is_active(m_server) && "Server already started.");
81 g_dbus_server_start(m_server);
83 g_signal_connect(m_server,
85 G_CALLBACK(onNewConnection),
88 LogInfo("Server started at: "
89 << g_dbus_server_get_client_address(m_server));
94 Assert(g_dbus_server_is_active(m_server) && "Server not started.");
96 g_dbus_server_stop(m_server);
99 gboolean Server::onNewConnection(GDBusServer* /*server*/,
100 GDBusConnection* connection,
103 Assert(NULL != data && "User data cannot be NULL.");
105 Server* self = static_cast<Server*>(data);
107 ServerEvents::NewConnectionEvent event(
108 ConnectionPtr(new Connection(connection)));
110 LogInfo("Emitting new connection event");
111 // TODO Blocking to allow object registration before any DBus messages are
113 self->DPL::Event::EventSupport<ServerEvents::NewConnectionEvent>::
114 EmitEvent(event, DPL::Event::EmitMode::Blocking);