2
* Copyright (C) 2013 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Michi Henning <michi.henning@canonical.com>
19
#include <scopes/internal/MiddlewareFactory.h>
20
#include <scopes/internal/RegistryConfig.h>
21
#include <scopes/internal/RegistryObject.h>
22
#include <scopes/internal/RuntimeConfig.h>
23
#include <scopes/internal/RuntimeImpl.h>
24
#include <unity/UnityExceptions.h>
29
using namespace unity::api::scopes;
30
using namespace unity::api::scopes::internal;
39
RuntimeImpl::UPtr runtime = RuntimeImpl::create("Registry", "RegistryMain.ini");
41
string identity = runtime->registry_identity();
42
RegistryConfig c(identity, runtime->registry_configfile());
43
string mw_kind = c.mw_kind();
44
string mw_endpoint = c.endpoint();
45
string mw_configfile = c.mw_configfile();
47
MiddlewareBase::SPtr middleware = runtime->factory()->create(identity, mw_kind, mw_configfile);
49
// Instantiate the registry implementation.
50
RegistryObject::SPtr registry(make_shared<RegistryObject>());
52
// TODO: populate registry here
54
// TODO: temporary hack for demonstration purposes. The actual scopes need to be retrieved from
55
// configuration instead.
56
auto proxy = middleware->create_scope_proxy("scope-A", "ipc://scope-A");
57
registry->add("scope-A", proxy);
58
proxy = middleware->create_scope_proxy("scope-B", "ipc://scope-B");
59
registry->add("scope-B", proxy);
60
proxy = middleware->create_scope_proxy("scope-C", "ipc://scope-C");
61
registry->add("scope-C", proxy);
62
proxy = middleware->create_scope_proxy("scope-D", "ipc://scope-D");
63
registry->add("scope-D", proxy);
64
proxy = middleware->create_scope_proxy("scope-slow", "ipc://scope-slow");
65
registry->add("scope-slow", proxy);
67
// END TODO temporary hack
69
// Add the registry implementation to the middleware. This causes
70
// incoming requests to be dispatched to the implementation.
71
middleware->add_registry_object(runtime->registry_identity(), registry);
73
// Wait until we are done.
74
middleware->wait_for_shutdown();
76
catch (unity::Exception const& e)
78
cerr << e.to_string() << endl;