~unity-api-team/unity-scopes-api/child-scopes-option

« back to all changes in this revision

Viewing changes to src/internal/RegistryMain.cpp

  • Committer: Michi Henning
  • Date: 2013-11-19 02:51:46 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: michi.henning@canonical.com-20131119025146-kglcalpphl4ozzk7
Fixed scoperegistry to use new scoperunner and to figure out which scopes to run from config files.
Still to do:
- deal with overrides and OEM scopes, particularly the grouping aspect.
- SignalThread needs to invoke a callback for clean shut-down on receipt of SIGINT.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 Canonical Ltd
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Michi Henning <michi.henning@canonical.com>
17
 
 */
18
 
 
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>
25
 
 
26
 
#include <iostream>
27
 
 
28
 
using namespace std;
29
 
using namespace unity::api::scopes;
30
 
using namespace unity::api::scopes::internal;
31
 
 
32
 
int
33
 
main(int, char*[])
34
 
{
35
 
    int exit_status = 0;
36
 
 
37
 
    try
38
 
    {
39
 
        RuntimeImpl::UPtr runtime = RuntimeImpl::create("Registry", "RegistryMain.ini");
40
 
 
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();
46
 
 
47
 
        MiddlewareBase::SPtr middleware = runtime->factory()->create(identity, mw_kind, mw_configfile);
48
 
 
49
 
        // Instantiate the registry implementation.
50
 
        RegistryObject::SPtr registry(make_shared<RegistryObject>());
51
 
 
52
 
        // TODO: populate registry here
53
 
 
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);
66
 
 
67
 
        // END TODO temporary hack
68
 
 
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);
72
 
 
73
 
        // Wait until we are done.
74
 
        middleware->wait_for_shutdown();
75
 
    }
76
 
    catch (unity::Exception const& e)
77
 
    {
78
 
        cerr << e.to_string() << endl;
79
 
        exit_status = 1;
80
 
    }
81
 
 
82
 
    return exit_status;
83
 
}