Merge lp:~michihenning/unity-scopes-api/scope-metadata into lp:unity-scopes-api

Proposed by Michi Henning
Status: Merged
Approved by: Michal Hruby
Approved revision: 78
Merged at revision: 75
Proposed branch: lp:~michihenning/unity-scopes-api/scope-metadata
Merge into: lp:unity-scopes-api
Diff against target: 3520 lines (+1636/-438)
91 files modified
STRUCTS (+16/-3)
demo/CMakeLists.txt (+0/-1)
demo/Factory.ini.in (+0/-2)
demo/Zmq.ini.in (+1/-1)
demo/client.cpp (+43/-5)
demo/scopes/scope-A/scope-A.cpp (+0/-1)
demo/scopes/scope-A/scope-A.ini.in (+6/-0)
demo/scopes/scope-B/scope-B.cpp (+4/-4)
demo/scopes/scope-B/scope-B.ini.in (+2/-0)
demo/scopes/scope-C/scope-C.ini.in (+2/-0)
demo/scopes/scope-D/scope-D.ini.in (+2/-0)
demo/scopes/scope-N/scope-N.cpp (+0/-1)
demo/scopes/scope-N/scope-N.ini.in (+2/-0)
demo/scopes/scope-S/scope-S.cpp (+0/-1)
demo/scopes/scope-S/scope-S.ini.in (+2/-0)
include/scopes/ObjectProxy.h (+3/-0)
include/scopes/Registry.h (+19/-12)
include/scopes/ResultItem.h (+1/-1)
include/scopes/Runtime.h (+6/-6)
include/scopes/ScopeMetadata.h (+78/-0)
include/scopes/internal/ConfigBase.h (+2/-0)
include/scopes/internal/MWObjectProxy.h (+3/-2)
include/scopes/internal/MWRegistry.h (+3/-2)
include/scopes/internal/MiddlewareBase.h (+3/-0)
include/scopes/internal/MiddlewareFactory.h (+1/-1)
include/scopes/internal/MiddlewareFactoryConfig.h (+0/-60)
include/scopes/internal/ObjectProxyImpl.h (+6/-3)
include/scopes/internal/RegistryImpl.h (+3/-2)
include/scopes/internal/RegistryObject.h (+7/-9)
include/scopes/internal/RuntimeConfig.h (+1/-1)
include/scopes/internal/RuntimeImpl.h (+1/-1)
include/scopes/internal/ScopeConfig.h (+13/-1)
include/scopes/internal/ScopeMetadataImpl.h (+94/-0)
include/scopes/internal/zmq_middleware/RegistryI.h (+1/-1)
include/scopes/internal/zmq_middleware/RequestType.h (+1/-1)
include/scopes/internal/zmq_middleware/ZmqConfig.h (+1/-4)
include/scopes/internal/zmq_middleware/ZmqMiddleware.h (+2/-0)
include/scopes/internal/zmq_middleware/ZmqObjectProxy.h (+2/-32)
include/scopes/internal/zmq_middleware/ZmqRegistry.h (+2/-2)
scoperegistry/scoperegistry.cpp (+77/-18)
scoperunner/scoperunner.cpp (+1/-6)
src/CMakeLists.txt (+1/-0)
src/ObjectProxy.cpp (+12/-0)
src/ReceiverBase.cpp (+2/-1)
src/Registry.cpp (+8/-3)
src/Runtime.cpp (+0/-2)
src/ScopeMetadata.cpp (+123/-0)
src/internal/CMakeLists.txt (+1/-1)
src/internal/ConfigBase.cpp (+26/-9)
src/internal/MiddlewareFactory.cpp (+1/-12)
src/internal/ObjectProxyImpl.cpp (+10/-0)
src/internal/RegistryImpl.cpp (+17/-3)
src/internal/RegistryObject.cpp (+12/-11)
src/internal/ResultItemImpl.cpp (+3/-7)
src/internal/RuntimeConfig.cpp (+23/-16)
src/internal/RuntimeImpl.cpp (+1/-2)
src/internal/ScopeConfig.cpp (+91/-0)
src/internal/ScopeImpl.cpp (+1/-0)
src/internal/ScopeMetadataImpl.cpp (+325/-0)
src/internal/zmq_middleware/RegistryI.cpp (+18/-23)
src/internal/zmq_middleware/ZmqConfig.cpp (+10/-9)
src/internal/zmq_middleware/ZmqMiddleware.cpp (+14/-0)
src/internal/zmq_middleware/ZmqObject.cpp (+11/-0)
src/internal/zmq_middleware/ZmqRegistry.cpp (+29/-22)
src/internal/zmq_middleware/capnproto/Registry.capnp (+7/-7)
test/gtest/unity/api/scopes/ResultItem/ResultItem_test.cpp (+9/-0)
test/gtest/unity/api/scopes/Runtime/CMakeLists.txt (+0/-1)
test/gtest/unity/api/scopes/Runtime/Factory.ini.in (+0/-2)
test/gtest/unity/api/scopes/Variant/Variant_test.cpp (+3/-0)
test/gtest/unity/api/scopes/internal/CMakeLists.txt (+1/-1)
test/gtest/unity/api/scopes/internal/MiddlewareFactory/CMakeLists.txt (+0/-2)
test/gtest/unity/api/scopes/internal/MiddlewareFactory/Factory.ini.in (+0/-3)
test/gtest/unity/api/scopes/internal/MiddlewareFactory/MiddlewareFactory_test.cpp (+5/-22)
test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/CMakeLists.txt (+0/-6)
test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/Factory.ini.in (+0/-3)
test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/MiddlewareFactoryConfig_test.cpp (+0/-31)
test/gtest/unity/api/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp (+1/-1)
test/gtest/unity/api/scopes/internal/RuntimeImpl/CMakeLists.txt (+0/-1)
test/gtest/unity/api/scopes/internal/RuntimeImpl/Factory.ini.in (+0/-2)
test/gtest/unity/api/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp (+0/-6)
test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/CMakeLists.txt (+6/-0)
test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/ScopeMetadataImpl_test.cpp (+388/-0)
test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini.in (+3/-0)
test/gtest/unity/api/scopes/internal/zmq_middleware/ObjectAdapter/Zmq.ini.in (+1/-0)
test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/CMakeLists.txt (+0/-1)
test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Factory.ini.in (+0/-3)
test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/RegistryI_test.cpp (+58/-41)
test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Zmq.ini.in (+1/-0)
test/gtest/unity/api/scopes/internal/zmq_middleware/ServantBase/Zmq.ini.in (+1/-0)
test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/Zmq.ini.in (+1/-0)
test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/ZmqMiddleware_test.cpp (+1/-0)
To merge this branch: bzr merge lp:~michihenning/unity-scopes-api/scope-metadata
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Paweł Stołowski (community) Needs Information
Review via email: mp+197005@code.launchpad.net

Commit message

Added scope metadata to config and registry. Optional fields that are not set throw on an attempt to access them. This allows us to distinguish "not set all" from "set to default value".

Simplified configuration. Factory.ini no longer exists. Client can now run without Runtime.ini, but still needs Registry.ini and Zmq.ini. (It looks for those in the current directory.) Will fix this next.

Various minor clean-up in tests and doc comments.

Description of the change

Added scope metadata to config and registry. Optional fields that are not set throw on an attempt to access them. This allows us to distinguish "not set all" from "set to default value".

Simplified configuration. Factory.ini no longer exists. Client can now run without Runtime.ini, but still needs Registry.ini and Zmq.ini. (It looks for those in the current directory.) Will fix this next.

Various minor clean-up in tests and doc comments.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

295 + ScopeMetadata find(std::string const& scope_name) const;

As we discussed can we please rename this to get_metadata()? find() throwing an exception if something is not found feels as if a contains() method threw an exception if a container doesn't contain the item.

25 + 'art' : string

I don't think we want "art" in categories too, "art" is called art for results because they can be camera pictures, product images, comic strips... anything. A category should indeed have an "icon", not a picture of your friends.

31 + 'art' : string

For scope metadata, I think we should have both art and icon - art would be used for the branded scope pages, and icons for the navigation bar (both optional I suppose).

review: Needs Fixing
Revision history for this message
Michal Hruby (mhr3) wrote :

2134 +dictionary<string, VariantMap> ScopeMap;

Got me really confused, we do have ScopeMap in the public API, perhaps using a different name would make things clearer.

Revision history for this message
Michal Hruby (mhr3) wrote :

399 +class UNITY_API ScopeMetadata final

No UNITY_DEFINES_PTRS for ScopeMetadata?

Revision history for this message
Michi Henning (michihenning) wrote :

Thanks for the feedback, I agree with all of this. Will change!

Sorry about the "art" thing. I noticed that ResultItem had changed from "icon" to "arg" and figured we had better be consistent. My misunderstanding...

Revision history for this message
Paweł Stołowski (stolowski) wrote :

2857 +TEST(ScopeMetadataImpl, serialize_exceptions)
2858 +{
2859 + ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini",
2860 + (RuntimeImpl*)0x1);
2861 +
2862 + ScopeMetadataImpl mi(&mw);
2863 + try
2864 + {
2865 + mi.serialize();
2866 + }
2867 + catch (InvalidArgumentException const&e)
2868 + {
2869 + EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'scope_name' is empty",
2870 + e.to_string());
2871 + }

Those kind of test should check if the exception was actually thrown.

review: Needs Fixing
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Since ScopeMetadataImpl::serialize() can throw InvalidArgumentException (on empty scope_name or art), is it OK that we don't catch it in RegistryI::find_() and RegistryI::list_()? Also, only for NotFoundException in find_() we set status to (capnproto::ResponseStatus::USER_EXCEPTION), otherwise it is capnproto::ResponseStatus::SUCCESS in both find_() and list_(), is this intended?

I'm sorry, I couldn't easily find out how the exceptions propagate, but from the observation Michal and I have it seems that if "art" attribute of ScopeMetadata is empty (and the assert on that is removed from ctor, which is the case in release code), then the problem is only discovered in deserialize() in the client code, not in the serialize() on registry side, e.g. client gives:

./client A a
unity::api::scopes::MiddlewareException: unity::InvalidArgumentException: ScopeMetadata: required attribute 'art' is empty

review: Needs Information
Revision history for this message
Michi Henning (michihenning) wrote :

> Those kind of test should check if the exception was actually thrown.

Thanks for catching this! I've just added the missing FAIL() statements.

Revision history for this message
Michi Henning (michihenning) wrote :

> Since ScopeMetadataImpl::serialize() can throw InvalidArgumentException (on
> empty scope_name or art), is it OK that we don't catch it in
> RegistryI::find_() and RegistryI::list_()? Also, only for NotFoundException in
> find_() we set status to (capnproto::ResponseStatus::USER_EXCEPTION),
> otherwise it is capnproto::ResponseStatus::SUCCESS in both find_() and
> list_(), is this intended?

Yes, that's OK. Not all exceptions are marshalled as specific exception types over the wire. If the implementation of a method throws something that isn't expected as an exception that is to be marshalled, that is caught in safe_dispatch_() in ServantBase, and the exception response will be UNKNOWN_EXCEPTION over the wire.

> I'm sorry, I couldn't easily find out how the exceptions propagate, but from
> the observation Michal and I have it seems that if "art" attribute of
> ScopeMetadata is empty (and the assert on that is removed from ctor, which is
> the case in release code), then the problem is only discovered in
> deserialize() in the client code, not in the serialize() on registry side,
> e.g. client gives:
>
> ./client A a
> unity::api::scopes::MiddlewareException: unity::InvalidArgumentException:
> ScopeMetadata: required attribute 'art' is empty

From a previous message from Michal, both art and icon should be optional:

> For scope metadata, I think we should have both art and icon - art would be used for the branded > scope pages, and icons for the navigation bar (both optional I suppose).

That's what I implemented (and what I'm about to push).

73. By Michi Henning

Renamed ScopeMap -> MetadataMap

74. By Michi Henning

Added Ptr definitions to ScopeMetadata.

75. By Michi Henning

Renamed find() -> get_metadata()

76. By Michi Henning

Added icon attribute to ScopeMetadata and made art attribute optional.

77. By Michi Henning

Addming missing FAIL() calls for tests that expect an exception when no exception is in fact thrown.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

1828 + // For optional values, we store them in a unique_ptr so we can distinguish the "not set at all" case
1829 + // from the "explicitly set to empty string" case.
1830 + try
1831 + {
1832 + string art = parser()->get_string(SCOPE_CONFIG_GROUP, art_str);
1833 + art_.reset(new string(art));
1834 + }
1835 + catch (LogicException const&)
1836 + {
1837 + }

Just a small nitpick - can you a add comment saying that these exceptions are ignored deliberately as they are for optional values? Otherwise looking good to me.

Revision history for this message
Michal Hruby (mhr3) wrote :

20 +Category (returned by serialize()):

Missing the new 'art'.

431 + std::string localized_name() const; // localized

Shouldn't this be just "name()"? I don't think we want i18n details to be visible in the API, do we? Also for consistency we'd then want "localized_description()", "locallized_search_hint()" etc. Was the concern that if it was just a "name()", it'd be confusing to have both name() and scope_name()? If so, perhaps we should rename the scope_name() to scope_id()? Afterall it's a unique id, isn't it?

689 + bool add(std::string const& scope_name, ScopeMetadata const scope);

Passing metadata by value? Is that desired?

review: Needs Fixing
Revision history for this message
Michi Henning (michihenning) wrote :

> Just a small nitpick - can you a add comment saying that these exceptions are ignored
> deliberately as they are for optional values? Otherwise looking good to me.

Fixed, thanks!

> 20 +Category (returned by serialize()):
>
> Missing the new 'art'.

Are you sure about this? Categories don't have art, as far as I can see.

> 431 + std::string localized_name() const; // localized
>
> Shouldn't this be just "name()"? I don't think we want i18n details to be
> visible in the API, do we? Also for consistency we'd then want
> "localized_description()", "locallized_search_hint()" etc. Was the concern
> that if it was just a "name()", it'd be confusing to have both name() and
> scope_name()? If so, perhaps we should rename the scope_name() to scope_id()?
> Afterall it's a unique id, isn't it?

Yes. Unfortunately, renaming "scope_name' to "scope_id" would be rather disruptive. It's all through the existing code. How about "display_name" for what is now "localised_name"? That would be much less intrusive a change.

> 689 + bool add(std::string const& scope_name, ScopeMetadata const
> scope);
>
> Passing metadata by value? Is that desired?

Yes, that was intentional. It's a sink function, and the implementation moves the value into place in the map. There are a few corner cases where that avoids a copy. But then, the efficiency gain is minor and basically not noticeable, so I changed it to const reference for consistency.

Please let me know about the "display_name" suggestion.

Revision history for this message
Michi Henning (michihenning) wrote :

Come to think of it, just "name" would work too, I think.

Revision history for this message
Michal Hruby (mhr3) wrote :

> > 20 +Category (returned by serialize()):
> >
> > Missing the new 'art'.
>
> Are you sure about this? Categories don't have art, as far as I can see.

Ah, right, that's for scopes themselves, nevermind then.

> > 431 + std::string localized_name() const; // localized
> >
> > Shouldn't this be just "name()"? I don't think we want i18n details to be
> > visible in the API, do we? Also for consistency we'd then want
> > "localized_description()", "locallized_search_hint()" etc. Was the concern
> > that if it was just a "name()", it'd be confusing to have both name() and
> > scope_name()? If so, perhaps we should rename the scope_name() to
> scope_id()?
> > Afterall it's a unique id, isn't it?
>
> Yes. Unfortunately, renaming "scope_name' to "scope_id" would be rather
> disruptive. It's all through the existing code. How about "display_name" for
> what is now "localised_name"? That would be much less intrusive a change.
>

display_name() works for me.

78. By Michi Henning

Changed localized_name to display_name. Improved comment for catching exceptions for optional attributes.

Revision history for this message
Michal Hruby (mhr3) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'STRUCTS'
--- STRUCTS 2013-11-18 11:32:10 +0000
+++ STRUCTS 2013-12-03 14:09:20 +0000
@@ -19,22 +19,35 @@
19middleware.19middleware.
20-----------------------------------------------------------------------------20-----------------------------------------------------------------------------
2121
22ResultItem (returned by variant_map()):22ResultItem (returned by serialize()):
23=======================================23=======================================
24 'uri' : string24 'uri' : string
25 'title' : string25 'title' : string
26 'icon' : string26 'art' : string
27 'dnd_uri' : string27 'dnd_uri' : string
28 'cat_id' : string28 'cat_id' : string
29 + any custom key-value attribute added by scope author.29 + any custom key-value attribute added by scope author.
3030
31Category (returned by variant_map()):31Category (returned by serialize()):
32=====================================32=====================================
33 'id' : string33 'id' : string
34 'title' : string34 'title' : string
35 'icon' : string35 'icon' : string
36 'renderer_template' : string36 'renderer_template' : string
3737
38ScopeMetadata (returned by serialize()):
39=====================================
40 'scope_name' : string
41 'proxy' : dictionary
42 'identity' : string
43 'endpoint' : string
44 'display_name' : string
45 'description' : string
46 'art' : string, optional
47 'icon' : string, optional
48 'search_hint' : string, optional
49 'hot_key' : string, optional
50
38PushRequest (capnproto structure)51PushRequest (capnproto structure)
39=================================52=================================
40 result : ValueDict with "category" and/or "result" key and serialized Category / ResultItem respectively.53 result : ValueDict with "category" and/or "result" key and serialized Category / ResultItem respectively.
4154
=== modified file 'demo/CMakeLists.txt'
--- demo/CMakeLists.txt 2013-11-19 02:51:46 +0000
+++ demo/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -1,7 +1,6 @@
1add_subdirectory(scopes)1add_subdirectory(scopes)
2add_subdirectory(scope-groups)2add_subdirectory(scope-groups)
33
4configure_file(Factory.ini.in Factory.ini)
5configure_file(Runtime.ini.in Runtime.ini)4configure_file(Runtime.ini.in Runtime.ini)
6configure_file(Registry.ini.in Registry.ini)5configure_file(Registry.ini.in Registry.ini)
7configure_file(Zmq.ini.in Zmq.ini)6configure_file(Zmq.ini.in Zmq.ini)
87
=== removed file 'demo/Factory.ini.in'
--- demo/Factory.ini.in 2013-11-19 02:51:46 +0000
+++ demo/Factory.ini.in 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1[MiddlewareFactory]
2Zmq.Configfile = @CMAKE_CURRENT_BINARY_DIR@/Zmq.ini
30
=== modified file 'demo/Zmq.ini.in'
--- demo/Zmq.ini.in 2013-11-19 02:51:46 +0000
+++ demo/Zmq.ini.in 2013-12-03 14:09:20 +0000
@@ -1,3 +1,3 @@
1[Zmq]1[Zmq]
2EndpointDir.Public = /tmp2EndpointDir.Public = /tmp
3EndpointDir.Private = @CMAKE_CURRENT_BINARY_DIR@3EndpointDir.Private = /tmp
44
=== modified file 'demo/client.cpp'
--- demo/client.cpp 2013-11-26 16:08:29 +0000
+++ demo/client.cpp 2013-12-03 14:09:20 +0000
@@ -16,12 +16,13 @@
16 * Authored by: Michi Henning <michi.henning@canonical.com>16 * Authored by: Michi Henning <michi.henning@canonical.com>
17 */17 */
1818
19#include <scopes/CategoryRenderer.h>
19#include <scopes/QueryCtrl.h>20#include <scopes/QueryCtrl.h>
20#include <scopes/Registry.h>21#include <scopes/Registry.h>
21#include <scopes/ReceiverBase.h>22#include <scopes/ReceiverBase.h>
22#include <scopes/Runtime.h>23#include <scopes/Runtime.h>
23#include <scopes/ResultItem.h>24#include <scopes/ResultItem.h>
24#include <scopes/CategoryRenderer.h>25#include <scopes/ScopeExceptions.h>
25#include <unity/UnityExceptions.h>26#include <unity/UnityExceptions.h>
2627
27#include <condition_variable>28#include <condition_variable>
@@ -91,15 +92,52 @@
91 Runtime::UPtr rt = Runtime::create("dash");92 Runtime::UPtr rt = Runtime::create("dash");
9293
93 RegistryProxy r = rt->registry();94 RegistryProxy r = rt->registry();
94 ScopeProxy s = r->find(scope_name);95 auto meta = r->get_metadata(scope_name);
96 cout << "Scope metadata: " << endl;
97 cout << "\tscope_name: " << meta.scope_name() << endl;
98 cout << "\tdisplay_name: " << meta.display_name() << endl;
99 cout << "\tdescription: " << meta.description() << endl;
100 string tmp;
101 try
102 {
103 tmp = meta.art();
104 cout << "\tart: " << meta.art() << endl;
105 }
106 catch (NotFoundException const& e)
107 {
108 }
109 try
110 {
111 tmp = meta.icon();
112 cout << "\ticon: " << meta.icon() << endl;
113 }
114 catch (NotFoundException const& e)
115 {
116 }
117 try
118 {
119 tmp = meta.search_hint();
120 cout << "\tsearch_hint: " << meta.search_hint() << endl;
121 }
122 catch (NotFoundException const& e)
123 {
124 }
125 try
126 {
127 tmp = meta.hot_key();
128 cout << "\thot_key: " << meta.hot_key() << endl;
129 }
130 catch (NotFoundException const& e)
131 {
132 }
95 shared_ptr<Receiver> reply(new Receiver);133 shared_ptr<Receiver> reply(new Receiver);
96 VariantMap vm;134 VariantMap vm;
97 vm["cardinality"] = 10;135 vm["cardinality"] = 10;
98 vm["locale"] = "C";136 vm["locale"] = "C";
99 auto ctrl = s->create_query(search_string, vm, reply); // Returns (almost) immediately137 auto ctrl = meta.proxy()->create_query(search_string, vm, reply); // Returns (almost) immediately
100 cerr << "client: created query" << endl;138 cout << "client: created query" << endl;
101 reply->wait_until_finished();139 reply->wait_until_finished();
102 cerr << "client: wait returned" << endl;140 cout << "client: wait returned" << endl;
103 }141 }
104142
105 catch (unity::Exception const& e)143 catch (unity::Exception const& e)
106144
=== modified file 'demo/scopes/scope-A/scope-A.cpp'
--- demo/scopes/scope-A/scope-A.cpp 2013-11-26 16:08:29 +0000
+++ demo/scopes/scope-A/scope-A.cpp 2013-12-03 14:09:20 +0000
@@ -73,7 +73,6 @@
73 }73 }
7474
75 virtual void stop() override {}75 virtual void stop() override {}
76 virtual void run() override {}
7776
78 virtual QueryBase::UPtr create_query(string const& q, VariantMap const&) override77 virtual QueryBase::UPtr create_query(string const& q, VariantMap const&) override
79 {78 {
8079
=== modified file 'demo/scopes/scope-A/scope-A.ini.in'
--- demo/scopes/scope-A/scope-A.ini.in 2013-11-19 02:51:46 +0000
+++ demo/scopes/scope-A/scope-A.ini.in 2013-12-03 14:09:20 +0000
@@ -1,1 +1,7 @@
1[ScopeConfig]1[ScopeConfig]
2DisplayName = scope-A.DisplayName
3Description = scope-A.Description
4Art = scope-A.Art
5Icon = scope-A.Icon
6SearchHint = scope-A.SearchHint
7HotKey = scope-A.HotKey
28
=== modified file 'demo/scopes/scope-B/scope-B.cpp'
--- demo/scopes/scope-B/scope-B.cpp 2013-11-26 16:08:29 +0000
+++ demo/scopes/scope-B/scope-B.cpp 2013-12-03 14:09:20 +0000
@@ -128,16 +128,16 @@
128 scope_name_ = scope_name;128 scope_name_ = scope_name;
129129
130 // Lock up scopes C and D in the registry and remember their proxies.130 // Lock up scopes C and D in the registry and remember their proxies.
131 scope_c_ = registry->find("scope-C");131 auto meta_c = registry->get_metadata("scope-C");
132 scope_d_ = registry->find("scope-D");132 scope_c_ = meta_c.proxy();
133 auto meta_d = registry->get_metadata("scope-D");
134 scope_d_ = meta_d.proxy();
133135
134 return VERSION;136 return VERSION;
135 }137 }
136138
137 virtual void stop() override {}139 virtual void stop() override {}
138140
139 virtual void run() override {}
140
141 virtual QueryBase::UPtr create_query(string const& q, VariantMap const&) override141 virtual QueryBase::UPtr create_query(string const& q, VariantMap const&) override
142 {142 {
143 QueryBase::UPtr query(new MyQuery(scope_name_, q, scope_c_, scope_d_));143 QueryBase::UPtr query(new MyQuery(scope_name_, q, scope_c_, scope_d_));
144144
=== modified file 'demo/scopes/scope-B/scope-B.ini.in'
--- demo/scopes/scope-B/scope-B.ini.in 2013-11-19 02:51:46 +0000
+++ demo/scopes/scope-B/scope-B.ini.in 2013-12-03 14:09:20 +0000
@@ -1,1 +1,3 @@
1[ScopeConfig]1[ScopeConfig]
2DisplayName = scope-B.DisplayName
3Description = scope-B.Description
24
=== modified file 'demo/scopes/scope-C/scope-C.ini.in'
--- demo/scopes/scope-C/scope-C.ini.in 2013-11-19 02:51:46 +0000
+++ demo/scopes/scope-C/scope-C.ini.in 2013-12-03 14:09:20 +0000
@@ -1,1 +1,3 @@
1[ScopeConfig]1[ScopeConfig]
2DisplayName = scope-C.DisplayName
3Description = scope-C.Description
24
=== modified file 'demo/scopes/scope-D/scope-D.ini.in'
--- demo/scopes/scope-D/scope-D.ini.in 2013-11-19 02:51:46 +0000
+++ demo/scopes/scope-D/scope-D.ini.in 2013-12-03 14:09:20 +0000
@@ -1,1 +1,3 @@
1[ScopeConfig]1[ScopeConfig]
2DisplayName = scope-D.DisplayName
3Description = scope-D.Description
24
=== modified file 'demo/scopes/scope-N/scope-N.cpp'
--- demo/scopes/scope-N/scope-N.cpp 2013-11-21 21:44:00 +0000
+++ demo/scopes/scope-N/scope-N.cpp 2013-12-03 14:09:20 +0000
@@ -62,7 +62,6 @@
62 }62 }
6363
64 virtual void stop() override {}64 virtual void stop() override {}
65 virtual void run() override {}
6665
67 virtual QueryBase::UPtr create_query(string const&, VariantMap const&) override66 virtual QueryBase::UPtr create_query(string const&, VariantMap const&) override
68 {67 {
6968
=== modified file 'demo/scopes/scope-N/scope-N.ini.in'
--- demo/scopes/scope-N/scope-N.ini.in 2013-11-19 02:51:46 +0000
+++ demo/scopes/scope-N/scope-N.ini.in 2013-12-03 14:09:20 +0000
@@ -1,1 +1,3 @@
1[ScopeConfig]1[ScopeConfig]
2DisplayName = scope-N.DisplayName
3Description = scope-N.Description
24
=== modified file 'demo/scopes/scope-S/scope-S.cpp'
--- demo/scopes/scope-S/scope-S.cpp 2013-11-26 16:08:29 +0000
+++ demo/scopes/scope-S/scope-S.cpp 2013-12-03 14:09:20 +0000
@@ -77,7 +77,6 @@
77 }77 }
7878
79 virtual void stop() override {}79 virtual void stop() override {}
80 virtual void run() override {}
8180
82 virtual QueryBase::UPtr create_query(string const& q, VariantMap const& hints) override81 virtual QueryBase::UPtr create_query(string const& q, VariantMap const& hints) override
83 {82 {
8483
=== modified file 'demo/scopes/scope-S/scope-S.ini.in'
--- demo/scopes/scope-S/scope-S.ini.in 2013-11-19 02:51:46 +0000
+++ demo/scopes/scope-S/scope-S.ini.in 2013-12-03 14:09:20 +0000
@@ -1,1 +1,3 @@
1[ScopeConfig]1[ScopeConfig]
2DisplayName = scope-S.DisplayName
3Description = scope-S.Description
24
=== modified file 'include/scopes/ObjectProxy.h'
--- include/scopes/ObjectProxy.h 2013-11-25 19:05:41 +0000
+++ include/scopes/ObjectProxy.h 2013-12-03 14:09:20 +0000
@@ -42,6 +42,9 @@
42 ObjectProxy();42 ObjectProxy();
43 virtual ~ObjectProxy() noexcept;43 virtual ~ObjectProxy() noexcept;
4444
45 std::string endpoint() const;
46 std::string identity() const;
47
45protected:48protected:
46 internal::ObjectProxyImpl* pimpl() const noexcept; // Non-virtual because we can't use covariance with incomplete types49 internal::ObjectProxyImpl* pimpl() const noexcept; // Non-virtual because we can't use covariance with incomplete types
47 // Each derived proxy type implements a non-virtual fwd() method50 // Each derived proxy type implements a non-virtual fwd() method
4851
=== modified file 'include/scopes/Registry.h'
--- include/scopes/Registry.h 2013-11-25 19:05:41 +0000
+++ include/scopes/Registry.h 2013-12-03 14:09:20 +0000
@@ -21,7 +21,7 @@
2121
22#include <scopes/ObjectProxy.h>22#include <scopes/ObjectProxy.h>
23#include <scopes/RegistryProxyFwd.h>23#include <scopes/RegistryProxyFwd.h>
24#include <scopes/Scope.h>24#include <scopes/ScopeMetadata.h>
2525
26#include <map>26#include <map>
2727
@@ -40,9 +40,9 @@
40}40}
4141
42/**42/**
43\brief Map for scope name and proxy pairs.43\brief Map for scope name and metadata pairs.
44*/44*/
45typedef std::map<std::string, ScopeProxy> ScopeMap;45typedef std::map<std::string, ScopeMetadata> MetadataMap;
4646
47/**47/**
48\brief RegistryProxy provides access to the available scopes.48\brief RegistryProxy provides access to the available scopes.
@@ -57,15 +57,22 @@
57 /// @endcond57 /// @endcond
5858
59 /**59 /**
60 \brief Returns a ScopeProxy for the scope with the given name.60 \brief Returns the metadata for the scope with the given name.
61 @return If no scope with the given name exists, find() throws NotFoundException.61 @return The metadata for the scope. If no scope with the given name exists, get_metadata() throws NotFoundException.
62 */62 */
63 ScopeProxy find(std::string const& scope_name) const;63 ScopeMetadata get_metadata(std::string const& scope_name) const;
6464
65 /**65 /**
66 \brief Returns a map containing the name/proxy pairs for all available scopes.66 \brief Returns a map containing the metadata for all scopes.
67 */67 */
68 ScopeMap list() const;68 MetadataMap list() const;
69
70 /**
71 \brief Returns a map containing only those scopes for which predicate returns true.
72 \param predicate a function object the must return true for each metadata item to be include in the map.
73 \return The metadata items for which the predicate returned true.
74 */
75 MetadataMap list_if(std::function<bool(ScopeMetadata const& item)> predicate) const;
6976
70protected:77protected:
71 Registry(internal::RegistryImpl* impl); // Instantiated only by RegistryImpl78 Registry(internal::RegistryImpl* impl); // Instantiated only by RegistryImpl
7279
=== modified file 'include/scopes/ResultItem.h'
--- include/scopes/ResultItem.h 2013-11-27 02:08:11 +0000
+++ include/scopes/ResultItem.h 2013-12-03 14:09:20 +0000
@@ -87,7 +87,7 @@
8787
88 /**88 /**
89 \brief Returns a dictionary of all attributes of this ResultItem instance.89 \brief Returns a dictionary of all attributes of this ResultItem instance.
90 \return dictionary of all base attributes and custom attributes set with add_metadata call.90 \return Dictionary of all base attributes and custom attributes set with add_metadata call.
91 */91 */
92 VariantMap serialize() const;92 VariantMap serialize() const;
9393
9494
=== modified file 'include/scopes/Runtime.h'
--- include/scopes/Runtime.h 2013-11-25 16:22:12 +0000
+++ include/scopes/Runtime.h 2013-12-03 14:09:20 +0000
@@ -58,11 +58,6 @@
58 /// @endcond58 /// @endcond
5959
60 /**60 /**
61 \brief The default configuration file (relative to the current directory) if none is passed to create().
62 */
63 static constexpr char const* DFLT_CONFIGFILE = "Runtime.ini";
64
65 /**
66 \brief Instantiates the scopes run time for the scope with the given name and (optional) configuration file.61 \brief Instantiates the scopes run time for the scope with the given name and (optional) configuration file.
6762
68 The life time of the run time is under control of the caller. Letting the returned `unique_ptr` go out63 The life time of the run time is under control of the caller. Letting the returned `unique_ptr` go out
@@ -71,8 +66,13 @@
71 You _must not_ create a Runtime instance until after `main()` is entered, and you _must_ destroy it66 You _must not_ create a Runtime instance until after `main()` is entered, and you _must_ destroy it
72 before leaving `main()` (either by explicitly calling destroy(), or by letting the returned67 before leaving `main()` (either by explicitly calling destroy(), or by letting the returned
73 `unique_ptr` go out of scope). Failure to do so causes undefined behavior.68 `unique_ptr` go out of scope). Failure to do so causes undefined behavior.
69
70 \param configfile The path name of the configuration file to use.
71
72 If configfile is the empty string, a default configuration is used.
74 */73 */
75 static UPtr create(std::string const& scope_name, std::string const& configfile = DFLT_CONFIGFILE);74 // TODO: Update above to state what the default configuration is exactly
75 static UPtr create(std::string const& scope_name, std::string const& configfile = "");
7676
77 /**77 /**
78 \brief Shuts down the run time, reclaiming all associated resources.78 \brief Shuts down the run time, reclaiming all associated resources.
7979
=== added file 'include/scopes/ScopeMetadata.h'
--- include/scopes/ScopeMetadata.h 1970-01-01 00:00:00 +0000
+++ include/scopes/ScopeMetadata.h 2013-12-03 14:09:20 +0000
@@ -0,0 +1,78 @@
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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser 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#ifndef UNITY_API_SCOPES_SCOPEMETADATA_H
20#define UNITY_API_SCOPES_SCOPEMETADATA_H
21
22#include <scopes/Scope.h>
23
24namespace unity
25{
26
27namespace api
28{
29
30namespace scopes
31{
32
33namespace internal
34{
35class ScopeMetadataImpl;
36} // namespace internal
37
38class UNITY_API ScopeMetadata final
39{
40public:
41 UNITY_DEFINES_PTRS(ScopeMetadata);
42
43 ScopeMetadata(ScopeMetadata const& other);
44 ScopeMetadata(ScopeMetadata&&);
45 ~ScopeMetadata();
46
47 ScopeMetadata& operator=(ScopeMetadata const& other);
48 ScopeMetadata& operator=(ScopeMetadata&&);
49
50 std::string scope_name() const;
51 ScopeProxy proxy() const;
52 std::string display_name() const; // localized
53 std::string description() const; // localized
54 std::string art() const; // optional
55 std::string icon() const; // optional
56 std::string search_hint() const; // localized, optional
57 std::string hot_key() const; // localized, optional
58
59 /**
60 \brief Returns a dictionary of all attributes of this ScopeMetadata instance.
61 \return Dictionary of all metadata attributes.
62 */
63 VariantMap serialize() const;
64
65private:
66 ScopeMetadata(std::unique_ptr<internal::ScopeMetadataImpl>); // Instantiable only by ScopeMetadataImpl
67 std::unique_ptr<internal::ScopeMetadataImpl> p;
68
69 friend class internal::ScopeMetadataImpl;
70};
71
72} // namespace scopes
73
74} // namespace api
75
76} // namespace unity
77
78#endif
079
=== modified file 'include/scopes/internal/ConfigBase.h'
--- include/scopes/internal/ConfigBase.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/ConfigBase.h 2013-12-03 14:09:20 +0000
@@ -41,6 +41,7 @@
41class ConfigBase41class ConfigBase
42{42{
43public:43public:
44 ConfigBase();
44 ConfigBase(std::string const& configfile);45 ConfigBase(std::string const& configfile);
45 virtual ~ConfigBase() noexcept;46 virtual ~ConfigBase() noexcept;
4647
@@ -53,6 +54,7 @@
53 virtual void throw_ex(::std::string const& reason) const;54 virtual void throw_ex(::std::string const& reason) const;
5455
55private:56private:
57 unity::util::IniParser::SPtr p() const;
56 unity::util::IniParser::SPtr parser_;58 unity::util::IniParser::SPtr parser_;
57 std::string configfile_;59 std::string configfile_;
58};60};
5961
=== modified file 'include/scopes/internal/MWObjectProxy.h'
--- include/scopes/internal/MWObjectProxy.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/MWObjectProxy.h 2013-12-03 14:09:20 +0000
@@ -37,8 +37,6 @@
3737
38// Base class for the MW<something>Proxy hierarchy. We store the pointer to the middleware here,38// Base class for the MW<something>Proxy hierarchy. We store the pointer to the middleware here,
39// which is needed to, for example, register callback objects (such as a Reply object) with the middleware.39// which is needed to, for example, register callback objects (such as a Reply object) with the middleware.
40// We also keep a pointer to the run time, so we can get at other relevant deatils, such as a scope name,
41// reply object reaper, etc.
4240
43class MWObjectProxy41class MWObjectProxy
44{42{
@@ -47,6 +45,9 @@
4745
48 virtual MiddlewareBase* mw_base() const noexcept = 0;46 virtual MiddlewareBase* mw_base() const noexcept = 0;
4947
48 virtual std::string identity() const = 0;
49 virtual std::string endpoint() const = 0;
50
50protected:51protected:
51 MWObjectProxy(MiddlewareBase* mw_base);52 MWObjectProxy(MiddlewareBase* mw_base);
5253
5354
=== modified file 'include/scopes/internal/MWRegistry.h'
--- include/scopes/internal/MWRegistry.h 2013-11-25 16:22:12 +0000
+++ include/scopes/internal/MWRegistry.h 2013-12-03 14:09:20 +0000
@@ -21,6 +21,7 @@
2121
22#include <scopes/internal/MWObjectProxy.h>22#include <scopes/internal/MWObjectProxy.h>
23#include <scopes/Registry.h>23#include <scopes/Registry.h>
24#include <scopes/ScopeMetadata.h>
2425
25namespace unity26namespace unity
26{27{
@@ -38,8 +39,8 @@
38{39{
39public:40public:
40 // Remote operation implementation41 // Remote operation implementation
41 virtual ScopeProxy find(std::string const& scope_name) = 0;42 virtual ScopeMetadata get_metadata(std::string const& scope_name) = 0;
42 virtual ScopeMap list() = 0;43 virtual MetadataMap list() = 0;
4344
44 virtual ~MWRegistry() noexcept;45 virtual ~MWRegistry() noexcept;
4546
4647
=== modified file 'include/scopes/internal/MiddlewareBase.h'
--- include/scopes/internal/MiddlewareBase.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/MiddlewareBase.h 2013-12-03 14:09:20 +0000
@@ -19,6 +19,7 @@
19#ifndef UNITY_API_SCOPES_INTERNAL_MIDDLEWAREBASE_H19#ifndef UNITY_API_SCOPES_INTERNAL_MIDDLEWAREBASE_H
20#define UNITY_API_SCOPES_INTERNAL_MIDDLEWAREBASE_H20#define UNITY_API_SCOPES_INTERNAL_MIDDLEWAREBASE_H
2121
22#include <scopes/internal/MWObjectProxyFwd.h>
22#include <scopes/internal/MWQueryCtrlProxyFwd.h>23#include <scopes/internal/MWQueryCtrlProxyFwd.h>
23#include <scopes/internal/MWQueryProxyFwd.h>24#include <scopes/internal/MWQueryProxyFwd.h>
24#include <scopes/internal/MWRegistryProxyFwd.h>25#include <scopes/internal/MWRegistryProxyFwd.h>
@@ -61,6 +62,8 @@
61 virtual void stop() = 0;62 virtual void stop() = 0;
62 virtual void wait_for_shutdown() = 0;63 virtual void wait_for_shutdown() = 0;
6364
65 virtual MWProxy create_proxy(std::string const& identity, std::string const& endpoint) = 0;
66
64 virtual MWRegistryProxy create_registry_proxy(std::string const& identity, std::string const& endpoint) = 0;67 virtual MWRegistryProxy create_registry_proxy(std::string const& identity, std::string const& endpoint) = 0;
65 virtual MWScopeProxy create_scope_proxy(std::string const& identity) = 0;68 virtual MWScopeProxy create_scope_proxy(std::string const& identity) = 0;
66 virtual MWScopeProxy create_scope_proxy(std::string const& identity, std::string const& endpoint) = 0;69 virtual MWScopeProxy create_scope_proxy(std::string const& identity, std::string const& endpoint) = 0;
6770
=== modified file 'include/scopes/internal/MiddlewareFactory.h'
--- include/scopes/internal/MiddlewareFactory.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/MiddlewareFactory.h 2013-12-03 14:09:20 +0000
@@ -44,7 +44,7 @@
44public:44public:
45 UNITY_DEFINES_PTRS(MiddlewareFactory);45 UNITY_DEFINES_PTRS(MiddlewareFactory);
4646
47 MiddlewareFactory(std::string const& configfile, RuntimeImpl* runtime);47 MiddlewareFactory(RuntimeImpl* runtime);
48 ~MiddlewareFactory() noexcept;48 ~MiddlewareFactory() noexcept;
4949
50 // Returns the middleware with the given name and kind. If that middleware hasn't been created yet,50 // Returns the middleware with the given name and kind. If that middleware hasn't been created yet,
5151
=== removed file 'include/scopes/internal/MiddlewareFactoryConfig.h'
--- include/scopes/internal/MiddlewareFactoryConfig.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/MiddlewareFactoryConfig.h 1970-01-01 00:00:00 +0000
@@ -1,60 +0,0 @@
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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser 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#ifndef UNITY_API_SCOPES_INTERNAL_MIDDLEWAREFACTORYCONFIG_H
20#define UNITY_API_SCOPES_INTERNAL_MIDDLEWAREFACTORYCONFIG_H
21
22#include <scopes/internal/ConfigBase.h>
23
24namespace unity
25{
26
27namespace api
28{
29
30namespace scopes
31{
32
33namespace internal
34{
35
36class MiddlewareFactoryConfig : public ConfigBase
37{
38public:
39 static const char* MIDDLEWARE_FACTORY_CONFIG_GROUP;
40
41 MiddlewareFactoryConfig(std::string const& configfile);
42 ~MiddlewareFactoryConfig() noexcept;
43
44 std::string zmq_configfile() const;
45 std::string rest_configfile() const;
46
47private:
48 std::string zmq_configfile_;
49 std::string rest_configfile_;
50};
51
52} // namespace internal
53
54} // namespace scopes
55
56} // namespace api
57
58} // namespace unity
59
60#endif
610
=== modified file 'include/scopes/internal/ObjectProxyImpl.h'
--- include/scopes/internal/ObjectProxyImpl.h 2013-11-25 19:05:41 +0000
+++ include/scopes/internal/ObjectProxyImpl.h 2013-12-03 14:09:20 +0000
@@ -40,10 +40,13 @@
40 ObjectProxyImpl(MWProxy const& mw_proxy);40 ObjectProxyImpl(MWProxy const& mw_proxy);
41 virtual ~ObjectProxyImpl() noexcept;41 virtual ~ObjectProxyImpl() noexcept;
4242
43 virtual std::string identity() const;
44 virtual std::string endpoint() const;
45
43protected:46protected:
44 MWProxy proxy() const; // Non-virtual because we cannot use covariance with incomplete types.47 MWProxy proxy() const; // Non-virtual because we cannot use covariance with incomplete types.
45 // Each derived proxy implements a non-virtual fwd() method48 // Each derived proxy implements a non-virtual fwd() method
46 // that is called from within each operation to down-cast the MWProxy.49 // that is called from within each operation to down-cast the MWProxy.
4750
48private:51private:
49 static Proxy create(MWProxy const& mw_proxy);52 static Proxy create(MWProxy const& mw_proxy);
5053
=== modified file 'include/scopes/internal/RegistryImpl.h'
--- include/scopes/internal/RegistryImpl.h 2013-11-25 19:05:41 +0000
+++ include/scopes/internal/RegistryImpl.h 2013-12-03 14:09:20 +0000
@@ -43,8 +43,9 @@
43 RegistryImpl(MWRegistryProxy const& mw_proxy, RuntimeImpl* runtime);43 RegistryImpl(MWRegistryProxy const& mw_proxy, RuntimeImpl* runtime);
44 ~RegistryImpl() noexcept;44 ~RegistryImpl() noexcept;
4545
46 ScopeProxy find(std::string const& scope_name);46 ScopeMetadata get_metadata(std::string const& scope_name);
47 ScopeMap list();47 MetadataMap list();
48 MetadataMap list_if(std::function<bool(ScopeMetadata const& item)> predicate);
4849
49 static RegistryProxy create(MWRegistryProxy const& mw_proxy, RuntimeImpl* runtime);50 static RegistryProxy create(MWRegistryProxy const& mw_proxy, RuntimeImpl* runtime);
5051
5152
=== modified file 'include/scopes/internal/RegistryObject.h'
--- include/scopes/internal/RegistryObject.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/RegistryObject.h 2013-12-03 14:09:20 +0000
@@ -20,9 +20,8 @@
20#define UNITY_API_SCOPES_INTERNAL_REGISTRYOBJECT_H20#define UNITY_API_SCOPES_INTERNAL_REGISTRYOBJECT_H
2121
22#include <scopes/internal/AbstractObject.h>22#include <scopes/internal/AbstractObject.h>
23#include <scopes/internal/MWScope.h>23#include <scopes/Registry.h>
2424
25#include <map>
26#include <mutex>25#include <mutex>
2726
28namespace unity27namespace unity
@@ -48,16 +47,15 @@
48 virtual ~RegistryObject() noexcept;47 virtual ~RegistryObject() noexcept;
4948
50 // Remote operation implementations49 // Remote operation implementations
51 MWScopeProxy find(std::string const& scope_name);50 ScopeMetadata get_metadata(std::string const& scope_name);
5251
53 typedef std::map<std::string, MWScopeProxy> MWScopeMap;52 MetadataMap list();
54 MWScopeMap list();53
5554 bool add(std::string const& scope_name, ScopeMetadata const& scope);
56 bool add(std::string const& scope_name, MWScopeProxy const& scope);
57 bool remove(std::string const& scope_name);55 bool remove(std::string const& scope_name);
5856
59private:57private:
60 mutable MWScopeMap scopes_;58 mutable MetadataMap scopes_;
61 mutable std::mutex mutex_;59 mutable std::mutex mutex_;
62};60};
6361
6462
=== modified file 'include/scopes/internal/RuntimeConfig.h'
--- include/scopes/internal/RuntimeConfig.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/RuntimeConfig.h 2013-12-03 14:09:20 +0000
@@ -39,7 +39,7 @@
39public:39public:
40 static const char* RUNTIME_CONFIG_GROUP;40 static const char* RUNTIME_CONFIG_GROUP;
4141
42 RuntimeConfig(std::string const& configfile = Runtime::DFLT_CONFIGFILE);42 RuntimeConfig(std::string const& configfile);
43 ~RuntimeConfig() noexcept;43 ~RuntimeConfig() noexcept;
4444
45 std::string registry_identity() const;45 std::string registry_identity() const;
4646
=== modified file 'include/scopes/internal/RuntimeImpl.h'
--- include/scopes/internal/RuntimeImpl.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/RuntimeImpl.h 2013-12-03 14:09:20 +0000
@@ -43,7 +43,7 @@
43public:43public:
44 UNITY_DEFINES_PTRS(RuntimeImpl);44 UNITY_DEFINES_PTRS(RuntimeImpl);
4545
46 static UPtr create(std::string const& scope_name, std::string const& configfile = Runtime::DFLT_CONFIGFILE);46 static UPtr create(std::string const& scope_name, std::string const& configfile = "");
47 void destroy();47 void destroy();
4848
49 std::string scope_name() const;49 std::string scope_name() const;
5050
=== modified file 'include/scopes/internal/ScopeConfig.h'
--- include/scopes/internal/ScopeConfig.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/ScopeConfig.h 2013-12-03 14:09:20 +0000
@@ -41,10 +41,22 @@
41 ScopeConfig(std::string const& configfile);41 ScopeConfig(std::string const& configfile);
42 ~ScopeConfig() noexcept;42 ~ScopeConfig() noexcept;
4343
44 bool overrideable() const;44 bool overrideable() const; // Optional, returns false if not present
45 std::string display_name() const;
46 std::string description() const;
47 std::string art() const; // Optional, throws NotFoundException if not present
48 std::string icon() const; // Optional, throws NotFoundException if not present
49 std::string search_hint() const; // Optional, throws NotFoundException if not present
50 std::string hot_key() const; // Optional, throws NotFoundException if not present
4551
46private:52private:
47 bool overrideable_;53 bool overrideable_;
54 std::string display_name_;
55 std::string description_;
56 std::unique_ptr<std::string> art_;
57 std::unique_ptr<std::string> icon_;
58 std::unique_ptr<std::string> search_hint_;
59 std::unique_ptr<std::string> hot_key_;
48};60};
4961
50} // namespace internal62} // namespace internal
5163
=== added file 'include/scopes/internal/ScopeMetadataImpl.h'
--- include/scopes/internal/ScopeMetadataImpl.h 1970-01-01 00:00:00 +0000
+++ include/scopes/internal/ScopeMetadataImpl.h 2013-12-03 14:09:20 +0000
@@ -0,0 +1,94 @@
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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the Lesser 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#ifndef UNITY_API_SCOPES_INTERNAL_SCOPEMETADATAIMPL_H
20#define UNITY_API_SCOPES_INTERNAL_SCOPEMETADATAIMPL_H
21
22#include <scopes/internal/MWScope.h>
23#include <scopes/ScopeMetadata.h>
24
25#include <unordered_set>
26
27namespace unity
28{
29
30namespace api
31{
32
33namespace scopes
34{
35
36namespace internal
37{
38
39class ScopeMetadataImpl
40{
41public:
42 ScopeMetadataImpl(MiddlewareBase* mw);
43 ScopeMetadataImpl(VariantMap const& variant_map, MiddlewareBase* mw);
44 ScopeMetadataImpl(ScopeMetadataImpl const&);
45 ScopeMetadataImpl(ScopeMetadataImpl&&) = default;
46 ScopeMetadataImpl& operator=(ScopeMetadataImpl const&);
47 ScopeMetadataImpl& operator=(ScopeMetadataImpl&&) = default;
48
49 std::string scope_name() const;
50 ScopeProxy proxy() const;
51 std::string display_name() const; // localized
52 std::string description() const; // localized
53 std::string art() const; // optional
54 std::string icon() const; // optional
55 std::string search_hint() const; // localized, optional
56 std::string hot_key() const; // localized, optional
57
58 void set_scope_name(std::string const& scope_name);
59 void set_proxy(ScopeProxy const& proxy);
60 void set_display_name(std::string const& display_name);
61 void set_description(std::string const& description);
62 void set_art(std::string const& art);
63 void set_icon(std::string const& icon);
64 void set_search_hint(std::string const& search_hint);
65 void set_hot_key(std::string const& hot_key);
66
67 VariantMap serialize() const;
68 void deserialize(VariantMap const& var);
69
70 static ScopeMetadata create(std::unique_ptr<ScopeMetadataImpl> impl);
71
72private:
73
74 MiddlewareBase* mw_;
75 std::string scope_name_;
76 ScopeProxy proxy_;
77 std::string display_name_;
78 std::string description_;
79 std::unique_ptr<std::string> art_; // Optional, hence a pointer
80 std::unique_ptr<std::string> icon_; // Optional, hence a pointer
81 std::unique_ptr<std::string> search_hint_; // Optional, hence a pointer
82 std::unique_ptr<std::string> hot_key_; // Optional, hence a pointer
83};
84
85} // namespace internal
86
87} // namespace scopes
88
89} // namespace api
90
91} // namespace unity
92
93
94#endif
095
=== modified file 'include/scopes/internal/zmq_middleware/RegistryI.h'
--- include/scopes/internal/zmq_middleware/RegistryI.h 2013-11-21 21:46:36 +0000
+++ include/scopes/internal/zmq_middleware/RegistryI.h 2013-12-03 14:09:20 +0000
@@ -51,7 +51,7 @@
51 virtual ~RegistryI() noexcept;51 virtual ~RegistryI() noexcept;
5252
53private:53private:
54 virtual void find_(Current const& current,54 virtual void get_metadata_(Current const& current,
55 capnp::ObjectPointer::Reader& in_params,55 capnp::ObjectPointer::Reader& in_params,
56 capnproto::Response::Builder& r);56 capnproto::Response::Builder& r);
5757
5858
=== modified file 'include/scopes/internal/zmq_middleware/RequestType.h'
--- include/scopes/internal/zmq_middleware/RequestType.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/zmq_middleware/RequestType.h 2013-12-03 14:09:20 +0000
@@ -36,7 +36,7 @@
36namespace zmq_middleware36namespace zmq_middleware
37{37{
3838
39enum RequestType { Oneway, Twoway };39enum RequestType { Unknown, Oneway, Twoway };
4040
41std::string to_string(RequestType);41std::string to_string(RequestType);
4242
4343
=== modified file 'include/scopes/internal/zmq_middleware/ZmqConfig.h'
--- include/scopes/internal/zmq_middleware/ZmqConfig.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/zmq_middleware/ZmqConfig.h 2013-12-03 14:09:20 +0000
@@ -21,8 +21,6 @@
2121
22#include <scopes/internal/ConfigBase.h>22#include <scopes/internal/ConfigBase.h>
2323
24#include <mutex>
25
26namespace unity24namespace unity
27{25{
2826
@@ -48,8 +46,7 @@
4846
49private:47private:
50 std::string public_dir_;48 std::string public_dir_;
51 mutable std::string private_dir_;49 std::string private_dir_;
52 mutable std::mutex mutex_;
53};50};
5451
55} // namespace internal52} // namespace internal
5653
=== modified file 'include/scopes/internal/zmq_middleware/ZmqMiddleware.h'
--- include/scopes/internal/zmq_middleware/ZmqMiddleware.h 2013-11-21 21:44:00 +0000
+++ include/scopes/internal/zmq_middleware/ZmqMiddleware.h 2013-12-03 14:09:20 +0000
@@ -61,6 +61,8 @@
61 virtual void stop() override;61 virtual void stop() override;
62 virtual void wait_for_shutdown() override;62 virtual void wait_for_shutdown() override;
6363
64 virtual MWProxy create_proxy(std::string const& identity, std::string const& endpoint) override;
65
64 virtual MWRegistryProxy create_registry_proxy(std::string const& identity, std::string const& endpoint) override;66 virtual MWRegistryProxy create_registry_proxy(std::string const& identity, std::string const& endpoint) override;
65 virtual MWScopeProxy create_scope_proxy(std::string const& identity) override;67 virtual MWScopeProxy create_scope_proxy(std::string const& identity) override;
66 virtual MWScopeProxy create_scope_proxy(std::string const& identity, std::string const& endpoint) override;68 virtual MWScopeProxy create_scope_proxy(std::string const& identity, std::string const& endpoint) override;
6769
=== modified file 'include/scopes/internal/zmq_middleware/ZmqObjectProxy.h'
--- include/scopes/internal/zmq_middleware/ZmqObjectProxy.h 2013-11-25 16:22:12 +0000
+++ include/scopes/internal/zmq_middleware/ZmqObjectProxy.h 2013-12-03 14:09:20 +0000
@@ -45,11 +45,12 @@
4545
46class ZmqReceiver;46class ZmqReceiver;
4747
48// An Zmq proxy that points at some Zmq object, but without a specific type.48// A Zmq proxy that points at some Zmq object, but without a specific type.
4949
50class ZmqObjectProxy : public virtual MWObjectProxy50class ZmqObjectProxy : public virtual MWObjectProxy
51{51{
52public:52public:
53 ZmqObjectProxy(ZmqMiddleware* mw_base, std::string const& endpoint, std::string const& identity);
53 ZmqObjectProxy(ZmqMiddleware* mw_base, std::string const& endpoint, std::string const& identity, RequestType t);54 ZmqObjectProxy(ZmqMiddleware* mw_base, std::string const& endpoint, std::string const& identity, RequestType t);
54 virtual ~ZmqObjectProxy() noexcept;55 virtual ~ZmqObjectProxy() noexcept;
5556
@@ -63,43 +64,12 @@
63 capnproto::Request::Builder make_request_(capnp::MessageBuilder& b, std::string const& operation_name) const;64 capnproto::Request::Builder make_request_(capnp::MessageBuilder& b, std::string const& operation_name) const;
64 std::unique_ptr<ZmqReceiver> invoke_(capnp::MessageBuilder& out_params);65 std::unique_ptr<ZmqReceiver> invoke_(capnp::MessageBuilder& out_params);
6566
66 // TODO: commented out for now (see below)
67#if 0
68 template<typename F>
69 std::unique_ptr<capnp::SegmentArrayMessageReader> submit_request_(F f);
70#endif
71
72private:67private:
73 std::string endpoint_;68 std::string endpoint_;
74 std::string identity_;69 std::string identity_;
75 RequestType type_;70 RequestType type_;
76};71};
7772
78// TODO: Ideally, we would use this template because this is type-independent work, instead of having the
79// body of this method repeated in each operation of the derived proxy. But, for some reason, the getRoot
80// call below causes a syntax error. Need to try with clang to see whether there is a better error message.
81// Or maybe it's a gcc bug...
82
83#if 0
84template<typename F>
85std::unique_ptr<capnp::SegmentArrayMessageReader> ZmqObjectProxy::submit_request_(F f)
86{
87 try
88 {
89 auto future = mw_base()->invoke_pool()->submit(f);
90 future.wait();
91 auto reader = future.get();
92 auto response = reader->getRoot<capnproto::Response>();
93 throw_if_runtime_exception(response);
94 return reader;
95 }
96 catch (...)
97 {
98 throw; // TODO: what to do here?
99 }
100}
101#endif
102
103} // namespace zmq_middleware73} // namespace zmq_middleware
10474
105} // namespace internal75} // namespace internal
10676
=== modified file 'include/scopes/internal/zmq_middleware/ZmqRegistry.h'
--- include/scopes/internal/zmq_middleware/ZmqRegistry.h 2013-11-25 16:22:12 +0000
+++ include/scopes/internal/zmq_middleware/ZmqRegistry.h 2013-12-03 14:09:20 +0000
@@ -48,8 +48,8 @@
48 virtual ~ZmqRegistry() noexcept;48 virtual ~ZmqRegistry() noexcept;
4949
50 // Remote operations.50 // Remote operations.
51 virtual ScopeProxy find(std::string const& scope_name) override;51 virtual ScopeMetadata get_metadata(std::string const& scope_name) override;
52 virtual ScopeMap list() override;52 virtual MetadataMap list() override;
53};53};
5454
55} // namespace zmq_middleware55} // namespace zmq_middleware
5656
=== modified file 'scoperegistry/scoperegistry.cpp'
--- scoperegistry/scoperegistry.cpp 2013-11-21 21:44:00 +0000
+++ scoperegistry/scoperegistry.cpp 2013-12-03 14:09:20 +0000
@@ -25,6 +25,9 @@
25#include <scopes/internal/RuntimeConfig.h>25#include <scopes/internal/RuntimeConfig.h>
26#include <scopes/internal/RuntimeImpl.h>26#include <scopes/internal/RuntimeImpl.h>
27#include <scopes/internal/ScopeConfig.h>27#include <scopes/internal/ScopeConfig.h>
28#include <scopes/internal/ScopeMetadataImpl.h>
29#include <scopes/internal/ScopeImpl.h>
30#include <scopes/ScopeExceptions.h>
28#include <unity/UnityExceptions.h>31#include <unity/UnityExceptions.h>
29#include <unity/util/ResourcePtr.h>32#include <unity/util/ResourcePtr.h>
3033
@@ -94,7 +97,7 @@
94 }97 }
95 catch (FileException const& e)98 catch (FileException const& e)
96 {99 {
97 error(e.to_string() + ": scope group file ignored");100 error("scope group config file ignored:\n" + e.to_string());
98 continue;101 continue;
99 }102 }
100103
@@ -105,7 +108,7 @@
105 }108 }
106 catch (LogicException const& e)109 catch (LogicException const& e)
107 {110 {
108 error("group file \"" + file + ": file ignored: " + e.to_string());111 error("group file \"" + file + ": file ignored:\n" + e.to_string());
109 continue;112 continue;
110 }113 }
111114
@@ -148,6 +151,62 @@
148 return scope_groups;151 return scope_groups;
149}152}
150153
154// For each scope, open the config file for each scope, create the metadata info from the config,
155// and add an entry to the RegistryObject.
156
157void add_metadata(RegistryObject::SPtr const& registry,
158 map<string, string> const& all_scopes,
159 MiddlewareBase::SPtr const& mw)
160{
161 for (auto pair : all_scopes)
162 {
163 try
164 {
165 unique_ptr<ScopeMetadataImpl> mi(new ScopeMetadataImpl(mw.get()));
166 ScopeConfig sc(pair.second);
167 mi->set_scope_name(pair.first);
168 mi->set_display_name(sc.display_name());
169 mi->set_description(sc.description());
170 try
171 {
172 mi->set_art(sc.art());
173 }
174 catch (NotFoundException const&)
175 {
176 }
177 try
178 {
179 mi->set_icon(sc.icon());
180 }
181 catch (NotFoundException const&)
182 {
183 }
184 try
185 {
186 mi->set_search_hint(sc.search_hint());
187 }
188 catch (NotFoundException const&)
189 {
190 }
191 try
192 {
193 mi->set_hot_key(sc.hot_key());
194 }
195 catch (NotFoundException const&)
196 {
197 }
198 ScopeProxy proxy = ScopeImpl::create(mw->create_scope_proxy(pair.first), mw->runtime());
199 mi->set_proxy(proxy);
200 auto meta = ScopeMetadataImpl::create(move(mi));
201 registry->add(pair.first, move(meta));
202 }
203 catch (unity::Exception const& e)
204 {
205 error("ignoring scope \"" + pair.first + "\": cannot create metadata: " + e.to_string());
206 }
207 }
208}
209
151void run_scopes(SignalThread& sigthread,210void run_scopes(SignalThread& sigthread,
152 string const& scoperunner_path,211 string const& scoperunner_path,
153 string const& config_file,212 string const& config_file,
@@ -200,7 +259,7 @@
200 }259 }
201 char const* const config_file = argv[1];260 char const* const config_file = argv[1];
202261
203 int exit_status = 0;262 int exit_status = 1;
204263
205 // Run a separate thread to deal with SIGCHLD. This allows us to report when a scope process exits abnormally.264 // Run a separate thread to deal with SIGCHLD. This allows us to report when a scope process exits abnormally.
206 SignalThread signal_thread;265 SignalThread signal_thread;
@@ -246,14 +305,21 @@
246 {305 {
247 string file_name = basename(const_cast<char*>(string(path).c_str())); // basename() modifies its argument306 string file_name = basename(const_cast<char*>(string(path).c_str())); // basename() modifies its argument
248 string scope_name = strip_suffix(file_name, ".ini");307 string scope_name = strip_suffix(file_name, ".ini");
249 ScopeConfig config(path);308 try
250 if (config.overrideable())
251 {309 {
252 overrideable_scopes[scope_name] = path;310 ScopeConfig config(path);
311 if (config.overrideable())
312 {
313 overrideable_scopes[scope_name] = path;
314 }
315 else
316 {
317 fixed_scopes[scope_name] = path;
318 }
253 }319 }
254 else320 catch (unity::Exception const& e)
255 {321 {
256 fixed_scopes[scope_name] = path;322 error("ignoring scope \"" + scope_name + "\": configuration error:\n" + e.to_string());
257 }323 }
258 }324 }
259325
@@ -297,13 +363,10 @@
297 RegistryObject::SPtr registry(new RegistryObject);363 RegistryObject::SPtr registry(new RegistryObject);
298 middleware->add_registry_object(runtime->registry_identity(), registry);364 middleware->add_registry_object(runtime->registry_identity(), registry);
299365
300 // Add a proxy for each scope to the lookup table.366 // Add the metadata for each scope to the lookup table.
301 // We do this before starting any of the scopes, so aggregating scopes don't get a lookup failure if367 // We do this before starting any of the scopes, so aggregating scopes don't get a lookup failure if
302 // they look for another scope in the registry.368 // they look for another scope in the registry.
303 for (auto pair : all_scopes)369 add_metadata(registry, all_scopes, middleware);
304 {
305 registry->add(pair.first, middleware->create_scope_proxy(pair.first));
306 }
307370
308 // Start a scoperunner for each Canonical scope group and add the corresponding proxies to the registry371 // Start a scoperunner for each Canonical scope group and add the corresponding proxies to the registry
309 run_scopes(signal_thread, scoperunner_path, config_file, canonical_groups);372 run_scopes(signal_thread, scoperunner_path, config_file, canonical_groups);
@@ -313,31 +376,27 @@
313376
314 // Wait until we are done.377 // Wait until we are done.
315 middleware->wait_for_shutdown();378 middleware->wait_for_shutdown();
379 exit_status = 0;
316 }380 }
317 catch (unity::Exception const& e)381 catch (unity::Exception const& e)
318 {382 {
319 error(e.to_string());383 error(e.to_string());
320 exit_status = 1;
321 }384 }
322 catch (std::exception const& e)385 catch (std::exception const& e)
323 {386 {
324 error(e.what());387 error(e.what());
325 exit_status = 1;
326 }388 }
327 catch (string const& e)389 catch (string const& e)
328 {390 {
329 error("fatal error: " + e);391 error("fatal error: " + e);
330 exit_status = 1;
331 }392 }
332 catch (char const* e)393 catch (char const* e)
333 {394 {
334 error(string("fatal error: ") + e);395 error(string("fatal error: ") + e);
335 exit_status = 1;
336 }396 }
337 catch (...)397 catch (...)
338 {398 {
339 error("terminated due to unknown exception");399 error("terminated due to unknown exception");
340 exit_status = 1;
341 }400 }
342401
343 return exit_status;402 return exit_status;
344403
=== modified file 'scoperunner/scoperunner.cpp'
--- scoperunner/scoperunner.cpp 2013-11-21 21:44:00 +0000
+++ scoperunner/scoperunner.cpp 2013-12-03 14:09:20 +0000
@@ -200,7 +200,7 @@
200 }200 }
201 char const* const runtime_config = argv[1];201 char const* const runtime_config = argv[1];
202202
203 int exit_status = 0;203 int exit_status = 1;
204 try204 try
205 {205 {
206 vector<string> config_files;206 vector<string> config_files;
@@ -218,27 +218,22 @@
218 catch (unity::Exception const& e)218 catch (unity::Exception const& e)
219 {219 {
220 error(e.to_string());220 error(e.to_string());
221 exit_status = 1;
222 }221 }
223 catch (std::exception const& e)222 catch (std::exception const& e)
224 {223 {
225 error(e.what());224 error(e.what());
226 exit_status = 1;
227 }225 }
228 catch (string const& e)226 catch (string const& e)
229 {227 {
230 error("fatal error: " + e);228 error("fatal error: " + e);
231 exit_status = 1;
232 }229 }
233 catch (char const* e)230 catch (char const* e)
234 {231 {
235 error(string("fatal error: ") + e);232 error(string("fatal error: ") + e);
236 exit_status = 1;
237 }233 }
238 catch (...)234 catch (...)
239 {235 {
240 error("terminated due to unknown exception");236 error("terminated due to unknown exception");
241 exit_status = 1;
242 }237 }
243238
244 return exit_status;239 return exit_status;
245240
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2013-11-26 15:35:46 +0000
+++ src/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -16,6 +16,7 @@
16 ${CMAKE_CURRENT_SOURCE_DIR}/Scope.cpp16 ${CMAKE_CURRENT_SOURCE_DIR}/Scope.cpp
17 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeBase.cpp17 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeBase.cpp
18 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeExceptions.cpp18 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeExceptions.cpp
19 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeMetadata.cpp
19 ${CMAKE_CURRENT_SOURCE_DIR}/Variant.cpp20 ${CMAKE_CURRENT_SOURCE_DIR}/Variant.cpp
20 ${CMAKE_CURRENT_SOURCE_DIR}/Version.cpp21 ${CMAKE_CURRENT_SOURCE_DIR}/Version.cpp
21)22)
2223
=== modified file 'src/ObjectProxy.cpp'
--- src/ObjectProxy.cpp 2013-11-25 19:05:41 +0000
+++ src/ObjectProxy.cpp 2013-12-03 14:09:20 +0000
@@ -20,6 +20,8 @@
2020
21#include <scopes/internal/ObjectProxyImpl.h>21#include <scopes/internal/ObjectProxyImpl.h>
2222
23using namespace std;
24
23namespace unity25namespace unity
24{26{
2527
@@ -51,6 +53,16 @@
51{53{
52}54}
5355
56string ObjectProxy::identity() const
57{
58 return p->identity();
59}
60
61string ObjectProxy::endpoint() const
62{
63 return p->endpoint();
64}
65
54internal::ObjectProxyImpl* ObjectProxy::pimpl() const noexcept66internal::ObjectProxyImpl* ObjectProxy::pimpl() const noexcept
55{67{
56 return p.get();68 return p.get();
5769
=== modified file 'src/ReceiverBase.cpp'
--- src/ReceiverBase.cpp 2013-11-25 19:05:41 +0000
+++ src/ReceiverBase.cpp 2013-12-03 14:09:20 +0000
@@ -42,8 +42,9 @@
42{42{
43}43}
4444
45void ReceiverBase::push(Category::SCPtr category)45void ReceiverBase::push(Category::SCPtr /* category */)
46{46{
47 // Intentionally empty: "do nothing" default implementation.
47}48}
4849
49// Possibly overkill, but safer than using the enum as the index into an array,50// Possibly overkill, but safer than using the enum as the index into an array,
5051
=== modified file 'src/Registry.cpp'
--- src/Registry.cpp 2013-11-25 19:05:41 +0000
+++ src/Registry.cpp 2013-12-03 14:09:20 +0000
@@ -42,16 +42,21 @@
4242
43//! @endcond43//! @endcond
4444
45ScopeProxy Registry::find(std::string const& scope_name) const45ScopeMetadata Registry::get_metadata(std::string const& scope_name) const
46{46{
47 return fwd()->find(scope_name);47 return fwd()->get_metadata(scope_name);
48}48}
4949
50ScopeMap Registry::list() const50MetadataMap Registry::list() const
51{51{
52 return fwd()->list();52 return fwd()->list();
53}53}
5454
55MetadataMap Registry::list_if(std::function<bool(ScopeMetadata const& item)> predicate) const
56{
57 return fwd()->list_if(predicate);
58}
59
55internal::RegistryImpl* Registry::fwd() const60internal::RegistryImpl* Registry::fwd() const
56{61{
57 return dynamic_cast<internal::RegistryImpl*>(pimpl());62 return dynamic_cast<internal::RegistryImpl*>(pimpl());
5863
=== modified file 'src/Runtime.cpp'
--- src/Runtime.cpp 2013-11-25 16:22:12 +0000
+++ src/Runtime.cpp 2013-12-03 14:09:20 +0000
@@ -31,8 +31,6 @@
31namespace scopes31namespace scopes
32{32{
3333
34constexpr char const* Runtime::DFLT_CONFIGFILE;
35
36//! @cond34//! @cond
3735
38Runtime::Runtime(string const& scope_name, string const& configfile) :36Runtime::Runtime(string const& scope_name, string const& configfile) :
3937
=== added file 'src/ScopeMetadata.cpp'
--- src/ScopeMetadata.cpp 1970-01-01 00:00:00 +0000
+++ src/ScopeMetadata.cpp 2013-12-03 14:09:20 +0000
@@ -0,0 +1,123 @@
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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser 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/ScopeMetadata.h>
20#include <scopes/internal/ScopeMetadataImpl.h>
21
22#include <cassert>
23
24using namespace std;
25
26namespace unity
27{
28
29namespace api
30{
31
32namespace scopes
33{
34
35//! @cond
36
37ScopeMetadata::ScopeMetadata(unique_ptr<internal::ScopeMetadataImpl> impl) :
38 p(move(impl))
39{
40 // The only way to create a ScopeMetadata instance is to first intialize
41 // a ScopeMetadataImpl, fill it in, and then call this constructor.
42 // We check here that all mandatory fields are present. If not
43 // we have an internal logic error.
44 assert(!p->scope_name().empty());
45 assert(p->proxy());
46 assert(!p->display_name().empty());
47 assert(!p->description().empty());
48}
49
50ScopeMetadata::ScopeMetadata(ScopeMetadata const& other) :
51 p(new internal::ScopeMetadataImpl(*(other.p)))
52{
53}
54
55ScopeMetadata::ScopeMetadata(ScopeMetadata&&) = default;
56
57ScopeMetadata::~ScopeMetadata()
58{
59}
60
61ScopeMetadata& ScopeMetadata::operator=(ScopeMetadata const& other)
62{
63 if (this != &other)
64 {
65 p.reset(new internal::ScopeMetadataImpl(*(other.p)));
66 }
67 return *this;
68}
69
70ScopeMetadata& ScopeMetadata::operator=(ScopeMetadata&&) = default;
71
72string ScopeMetadata::scope_name() const
73{
74 return p->scope_name();
75}
76
77ScopeProxy ScopeMetadata::proxy() const
78{
79 return p->proxy();
80}
81
82string ScopeMetadata::display_name() const
83{
84 return p->display_name();
85}
86
87string ScopeMetadata::description() const
88{
89 return p->description();
90}
91
92string ScopeMetadata::art() const
93{
94 return p->art();
95}
96
97string ScopeMetadata::icon() const
98{
99 return p->icon();
100}
101
102string ScopeMetadata::search_hint() const
103{
104 return p->search_hint();
105}
106
107string ScopeMetadata::hot_key() const
108{
109 return p->hot_key();
110}
111
112VariantMap ScopeMetadata::serialize() const
113{
114 return p->serialize();
115}
116
117//! @endcond
118
119} // namespace scopes
120
121} // namespace api
122
123} // namespace unity
0124
=== modified file 'src/internal/CMakeLists.txt'
--- src/internal/CMakeLists.txt 2013-11-26 15:35:46 +0000
+++ src/internal/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -11,7 +11,6 @@
11 ${CMAKE_CURRENT_SOURCE_DIR}/DynamicLoader.cpp11 ${CMAKE_CURRENT_SOURCE_DIR}/DynamicLoader.cpp
12 ${CMAKE_CURRENT_SOURCE_DIR}/MiddlewareBase.cpp12 ${CMAKE_CURRENT_SOURCE_DIR}/MiddlewareBase.cpp
13 ${CMAKE_CURRENT_SOURCE_DIR}/MiddlewareFactory.cpp13 ${CMAKE_CURRENT_SOURCE_DIR}/MiddlewareFactory.cpp
14 ${CMAKE_CURRENT_SOURCE_DIR}/MiddlewareFactoryConfig.cpp
15 ${CMAKE_CURRENT_SOURCE_DIR}/MWObject.cpp14 ${CMAKE_CURRENT_SOURCE_DIR}/MWObject.cpp
16 ${CMAKE_CURRENT_SOURCE_DIR}/MWQuery.cpp15 ${CMAKE_CURRENT_SOURCE_DIR}/MWQuery.cpp
17 ${CMAKE_CURRENT_SOURCE_DIR}/MWQueryCtrl.cpp16 ${CMAKE_CURRENT_SOURCE_DIR}/MWQueryCtrl.cpp
@@ -35,6 +34,7 @@
35 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeConfig.cpp34 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeConfig.cpp
36 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeImpl.cpp35 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeImpl.cpp
37 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeLoader.cpp36 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeLoader.cpp
37 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeMetadataImpl.cpp
38 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeObject.cpp38 ${CMAKE_CURRENT_SOURCE_DIR}/ScopeObject.cpp
39 ${CMAKE_CURRENT_SOURCE_DIR}/ThreadPool.cpp39 ${CMAKE_CURRENT_SOURCE_DIR}/ThreadPool.cpp
40 ${CMAKE_CURRENT_SOURCE_DIR}/UniqueID.cpp40 ${CMAKE_CURRENT_SOURCE_DIR}/UniqueID.cpp
4141
=== modified file 'src/internal/ConfigBase.cpp'
--- src/internal/ConfigBase.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/ConfigBase.cpp 2013-12-03 14:09:20 +0000
@@ -22,7 +22,6 @@
22#include <unity/UnityExceptions.h>22#include <unity/UnityExceptions.h>
23#include <unity/util/IniParser.h>23#include <unity/util/IniParser.h>
2424
25#include <sstream>
2625
27using namespace std;26using namespace std;
2827
@@ -38,24 +37,30 @@
38namespace internal37namespace internal
39{38{
4039
40// If configfile is the empty string, we create a default instance that returns "Zmq" for the middleware
41// and throws for the other methods.
42
41ConfigBase::ConfigBase(string const& configfile) :43ConfigBase::ConfigBase(string const& configfile) :
42 parser_(make_shared<util::IniParser>(configfile.c_str())),
43 configfile_(configfile)44 configfile_(configfile)
44{45{
46 if (!configfile.empty())
47 {
48 parser_ = make_shared<util::IniParser>(configfile.c_str());
49 }
45}50}
4651
47ConfigBase::~ConfigBase() noexcept52ConfigBase::~ConfigBase() noexcept
48{53{
49}54}
5055
51shared_ptr<util::IniParser> ConfigBase::parser() const noexcept56util::IniParser::SPtr ConfigBase::parser() const noexcept
52{57{
53 return parser_;58 return p();
54}59}
5560
56string ConfigBase::get_string(string const& group, string const& key) const61string ConfigBase::get_string(string const& group, string const& key) const
57{62{
58 string val = parser_->get_string(group, key);63 string val = p()->get_string(group, key);
59 if (val.empty())64 if (val.empty())
60 {65 {
61 throw_ex("Illegal empty value for " + key);66 throw_ex("Illegal empty value for " + key);
@@ -67,7 +72,7 @@
67{72{
68 try73 try
69 {74 {
70 return parser_->get_string(group, key);75 return p()->get_string(group, key);
71 }76 }
72 catch (unity::LogicException const&)77 catch (unity::LogicException const&)
73 {78 {
@@ -77,6 +82,10 @@
7782
78string ConfigBase::get_middleware(string const& group, string const& key) const83string ConfigBase::get_middleware(string const& group, string const& key) const
79{84{
85 if (!parser_)
86 {
87 return "Zmq";
88 }
80 string val = get_string(group, key);89 string val = get_string(group, key);
81 if (val != "Zmq" && val != "REST")90 if (val != "Zmq" && val != "REST")
82 {91 {
@@ -88,9 +97,17 @@
8897
89void ConfigBase::throw_ex(string const& reason) const98void ConfigBase::throw_ex(string const& reason) const
90{99{
91 ostringstream s;100 string s = "\"" + configfile_ + "\": " + reason;
92 s << "\"" << configfile_ << "\": " << reason;101 throw ConfigException(s);
93 throw ConfigException(s.str());102}
103
104util::IniParser::SPtr ConfigBase::p() const
105{
106 if (!parser_)
107 {
108 throw LogicException("ConfigBase: no parser available with default config");
109 }
110 return parser_;
94}111}
95112
96} // namespace internal113} // namespace internal
97114
=== modified file 'src/internal/MiddlewareFactory.cpp'
--- src/internal/MiddlewareFactory.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/MiddlewareFactory.cpp 2013-12-03 14:09:20 +0000
@@ -18,8 +18,6 @@
1818
19#include <scopes/internal/MiddlewareFactory.h>19#include <scopes/internal/MiddlewareFactory.h>
2020
21// #include <scopes/internal/ice_middleware/IceMiddleware.h>
22#include <scopes/internal/MiddlewareFactoryConfig.h>
23#include <scopes/internal/zmq_middleware/ZmqMiddleware.h>21#include <scopes/internal/zmq_middleware/ZmqMiddleware.h>
24#include <scopes/ScopeExceptions.h>22#include <scopes/ScopeExceptions.h>
2523
@@ -40,19 +38,10 @@
40namespace internal38namespace internal
41{39{
4240
43MiddlewareFactory::MiddlewareFactory(string const& configfile, RuntimeImpl* runtime) :41MiddlewareFactory::MiddlewareFactory(RuntimeImpl* runtime) :
44 runtime_(runtime)42 runtime_(runtime)
45{43{
46 assert(runtime);44 assert(runtime);
47
48 try
49 {
50 MiddlewareFactoryConfig config(configfile);
51 }
52 catch (unity::Exception const& e)
53 {
54 throw ConfigException("cannot instantiate MiddlewareFactory: config file: " + configfile);
55 }
56}45}
5746
58MiddlewareFactory::~MiddlewareFactory() noexcept47MiddlewareFactory::~MiddlewareFactory() noexcept
5948
=== modified file 'src/internal/ObjectProxyImpl.cpp'
--- src/internal/ObjectProxyImpl.cpp 2013-11-25 19:05:41 +0000
+++ src/internal/ObjectProxyImpl.cpp 2013-12-03 14:09:20 +0000
@@ -49,6 +49,16 @@
49 return make_shared<ObjectProxy>();49 return make_shared<ObjectProxy>();
50}50}
5151
52string ObjectProxyImpl::identity() const
53{
54 return mw_proxy_->identity();
55}
56
57string ObjectProxyImpl::endpoint() const
58{
59 return mw_proxy_->endpoint();
60}
61
52MWProxy ObjectProxyImpl::proxy() const62MWProxy ObjectProxyImpl::proxy() const
53{63{
54 return mw_proxy_;64 return mw_proxy_;
5565
=== modified file 'src/internal/RegistryImpl.cpp'
--- src/internal/RegistryImpl.cpp 2013-11-25 19:05:41 +0000
+++ src/internal/RegistryImpl.cpp 2013-12-03 14:09:20 +0000
@@ -45,16 +45,30 @@
45{45{
46}46}
4747
48ScopeProxy RegistryImpl::find(std::string const& scope_name)48ScopeMetadata RegistryImpl::get_metadata(std::string const& scope_name)
49{49{
50 return fwd()->find(scope_name);50 return fwd()->get_metadata(scope_name);
51}51}
5252
53ScopeMap RegistryImpl::list()53MetadataMap RegistryImpl::list()
54{54{
55 return fwd()->list();55 return fwd()->list();
56}56}
5757
58MetadataMap RegistryImpl::list_if(std::function<bool(ScopeMetadata const& item)> predicate)
59{
60 auto scope_map = list();
61 MetadataMap matching_entries;
62 for (auto& pair : scope_map)
63 {
64 if (predicate(pair.second))
65 {
66 matching_entries.emplace(pair);
67 }
68 }
69 return matching_entries;
70}
71
58RegistryProxy RegistryImpl::create(MWRegistryProxy const& mw_proxy, RuntimeImpl* runtime)72RegistryProxy RegistryImpl::create(MWRegistryProxy const& mw_proxy, RuntimeImpl* runtime)
59{73{
60 return RegistryProxy(new Registry(new RegistryImpl(mw_proxy, runtime)));74 return RegistryProxy(new Registry(new RegistryImpl(mw_proxy, runtime)));
6175
=== modified file 'src/internal/RegistryObject.cpp'
--- src/internal/RegistryObject.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/RegistryObject.cpp 2013-12-03 14:09:20 +0000
@@ -43,7 +43,7 @@
43{43{
44}44}
4545
46MWScopeProxy RegistryObject::find(std::string const& scope_name)46ScopeMetadata RegistryObject::get_metadata(std::string const& scope_name)
47{47{
48 // If the name is empty, it was sent as empty by the remote client.48 // If the name is empty, it was sent as empty by the remote client.
49 if (scope_name.empty())49 if (scope_name.empty())
@@ -56,33 +56,34 @@
56 auto const& it = scopes_.find(scope_name);56 auto const& it = scopes_.find(scope_name);
57 if (it == scopes_.end())57 if (it == scopes_.end())
58 {58 {
59 throw NotFoundException("Registry::find(): no such scope", scope_name);59 throw NotFoundException("Registry::get_metadata(): no such scope", scope_name);
60 }60 }
61 return it->second;61 return it->second;
62}62}
6363
64RegistryObject::MWScopeMap RegistryObject::list()64MetadataMap RegistryObject::list()
65{65{
66 lock_guard<decltype(mutex_)> lock(mutex_);66 lock_guard<decltype(mutex_)> lock(mutex_);
67 return scopes_;67 return scopes_;
68}68}
6969
70bool RegistryObject::add(std::string const& scope_name, MWScopeProxy const& scope)70bool RegistryObject::add(std::string const& scope_name, ScopeMetadata const& metadata)
71{71{
72 // TODO: also check for names containing a slash, because that won't work if we use72 if (scope_name.empty())
73 {
74 throw unity::InvalidArgumentException("Registry: Cannot add scope with empty name");
75 }
76 // TODO: check for names containing a slash, because that won't work if we use
73 // the name for a socket in the file system.77 // the name for a socket in the file system.
74 if (scope_name.empty())
75 {
76 throw unity::InvalidArgumentException("Registry: Cannot add scope with empty name");
77 }
7878
79 lock_guard<decltype(mutex_)> lock(mutex_);79 lock_guard<decltype(mutex_)> lock(mutex_);
8080
81 auto const& pair = scopes_.insert(make_pair(scope_name, scope));81 auto const& pair = scopes_.insert(make_pair(scope_name, metadata));
82 if (!pair.second)82 if (!pair.second)
83 {83 {
84 // Replace already existing entry with this one
84 scopes_.erase(pair.first);85 scopes_.erase(pair.first);
85 scopes_.insert(make_pair(scope_name, scope));86 scopes_.insert(make_pair(scope_name, metadata));
86 return false;87 return false;
87 }88 }
88 return true;89 return true;
8990
=== modified file 'src/internal/ResultItemImpl.cpp'
--- src/internal/ResultItemImpl.cpp 2013-11-27 02:08:11 +0000
+++ src/internal/ResultItemImpl.cpp 2013-12-03 14:09:20 +0000
@@ -19,7 +19,6 @@
19#include <scopes/internal/ResultItemImpl.h>19#include <scopes/internal/ResultItemImpl.h>
20#include <unity/UnityExceptions.h>20#include <unity/UnityExceptions.h>
21#include <scopes/Category.h>21#include <scopes/Category.h>
22#include <sstream>
2322
24namespace unity23namespace unity
25{24{
@@ -113,9 +112,7 @@
113{112{
114 if (value.empty())113 if (value.empty())
115 {114 {
116 std::ostringstream s;115 throw InvalidArgumentException("ResultItem: invalid empty attribute: " + name);
117 s << "Required attribute " << name << " is empty";
118 throw InvalidArgumentException(s.str());
119 }116 }
120}117}
121118
@@ -139,9 +136,8 @@
139 {136 {
140 if (var.find(kv.first) != var.end())137 if (var.find(kv.first) != var.end())
141 {138 {
142 std::ostringstream s;139 throw InvalidArgumentException("ResultItemImpl::serialize(): Can't overwrite internal attribute: "
143 s << "Can't overwrite internal attribute: " << kv.first;140 + kv.first);
144 throw InvalidArgumentException(s.str());
145 }141 }
146 var[kv.first] = kv.second;142 var[kv.first] = kv.second;
147 }143 }
148144
=== modified file 'src/internal/RuntimeConfig.cpp'
--- src/internal/RuntimeConfig.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/RuntimeConfig.cpp 2013-12-03 14:09:20 +0000
@@ -46,22 +46,29 @@
46RuntimeConfig::RuntimeConfig(string const& configfile) :46RuntimeConfig::RuntimeConfig(string const& configfile) :
47 ConfigBase(configfile)47 ConfigBase(configfile)
48{48{
49 registry_identity_ = get_string(RUNTIME_CONFIG_GROUP, registry_identity_str);49 if (configfile.empty()) // Default config
50 auto pos = registry_identity_.find_first_of("@:/");50 {
51 if (pos != string::npos)51 registry_identity_ = "Registry";
52 {52 registry_configfile_ = "Registry.ini";
53 throw_ex("Illegal character in value for " + registry_identity_str + ": \"" + registry_identity_ +53 default_middleware_ = "Zmq";
54 "\": identity cannot contain '" + registry_identity_[pos] + "'");54 default_middleware_configfile_ = "";
55 }55 factory_configfile_ = "Factory.ini";
5656 }
57 registry_configfile_ = get_string(RUNTIME_CONFIG_GROUP, registry_configfile_str);57 else
5858 {
59 default_middleware_ = get_middleware(RUNTIME_CONFIG_GROUP, default_middleware_str);59 registry_identity_ = get_string(RUNTIME_CONFIG_GROUP, registry_identity_str);
6060 auto pos = registry_identity_.find_first_of("@:/");
61 default_middleware_configfile_ = get_string(RUNTIME_CONFIG_GROUP,61 if (pos != string::npos)
62 default_middleware_ + "." + default_middleware_configfile_str);62 {
6363 throw_ex("Illegal character in value for " + registry_identity_str + ": \"" + registry_identity_ +
64 factory_configfile_ = get_string(RUNTIME_CONFIG_GROUP, factory_configfile_str);64 "\": identity cannot contain '" + registry_identity_[pos] + "'");
65 }
66 registry_configfile_ = get_string(RUNTIME_CONFIG_GROUP, registry_configfile_str);
67 default_middleware_ = get_middleware(RUNTIME_CONFIG_GROUP, default_middleware_str);
68 default_middleware_configfile_ = get_string(RUNTIME_CONFIG_GROUP,
69 default_middleware_ + "." + default_middleware_configfile_str);
70 factory_configfile_ = get_string(RUNTIME_CONFIG_GROUP, factory_configfile_str);
71 }
65}72}
6673
67RuntimeConfig::~RuntimeConfig() noexcept74RuntimeConfig::~RuntimeConfig() noexcept
6875
=== modified file 'src/internal/RuntimeImpl.cpp'
--- src/internal/RuntimeImpl.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/RuntimeImpl.cpp 2013-12-03 14:09:20 +0000
@@ -56,8 +56,7 @@
56 RuntimeConfig config(configfile);56 RuntimeConfig config(configfile);
57 string default_middleware = config.default_middleware();57 string default_middleware = config.default_middleware();
58 string middleware_configfile = config.default_middleware_configfile();58 string middleware_configfile = config.default_middleware_configfile();
59 string factory_configfile = config.factory_configfile();59 middleware_factory_.reset(new MiddlewareFactory(this));
60 middleware_factory_.reset(new MiddlewareFactory(factory_configfile, this));
61 registry_configfile_ = config.registry_configfile();60 registry_configfile_ = config.registry_configfile();
62 registry_identity_ = config.registry_identity();61 registry_identity_ = config.registry_identity();
63 assert(!registry_identity_.empty());62 assert(!registry_identity_.empty());
6463
=== modified file 'src/internal/ScopeConfig.cpp'
--- src/internal/ScopeConfig.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/ScopeConfig.cpp 2013-12-03 14:09:20 +0000
@@ -18,6 +18,7 @@
1818
19#include <scopes/internal/ScopeConfig.h>19#include <scopes/internal/ScopeConfig.h>
2020
21#include <scopes/ScopeExceptions.h>
21#include <unity/UnityExceptions.h>22#include <unity/UnityExceptions.h>
2223
23using namespace std;24using namespace std;
@@ -37,6 +38,12 @@
37namespace38namespace
38{39{
39 const string overrideable_str = "Override";40 const string overrideable_str = "Override";
41 const string scope_name_str = "DisplayName";
42 const string description_str = "Description";
43 const string art_str = "Art";
44 const string icon_str = "Icon";
45 const string search_hint_str = "SearchHint";
46 const string hot_key_str = "HotKey";
40}47}
4148
42ScopeConfig::ScopeConfig(string const& configfile) :49ScopeConfig::ScopeConfig(string const& configfile) :
@@ -50,6 +57,44 @@
50 {57 {
51 overrideable_ = false;58 overrideable_ = false;
52 }59 }
60 display_name_ = parser()->get_string(SCOPE_CONFIG_GROUP, scope_name_str);
61 description_ = parser()->get_string(SCOPE_CONFIG_GROUP, description_str);
62
63 // For optional values, we store them in a unique_ptr so we can distinguish the "not set at all" case
64 // from the "explicitly set to empty string" case. parser()->get_string throws LogicException if
65 // the key is not present, so we ignore the exception for optional values.
66 try
67 {
68 string art = parser()->get_string(SCOPE_CONFIG_GROUP, art_str);
69 art_.reset(new string(art));
70 }
71 catch (LogicException const&)
72 {
73 }
74 try
75 {
76 string icon = parser()->get_string(SCOPE_CONFIG_GROUP, icon_str);
77 icon_.reset(new string(icon));
78 }
79 catch (LogicException const&)
80 {
81 }
82 try
83 {
84 string hint = parser()->get_string(SCOPE_CONFIG_GROUP, search_hint_str);
85 search_hint_.reset(new string(hint));
86 }
87 catch (LogicException const&)
88 {
89 }
90 try
91 {
92 string key = parser()->get_string(SCOPE_CONFIG_GROUP, hot_key_str);
93 hot_key_.reset(new string(key));
94 }
95 catch (LogicException const&)
96 {
97 }
53}98}
5499
55ScopeConfig::~ScopeConfig() noexcept100ScopeConfig::~ScopeConfig() noexcept
@@ -61,6 +106,52 @@
61 return overrideable_;106 return overrideable_;
62}107}
63108
109string ScopeConfig::display_name() const
110{
111 return display_name_;
112}
113
114string ScopeConfig::description() const
115{
116 return description_;
117}
118
119string ScopeConfig::art() const
120{
121 if (!art_)
122 {
123 throw NotFoundException("Art not set", art_str);
124 }
125 return *art_;
126}
127
128string ScopeConfig::icon() const
129{
130 if (!icon_)
131 {
132 throw NotFoundException("Icon not set", icon_str);
133 }
134 return *icon_;
135}
136
137string ScopeConfig::search_hint() const
138{
139 if (!search_hint_)
140 {
141 throw NotFoundException("Hint not set", search_hint_str);
142 }
143 return *search_hint_;
144}
145
146string ScopeConfig::hot_key() const
147{
148 if (!hot_key_)
149 {
150 throw NotFoundException("Key not set", hot_key_str);
151 }
152 return *hot_key_;
153}
154
64} // namespace internal155} // namespace internal
65156
66} // namespace scopes157} // namespace scopes
67158
=== modified file 'src/internal/ScopeImpl.cpp'
--- src/internal/ScopeImpl.cpp 2013-11-25 19:05:41 +0000
+++ src/internal/ScopeImpl.cpp 2013-12-03 14:09:20 +0000
@@ -19,6 +19,7 @@
19#include <scopes/internal/ScopeImpl.h>19#include <scopes/internal/ScopeImpl.h>
2020
21#include <scopes/internal/MiddlewareBase.h>21#include <scopes/internal/MiddlewareBase.h>
22#include <scopes/internal/MWScope.h>
22#include <scopes/internal/QueryCtrlImpl.h>23#include <scopes/internal/QueryCtrlImpl.h>
23#include <scopes/Scope.h>24#include <scopes/Scope.h>
24#include <unity/Exception.h>25#include <unity/Exception.h>
2526
=== added file 'src/internal/ScopeMetadataImpl.cpp'
--- src/internal/ScopeMetadataImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/internal/ScopeMetadataImpl.cpp 2013-12-03 14:09:20 +0000
@@ -0,0 +1,325 @@
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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the Lesser 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/ScopeMetadataImpl.h>
20
21#include <scopes/internal/MiddlewareBase.h>
22#include <scopes/internal/ScopeImpl.h>
23#include <scopes/ScopeExceptions.h>
24#include <unity/UnityExceptions.h>
25
26using namespace std;
27using namespace unity;
28
29namespace unity
30{
31
32namespace api
33{
34
35namespace scopes
36{
37
38namespace internal
39{
40
41ScopeMetadataImpl::ScopeMetadataImpl(MiddlewareBase* mw) :
42 mw_(mw)
43{
44}
45
46ScopeMetadataImpl::ScopeMetadataImpl(const VariantMap& variant_map, MiddlewareBase* mw) :
47 mw_(mw)
48{
49 deserialize(variant_map);
50}
51
52ScopeMetadataImpl::ScopeMetadataImpl(ScopeMetadataImpl const& other) :
53 scope_name_(other.scope_name_),
54 proxy_(other.proxy_),
55 display_name_(other.display_name_),
56 description_(other.description_)
57{
58 if (other.art_)
59 {
60 art_.reset(new string(*other.art_));
61 }
62 if (other.icon_)
63 {
64 icon_.reset(new string(*other.icon_));
65 }
66 if (other.search_hint_)
67 {
68 search_hint_.reset(new string(*other.search_hint_));
69 }
70 if (other.hot_key_)
71 {
72 hot_key_.reset(new string(*other.hot_key_));
73 }
74}
75
76ScopeMetadataImpl& ScopeMetadataImpl::operator=(ScopeMetadataImpl const& rhs)
77{
78 if (this != &rhs)
79 {
80 scope_name_ = rhs.scope_name_;
81 proxy_ = rhs.proxy_;
82 display_name_ = rhs.display_name_;
83 description_ = rhs.description_;
84 art_.reset(rhs.art_ ? new string(*rhs.art_) : nullptr);
85 icon_.reset(rhs.icon_ ? new string(*rhs.icon_) : nullptr);
86 search_hint_.reset(rhs.search_hint_ ? new string(*rhs.search_hint_) : nullptr);
87 hot_key_.reset(rhs.hot_key_ ? new string(*rhs.hot_key_) : nullptr);
88 }
89 return *this;
90}
91
92std::string ScopeMetadataImpl::scope_name() const
93{
94 return scope_name_;
95}
96
97ScopeProxy ScopeMetadataImpl::proxy() const
98{
99 return proxy_;
100}
101
102std::string ScopeMetadataImpl::display_name() const
103{
104 return display_name_;
105}
106
107std::string ScopeMetadataImpl::description() const
108{
109 return description_;
110}
111
112std::string ScopeMetadataImpl::art() const
113{
114 if (art_)
115 {
116 return *art_;
117 }
118 throw NotFoundException("attribute not set", "art");
119}
120
121std::string ScopeMetadataImpl::icon() const
122{
123 if (icon_)
124 {
125 return *icon_;
126 }
127 throw NotFoundException("attribute not set", "icon");
128}
129
130std::string ScopeMetadataImpl::search_hint() const
131{
132 if (search_hint_)
133 {
134 return *search_hint_;
135 }
136 throw NotFoundException("attribute not set", "search_hint");
137}
138
139std::string ScopeMetadataImpl::hot_key() const
140{
141 if (hot_key_)
142 {
143 return *hot_key_;
144 }
145 throw NotFoundException("attribute not set", "hot_key");
146}
147
148void ScopeMetadataImpl::set_scope_name(std::string const& scope_name)
149{
150 scope_name_ = scope_name;
151}
152
153void ScopeMetadataImpl::set_proxy(ScopeProxy const& proxy)
154{
155 proxy_ = proxy;
156}
157
158void ScopeMetadataImpl::set_display_name(std::string const& display_name)
159{
160 display_name_ = display_name;
161}
162
163void ScopeMetadataImpl::set_description(std::string const& description)
164{
165 description_ = description;
166}
167
168void ScopeMetadataImpl::set_art(std::string const& art)
169{
170 art_.reset(new string(art));
171}
172
173void ScopeMetadataImpl::set_icon(std::string const& icon)
174{
175 icon_.reset(new string(icon));
176}
177
178void ScopeMetadataImpl::set_search_hint(std::string const& search_hint)
179{
180 search_hint_.reset(new string(search_hint));
181}
182
183void ScopeMetadataImpl::set_hot_key(std::string const& hot_key)
184{
185 hot_key_.reset(new string(hot_key));
186}
187
188namespace
189{
190
191void throw_on_empty(std::string const& name, std::string const& value)
192{
193 if (value.empty())
194 {
195 throw InvalidArgumentException("ScopeMetadata: required attribute '" + name + "' is empty");
196 }
197}
198
199} // namespace
200
201VariantMap ScopeMetadataImpl::serialize() const
202{
203 throw_on_empty("scope_name", scope_name_);
204 if (!proxy_)
205 {
206 throw InvalidArgumentException("ScopeMetadataImpl::serialize(): required attribute 'proxy' is null");
207 }
208 throw_on_empty("display_name", display_name_);
209 throw_on_empty("description", description_);
210
211 VariantMap var;
212 var["scope_name"] = scope_name_;
213 VariantMap proxy;
214 proxy["identity"] = proxy_->identity();
215 proxy["endpoint"] = proxy_->endpoint();
216 var["proxy"] = proxy;
217 var["display_name"] = display_name_;
218 var["description"] = description_;
219
220 // Optional fields
221 if (art_)
222 {
223 var["art"] = *art_;
224 }
225 if (icon_)
226 {
227 var["icon"] = *icon_;
228 }
229 if (search_hint_)
230 {
231 var["search_hint"] = *search_hint_;
232 }
233 if (hot_key_)
234 {
235 var["hot_key"] = *hot_key_;
236 }
237
238 return var;
239}
240
241namespace
242{
243
244VariantMap::const_iterator find_or_throw(VariantMap const& var, std::string const& name)
245{
246 auto it = var.find(name);
247 if (it == var.end())
248 {
249 throw InvalidArgumentException("ScopeMetadata::deserialize(): required attribute '" + name + "' is missing");
250 }
251 return it;
252}
253
254} // namespace
255
256void ScopeMetadataImpl::deserialize(VariantMap const& var)
257{
258 auto it = find_or_throw(var, "scope_name");
259 scope_name_ = it->second.get_string();
260 throw_on_empty("scope_name", scope_name_);
261
262 it = find_or_throw(var, "proxy");
263 auto proxy = it->second.get_dict();
264 auto it2 = proxy.find("identity");
265 if (it2 == proxy.end())
266 {
267 throw InvalidArgumentException("ScopeMetadataImpl::deserialize(): missing 'proxy.identity'");
268 }
269 auto identity = it2->second.get_string();
270 throw_on_empty("proxy.identity", identity);
271 it2 = proxy.find("endpoint");
272 if (it2 == proxy.end())
273 {
274 throw InvalidArgumentException("ScopeMetadataImpl::deserialize(): missing 'proxy.endpoint'");
275 }
276 auto endpoint = it2->second.get_string();
277 throw_on_empty("proxy.endpoint", endpoint);
278 auto mw_proxy = mw_->create_scope_proxy(identity, endpoint);
279 proxy_ = ScopeImpl::create(mw_proxy, mw_->runtime());
280
281 it = find_or_throw(var, "display_name");
282 display_name_ = it->second.get_string();
283
284 it = find_or_throw(var, "description");
285 description_ = it->second.get_string();
286
287 // Optional fields
288
289 it = var.find("art");
290 if (it != var.end())
291 {
292 art_.reset(new string(it->second.get_string()));
293 }
294
295 it = var.find("icon");
296 if (it != var.end())
297 {
298 icon_.reset(new string(it->second.get_string()));
299 }
300
301 it = var.find("search_hint");
302 if (it != var.end())
303 {
304 search_hint_.reset(new string(it->second.get_string()));
305 }
306
307 it = var.find("hot_key");
308 if (it != var.end())
309 {
310 hot_key_.reset(new string(it->second.get_string()));
311 }
312}
313
314ScopeMetadata ScopeMetadataImpl::create(unique_ptr<ScopeMetadataImpl> impl)
315{
316 return ScopeMetadata(move(impl));
317}
318
319} // namespace internal
320
321} // namespace scopes
322
323} // namespace api
324
325} // namespace unity
0326
=== modified file 'src/internal/zmq_middleware/RegistryI.cpp'
--- src/internal/zmq_middleware/RegistryI.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/zmq_middleware/RegistryI.cpp 2013-12-03 14:09:20 +0000
@@ -21,6 +21,7 @@
21#include <internal/zmq_middleware/capnproto/Registry.capnp.h>21#include <internal/zmq_middleware/capnproto/Registry.capnp.h>
22#include <internal/zmq_middleware/capnproto/Scope.capnp.h>22#include <internal/zmq_middleware/capnproto/Scope.capnp.h>
23#include <scopes/internal/zmq_middleware/ObjectAdapter.h>23#include <scopes/internal/zmq_middleware/ObjectAdapter.h>
24#include <scopes/internal/zmq_middleware/VariantConverter.h>
24#include <scopes/internal/zmq_middleware/ZmqScope.h>25#include <scopes/internal/zmq_middleware/ZmqScope.h>
25#include <scopes/internal/RegistryObject.h>26#include <scopes/internal/RegistryObject.h>
26#include <scopes/ScopeExceptions.h>27#include <scopes/ScopeExceptions.h>
@@ -48,7 +49,7 @@
4849
49interface Scope;50interface Scope;
5051
51dictionary<string, Scope*> ScopeDictMap;52dictionary<string, VariantMap> MetadataMap;
5253
53exception NotFoundException54exception NotFoundException
54{55{
@@ -57,8 +58,8 @@
5758
58interface Registry59interface Registry
59{60{
60 Scope* find(string name) throws NotFoundException;61 Scope* get_metadata(string name) throws NotFoundException;
61 ScopeDict list();62 ScopeMap list();
62};63};
6364
64*/65*/
@@ -66,7 +67,7 @@
66using namespace std::placeholders;67using namespace std::placeholders;
6768
68RegistryI::RegistryI(RegistryObject::SPtr const& ro) :69RegistryI::RegistryI(RegistryObject::SPtr const& ro) :
69 ServantBase(ro, { { "find", bind(&RegistryI::find_, this, _1, _2, _3) },70 ServantBase(ro, { { "get_metadata", bind(&RegistryI::get_metadata_, this, _1, _2, _3) },
70 { "list", bind(&RegistryI::list_, this, _1, _2, _3) } })71 { "list", bind(&RegistryI::list_, this, _1, _2, _3) } })
7172
72{73{
@@ -76,28 +77,26 @@
76{77{
77}78}
7879
79void RegistryI::find_(Current const&,80void RegistryI::get_metadata_(Current const&,
80 capnp::ObjectPointer::Reader& in_params,81 capnp::ObjectPointer::Reader& in_params,
81 capnproto::Response::Builder& r)82 capnproto::Response::Builder& r)
82{83{
83 auto req = in_params.getAs<capnproto::Registry::FindRequest>();84 auto req = in_params.getAs<capnproto::Registry::GetMetadataRequest>();
84 string name = req.getName().cStr();85 string name = req.getName().cStr();
85 auto delegate = dynamic_pointer_cast<RegistryObject>(del());86 auto delegate = dynamic_pointer_cast<RegistryObject>(del());
86 try87 try
87 {88 {
88 auto proxy = dynamic_pointer_cast<ZmqObjectProxy>(delegate->find(name));89 auto meta = delegate->get_metadata(name);
89 assert(proxy);
90 r.setStatus(capnproto::ResponseStatus::SUCCESS);90 r.setStatus(capnproto::ResponseStatus::SUCCESS);
91 auto find_response = r.initPayload().getAs<capnproto::Registry::FindResponse>().initResponse();91 auto get_metadata_response = r.initPayload().getAs<capnproto::Registry::GetMetadataResponse>().initResponse();
92 auto p = find_response.initReturnValue();92 auto dict = get_metadata_response.initReturnValue();
93 p.setEndpoint(proxy->endpoint().c_str());93 to_value_dict(meta.serialize(), dict);
94 p.setIdentity(proxy->identity().c_str());
95 }94 }
96 catch (NotFoundException const& e)95 catch (NotFoundException const& e)
97 {96 {
98 r.setStatus(capnproto::ResponseStatus::USER_EXCEPTION);97 r.setStatus(capnproto::ResponseStatus::USER_EXCEPTION);
99 auto find_response = r.initPayload().getAs<capnproto::Registry::FindResponse>().initResponse();98 auto get_metadata_response = r.initPayload().getAs<capnproto::Registry::GetMetadataResponse>().initResponse();
100 find_response.initNotFoundException().setName(e.name().c_str());99 get_metadata_response.initNotFoundException().setName(e.name().c_str());
101 }100 }
102}101}
103102
@@ -106,18 +105,14 @@
106 capnproto::Response::Builder& r)105 capnproto::Response::Builder& r)
107{106{
108 auto delegate = dynamic_pointer_cast<RegistryObject>(del());107 auto delegate = dynamic_pointer_cast<RegistryObject>(del());
109 auto scope_map = delegate->list();108 auto metadata_map = delegate->list();
110 r.setStatus(capnproto::ResponseStatus::SUCCESS);109 r.setStatus(capnproto::ResponseStatus::SUCCESS);
111 auto rv = r.initPayload().getAs<capnproto::Registry::ListResponse>().initReturnValue();110 auto rv = r.initPayload().getAs<capnproto::Registry::ListResponse>().initReturnValue(metadata_map.size());
112 auto list = rv.initPairs(scope_map.size());
113 int i = 0;111 int i = 0;
114 for (auto const& pair : scope_map)112 for (auto& pair : metadata_map)
115 {113 {
116 list[i].setName(pair.first.c_str());114 auto dict = rv[i];
117 auto p = list[i].initScopeProxy();115 to_value_dict(pair.second.serialize(), dict);
118 auto sp = dynamic_pointer_cast<ZmqScope>(pair.second);
119 p.setEndpoint(sp->endpoint().c_str());
120 p.setIdentity(sp->identity().c_str());
121 ++i;116 ++i;
122 }117 }
123}118}
124119
=== modified file 'src/internal/zmq_middleware/ZmqConfig.cpp'
--- src/internal/zmq_middleware/ZmqConfig.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/zmq_middleware/ZmqConfig.cpp 2013-12-03 14:09:20 +0000
@@ -43,10 +43,16 @@
43ZmqConfig::ZmqConfig(string const& configfile) :43ZmqConfig::ZmqConfig(string const& configfile) :
44 ConfigBase(configfile)44 ConfigBase(configfile)
45{45{
46 public_dir_ = get_string(ZMQ_CONFIG_GROUP, public_dir_str);46 if (configfile.empty())
4747 {
48 // Private directory is not needed by all processes. It is retrieved48 public_dir_ = "/tmp";
49 // on demand during adapter creation.49 private_dir_ = "/tmp";
50 }
51 else
52 {
53 public_dir_ = get_string(ZMQ_CONFIG_GROUP, public_dir_str);
54 private_dir_ = get_string(ZMQ_CONFIG_GROUP, private_dir_str);
55 }
50}56}
5157
52ZmqConfig::~ZmqConfig() noexcept58ZmqConfig::~ZmqConfig() noexcept
@@ -60,11 +66,6 @@
6066
61string ZmqConfig::private_dir() const67string ZmqConfig::private_dir() const
62{68{
63 lock_guard<mutex> lock(mutex_);
64 if (private_dir_.empty()) // Initialize first time only
65 {
66 private_dir_ = get_string(ZMQ_CONFIG_GROUP, private_dir_str);
67 }
68 return private_dir_;69 return private_dir_;
69}70}
7071
7172
=== modified file 'src/internal/zmq_middleware/ZmqMiddleware.cpp'
--- src/internal/zmq_middleware/ZmqMiddleware.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/zmq_middleware/ZmqMiddleware.cpp 2013-12-03 14:09:20 +0000
@@ -164,6 +164,20 @@
164 state_changed_.wait(lock, [this] { return state_ == Stopped; }); // LCOV_EXCL_LINE164 state_changed_.wait(lock, [this] { return state_ == Stopped; }); // LCOV_EXCL_LINE
165}165}
166166
167MWProxy ZmqMiddleware::create_proxy(string const& identity, string const& endpoint)
168{
169 MWProxy proxy;
170 try
171 {
172 proxy.reset(new ZmqObjectProxy(this, endpoint, identity));
173 }
174 catch (zmqpp::exception const& e)
175 {
176 rethrow_zmq_ex(e);
177 }
178 return proxy;
179}
180
167MWRegistryProxy ZmqMiddleware::create_registry_proxy(string const& identity, string const& endpoint)181MWRegistryProxy ZmqMiddleware::create_registry_proxy(string const& identity, string const& endpoint)
168{182{
169 MWRegistryProxy proxy;183 MWRegistryProxy proxy;
170184
=== modified file 'src/internal/zmq_middleware/ZmqObject.cpp'
--- src/internal/zmq_middleware/ZmqObject.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/zmq_middleware/ZmqObject.cpp 2013-12-03 14:09:20 +0000
@@ -44,6 +44,16 @@
4444
45#define MONITOR_ENDPOINT "ipc:///tmp/scopes-monitor"45#define MONITOR_ENDPOINT "ipc:///tmp/scopes-monitor"
4646
47ZmqObjectProxy::ZmqObjectProxy(ZmqMiddleware* mw_base, string const& endpoint, string const& identity) :
48 MWObjectProxy(mw_base),
49 endpoint_(endpoint),
50 identity_(identity),
51 type_(Unknown)
52{
53 assert(!endpoint.empty());
54 assert(!identity.empty());
55}
56
47ZmqObjectProxy::ZmqObjectProxy(ZmqMiddleware* mw_base, string const& endpoint, string const& identity, RequestType t) :57ZmqObjectProxy::ZmqObjectProxy(ZmqMiddleware* mw_base, string const& endpoint, string const& identity, RequestType t) :
48 MWObjectProxy(mw_base),58 MWObjectProxy(mw_base),
49 endpoint_(endpoint),59 endpoint_(endpoint),
@@ -52,6 +62,7 @@
52{62{
53 assert(!endpoint.empty());63 assert(!endpoint.empty());
54 assert(!identity.empty());64 assert(!identity.empty());
65 assert(t != Unknown);
55}66}
5667
57ZmqObjectProxy::~ZmqObjectProxy() noexcept68ZmqObjectProxy::~ZmqObjectProxy() noexcept
5869
=== modified file 'src/internal/zmq_middleware/ZmqRegistry.cpp'
--- src/internal/zmq_middleware/ZmqRegistry.cpp 2013-11-21 21:44:00 +0000
+++ src/internal/zmq_middleware/ZmqRegistry.cpp 2013-12-03 14:09:20 +0000
@@ -19,9 +19,11 @@
19#include <scopes/internal/zmq_middleware/ZmqRegistry.h>19#include <scopes/internal/zmq_middleware/ZmqRegistry.h>
2020
21#include <internal/zmq_middleware/capnproto/Registry.capnp.h>21#include <internal/zmq_middleware/capnproto/Registry.capnp.h>
22#include <scopes/internal/zmq_middleware/VariantConverter.h>
22#include <scopes/internal/zmq_middleware/ZmqException.h>23#include <scopes/internal/zmq_middleware/ZmqException.h>
23#include <scopes/internal/zmq_middleware/ZmqScope.h>24#include <scopes/internal/zmq_middleware/ZmqScope.h>
24#include <scopes/internal/ScopeImpl.h>25#include <scopes/internal/ScopeImpl.h>
26#include <scopes/internal/ScopeMetadataImpl.h>
25#include <scopes/ScopeExceptions.h>27#include <scopes/ScopeExceptions.h>
2628
27#include <capnp/message.h>29#include <capnp/message.h>
@@ -47,7 +49,7 @@
4749
48interface Scope;50interface Scope;
4951
50dictionary<string, Scope*> ScopeDictMap;52dictionary<string, ScopeMetadata> MetadataMap;
5153
52exception NotFoundException54exception NotFoundException
53{55{
@@ -56,7 +58,7 @@
5658
57interface Registry59interface Registry
58{60{
59 Scope* find(string name) throws NotFoundException;61 ScopeMetadata get_metadata(string name) throws NotFoundException;
60 ScopeDict list();62 ScopeDict list();
61};63};
6264
@@ -73,11 +75,11 @@
73{75{
74}76}
7577
76ScopeProxy ZmqRegistry::find(std::string const& scope_name)78ScopeMetadata ZmqRegistry::get_metadata(std::string const& scope_name)
77{79{
78 capnp::MallocMessageBuilder request_builder;80 capnp::MallocMessageBuilder request_builder;
79 auto request = make_request_(request_builder, "find");81 auto request = make_request_(request_builder, "get_metadata");
80 auto in_params = request.initInParams().getAs<capnproto::Registry::FindRequest>();82 auto in_params = request.initInParams().getAs<capnproto::Registry::GetMetadataRequest>();
81 in_params.setName(scope_name.c_str());83 in_params.setName(scope_name.c_str());
8284
83 auto future = mw_base()->invoke_pool()->submit([&] { return this->invoke_(request_builder); });85 auto future = mw_base()->invoke_pool()->submit([&] { return this->invoke_(request_builder); });
@@ -88,28 +90,30 @@
88 auto response = reader.getRoot<capnproto::Response>();90 auto response = reader.getRoot<capnproto::Response>();
89 throw_if_runtime_exception(response);91 throw_if_runtime_exception(response);
9092
91 auto find_response = response.getPayload().getAs<capnproto::Registry::FindResponse>().getResponse();93 auto get_metadata_response = response.getPayload().getAs<capnproto::Registry::GetMetadataResponse>().getResponse();
92 switch (find_response.which())94 switch (get_metadata_response.which())
93 {95 {
94 case capnproto::Registry::FindResponse::Response::RETURN_VALUE:96 case capnproto::Registry::GetMetadataResponse::Response::RETURN_VALUE:
95 {97 {
96 auto proxy = find_response.getReturnValue();98 auto md = get_metadata_response.getReturnValue();
97 ZmqScopeProxy p(new ZmqScope(mw_base(), proxy.getEndpoint().cStr(), proxy.getIdentity().cStr()));99 VariantMap m = to_variant_map(md);
98 return ScopeImpl::create(p, mw_base()->runtime());100 unique_ptr<ScopeMetadataImpl> smdi(new ScopeMetadataImpl(mw_base()));
101 smdi->deserialize(m);
102 return ScopeMetadata(ScopeMetadataImpl::create(move(smdi)));
99 }103 }
100 case capnproto::Registry::FindResponse::Response::NOT_FOUND_EXCEPTION:104 case capnproto::Registry::GetMetadataResponse::Response::NOT_FOUND_EXCEPTION:
101 {105 {
102 auto ex = find_response.getNotFoundException();106 auto ex = get_metadata_response.getNotFoundException();
103 throw NotFoundException("Registry::find(): no such scope", ex.getName().cStr());107 throw NotFoundException("Registry::get_metadata(): no such scope", ex.getName().cStr());
104 }108 }
105 default:109 default:
106 {110 {
107 throw MiddlewareException("Registry::find(): unknown user exception");111 throw MiddlewareException("Registry::get_metadata(): unknown user exception");
108 }112 }
109 }113 }
110}114}
111115
112ScopeMap ZmqRegistry::list()116MetadataMap ZmqRegistry::list()
113{117{
114 capnp::MallocMessageBuilder request_builder;118 capnp::MallocMessageBuilder request_builder;
115 make_request_(request_builder, "list");119 make_request_(request_builder, "list");
@@ -123,13 +127,16 @@
123 throw_if_runtime_exception(response);127 throw_if_runtime_exception(response);
124128
125 auto list_response = response.getPayload().getAs<capnproto::Registry::ListResponse>();129 auto list_response = response.getPayload().getAs<capnproto::Registry::ListResponse>();
126 auto pairs = list_response.getReturnValue().getPairs();130 auto list = list_response.getReturnValue();
127 ScopeMap sm;131 MetadataMap sm;
128 for (size_t i = 0; i < pairs.size(); ++i)132 for (size_t i = 0; i < list.size(); ++i)
129 {133 {
130 auto proxy = pairs[i].getScopeProxy();134 VariantMap m = to_variant_map(list[i]);
131 ZmqScopeProxy p(new ZmqScope(mw_base(), proxy.getEndpoint().cStr(), proxy.getIdentity().cStr()));135 string scope_name = m["scope_name"].get_string();
132 sm[pairs[i].getName().cStr()] = ScopeImpl::create(p, mw_base()->runtime());136 unique_ptr<ScopeMetadataImpl> smdi(new ScopeMetadataImpl(mw_base()));
137 smdi->deserialize(m);
138 ScopeMetadata d(ScopeMetadataImpl::create(move(smdi)));
139 sm.emplace(make_pair(move(scope_name), move(d)));
133 }140 }
134 return sm;141 return sm;
135}142}
136143
=== modified file 'src/internal/zmq_middleware/capnproto/Registry.capnp'
--- src/internal/zmq_middleware/capnproto/Registry.capnp 2013-09-17 08:02:23 +0000
+++ src/internal/zmq_middleware/capnproto/Registry.capnp 2013-12-03 14:09:20 +0000
@@ -22,31 +22,31 @@
2222
23$Cxx.namespace("unity::api::scopes::internal::zmq_middleware::capnproto::Registry");23$Cxx.namespace("unity::api::scopes::internal::zmq_middleware::capnproto::Registry");
2424
25using ScopeDict = import "ScopeDict.capnp";25using ValueDict = import "ValueDict.capnp";
26using Proxy = import "Proxy.capnp";26using Proxy = import "Proxy.capnp";
2727
28# Registry interface28# Registry interface
29#29#
30# Operations:30# Operations:
31#31#
32# Proxy find(string name) throws NotFoundException;32# ValueDict get_metadata(string name) throws NotFoundException;
33# ScopeDict list();33# map<string, ScopeMetadata> list();
3434
35struct NotFoundException35struct NotFoundException
36{36{
37 name @0 : Text;37 name @0 : Text;
38}38}
3939
40struct FindRequest40struct GetMetadataRequest
41{41{
42 name @0 : Text;42 name @0 : Text;
43}43}
4444
45struct FindResponse45struct GetMetadataResponse
46{46{
47 response : union47 response : union
48 {48 {
49 returnValue @0 : Proxy.Proxy;49 returnValue @0 : ValueDict.ValueDict;
50 notFoundException @1 : NotFoundException;50 notFoundException @1 : NotFoundException;
51 }51 }
52}52}
@@ -57,5 +57,5 @@
5757
58struct ListResponse58struct ListResponse
59{59{
60 returnValue @0 : ScopeDict.ScopeDict;60 returnValue @0 : List(ValueDict.ValueDict);
61}61}
6262
=== modified file 'test/gtest/unity/api/scopes/ResultItem/ResultItem_test.cpp'
--- test/gtest/unity/api/scopes/ResultItem/ResultItem_test.cpp 2013-11-27 10:44:35 +0000
+++ test/gtest/unity/api/scopes/ResultItem/ResultItem_test.cpp 2013-12-03 14:09:20 +0000
@@ -116,6 +116,15 @@
116 EXPECT_EQ("dnd_uri b", copy.dnd_uri());116 EXPECT_EQ("dnd_uri b", copy.dnd_uri());
117 EXPECT_EQ("xyz", copy.serialize()["foo"].get_string());117 EXPECT_EQ("xyz", copy.serialize()["foo"].get_string());
118 EXPECT_EQ("1", copy.category()->id());118 EXPECT_EQ("1", copy.category()->id());
119
120 ResultItem copy2(cat);
121 copy2 = copy;
122 EXPECT_EQ("uri b", copy2.uri());
123 EXPECT_EQ("title b", copy2.title());
124 EXPECT_EQ("icon b", copy2.art());
125 EXPECT_EQ("dnd_uri b", copy2.dnd_uri());
126 EXPECT_EQ("xyz", copy2.serialize()["foo"].get_string());
127 EXPECT_EQ("1", copy2.category()->id());
119 }128 }
120}129}
121130
122131
=== modified file 'test/gtest/unity/api/scopes/Runtime/CMakeLists.txt'
--- test/gtest/unity/api/scopes/Runtime/CMakeLists.txt 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/Runtime/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -1,4 +1,3 @@
1configure_file(Factory.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Factory.ini)
2configure_file(Registry.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Registry.ini)1configure_file(Registry.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Registry.ini)
3configure_file(Runtime.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Runtime.ini)2configure_file(Runtime.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Runtime.ini)
4configure_file(Zmq.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Zmq.ini)3configure_file(Zmq.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Zmq.ini)
54
=== removed file 'test/gtest/unity/api/scopes/Runtime/Factory.ini.in'
--- test/gtest/unity/api/scopes/Runtime/Factory.ini.in 2013-09-17 08:02:23 +0000
+++ test/gtest/unity/api/scopes/Runtime/Factory.ini.in 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1[MiddlewareFactory]
2Zmq.Configfile =
30
=== modified file 'test/gtest/unity/api/scopes/Variant/Variant_test.cpp'
--- test/gtest/unity/api/scopes/Variant/Variant_test.cpp 2013-11-19 15:35:07 +0000
+++ test/gtest/unity/api/scopes/Variant/Variant_test.cpp 2013-12-03 14:09:20 +0000
@@ -106,6 +106,9 @@
106 v = 99;106 v = 99;
107 EXPECT_EQ(99, v.get_int());107 EXPECT_EQ(99, v.get_int());
108108
109 v = 10.5f;
110 EXPECT_TRUE(v.get_double() - 10.5f < 0.00001f);
111
109 v = false;112 v = false;
110 EXPECT_FALSE(v.get_bool());113 EXPECT_FALSE(v.get_bool());
111114
112115
=== modified file 'test/gtest/unity/api/scopes/internal/CMakeLists.txt'
--- test/gtest/unity/api/scopes/internal/CMakeLists.txt 2013-11-18 08:14:46 +0000
+++ test/gtest/unity/api/scopes/internal/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -3,12 +3,12 @@
3add_subdirectory(DynamicLoader)3add_subdirectory(DynamicLoader)
4add_subdirectory(lttng)4add_subdirectory(lttng)
5add_subdirectory(MiddlewareFactory)5add_subdirectory(MiddlewareFactory)
6add_subdirectory(MiddlewareFactoryConfig)
7add_subdirectory(Reaper)6add_subdirectory(Reaper)
8add_subdirectory(RegistryConfig)7add_subdirectory(RegistryConfig)
9add_subdirectory(RuntimeConfig)8add_subdirectory(RuntimeConfig)
10add_subdirectory(RuntimeImpl)9add_subdirectory(RuntimeImpl)
11add_subdirectory(ScopeLoader)10add_subdirectory(ScopeLoader)
11add_subdirectory(ScopeMetadataImpl)
12add_subdirectory(ThreadPool)12add_subdirectory(ThreadPool)
13add_subdirectory(ThreadSafeQueue)13add_subdirectory(ThreadSafeQueue)
14add_subdirectory(UniqueID)14add_subdirectory(UniqueID)
1515
=== modified file 'test/gtest/unity/api/scopes/internal/MiddlewareFactory/CMakeLists.txt'
--- test/gtest/unity/api/scopes/internal/MiddlewareFactory/CMakeLists.txt 2013-09-23 06:13:06 +0000
+++ test/gtest/unity/api/scopes/internal/MiddlewareFactory/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -1,5 +1,3 @@
1configure_file(Factory.ini.in Factory.ini)
2
3add_executable(MiddlewareFactory_test MiddlewareFactory_test.cpp)1add_executable(MiddlewareFactory_test MiddlewareFactory_test.cpp)
4target_link_libraries(MiddlewareFactory_test ${TESTLIBS})2target_link_libraries(MiddlewareFactory_test ${TESTLIBS})
53
64
=== removed file 'test/gtest/unity/api/scopes/internal/MiddlewareFactory/Factory.ini.in'
--- test/gtest/unity/api/scopes/internal/MiddlewareFactory/Factory.ini.in 2013-08-06 01:51:26 +0000
+++ test/gtest/unity/api/scopes/internal/MiddlewareFactory/Factory.ini.in 1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
1[MiddlewareFactory]
2Ice.Configfile = Ice.Config
3REST.Configfile = REST.Config
40
=== modified file 'test/gtest/unity/api/scopes/internal/MiddlewareFactory/MiddlewareFactory_test.cpp'
--- test/gtest/unity/api/scopes/internal/MiddlewareFactory/MiddlewareFactory_test.cpp 2013-11-01 12:44:48 +0000
+++ test/gtest/unity/api/scopes/internal/MiddlewareFactory/MiddlewareFactory_test.cpp 2013-12-03 14:09:20 +0000
@@ -27,10 +27,10 @@
2727
28TEST(MiddlewareFactory, basic)28TEST(MiddlewareFactory, basic)
29{29{
30 MiddlewareFactory f("Factory.ini", (RuntimeImpl*)0x1);30 MiddlewareFactory f((RuntimeImpl*)0x1);
31 EXPECT_EQ(nullptr, f.find("nosuchscope", "Ice"));31 EXPECT_EQ(nullptr, f.find("nosuchscope", "Zmq"));
32 MiddlewareBase::SPtr not_found;32 MiddlewareBase::SPtr not_found;
33 MiddlewareBase::SPtr mw = f.find("testscope", "Ice");33 MiddlewareBase::SPtr mw = f.find("testscope", "Zmq");
34 EXPECT_EQ(not_found, mw);34 EXPECT_EQ(not_found, mw);
35 mw = f.find("testscope", "NoSuchMiddleware");35 mw = f.find("testscope", "NoSuchMiddleware");
36 EXPECT_EQ(not_found, mw);36 EXPECT_EQ(not_found, mw);
@@ -40,8 +40,8 @@
40{40{
41 try41 try
42 {42 {
43 MiddlewareFactory f("Factory.ini", (RuntimeImpl*)0x1);43 MiddlewareFactory f((RuntimeImpl*)0x1);
44 f.create("somescope", "NoSuchMiddleware", "Ice.Config");44 f.create("somescope", "NoSuchMiddleware", "Zmq.ini");
45 FAIL();45 FAIL();
46 }46 }
47 catch (ConfigException const& e)47 catch (ConfigException const& e)
@@ -49,20 +49,3 @@
49 EXPECT_EQ("unity::api::scopes::ConfigException: Invalid middleware kind: NoSuchMiddleware", e.to_string());49 EXPECT_EQ("unity::api::scopes::ConfigException: Invalid middleware kind: NoSuchMiddleware", e.to_string());
50 }50 }
51}51}
52
53TEST(MiddlewareFactory, BadIniFile)
54{
55 try
56 {
57 MiddlewareFactory f("NoSuchFile.ini", (RuntimeImpl*)0x1);
58 FAIL();
59 }
60 catch (ConfigException const& e)
61 {
62 EXPECT_EQ("unity::api::scopes::ConfigException: cannot instantiate MiddlewareFactory: "
63 "config file: NoSuchFile.ini:\n"
64 " unity::FileException: Could not load ini file NoSuchFile.ini: "
65 "No such file or directory (errno = 4)",
66 e.to_string());
67 }
68}
6952
=== removed directory 'test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig'
=== removed file 'test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/CMakeLists.txt'
--- test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/CMakeLists.txt 2013-08-06 01:51:26 +0000
+++ test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/CMakeLists.txt 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1configure_file(Factory.ini.in Factory.ini)
2
3add_executable(MiddlewareFactoryConfig_test MiddlewareFactoryConfig_test.cpp)
4target_link_libraries(MiddlewareFactoryConfig_test ${TESTLIBS})
5
6add_test(MiddlewareFactoryConfig MiddlewareFactoryConfig_test)
70
=== removed file 'test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/Factory.ini.in'
--- test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/Factory.ini.in 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/Factory.ini.in 1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
1[MiddlewareFactory]
2Zmq.ConfigFile = Zmq.ini
3REST.ConfigFile = REST.ini
40
=== removed file 'test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/MiddlewareFactoryConfig_test.cpp'
--- test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/MiddlewareFactoryConfig_test.cpp 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/internal/MiddlewareFactoryConfig/MiddlewareFactoryConfig_test.cpp 1970-01-01 00:00:00 +0000
@@ -1,31 +0,0 @@
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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser 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/MiddlewareFactoryConfig.h>
20
21#include <gtest/gtest.h>
22
23using namespace std;
24using namespace unity::api::scopes::internal;
25
26TEST(MiddlewareFactoryConfig, basic)
27{
28 MiddlewareFactoryConfig c("Factory.ini");
29 EXPECT_EQ("Zmq.ini", c.zmq_configfile());
30 EXPECT_EQ("REST.ini", c.rest_configfile());
31}
320
=== modified file 'test/gtest/unity/api/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp'
--- test/gtest/unity/api/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp 2013-12-03 14:09:20 +0000
@@ -27,7 +27,7 @@
2727
28TEST(RuntimeConfig, basic)28TEST(RuntimeConfig, basic)
29{29{
30 RuntimeConfig c;30 RuntimeConfig c("");
31 EXPECT_EQ("Registry", c.registry_identity());31 EXPECT_EQ("Registry", c.registry_identity());
32 EXPECT_EQ("Registry.ini", c.registry_configfile());32 EXPECT_EQ("Registry.ini", c.registry_configfile());
33 EXPECT_EQ("Zmq", c.default_middleware());33 EXPECT_EQ("Zmq", c.default_middleware());
3434
=== modified file 'test/gtest/unity/api/scopes/internal/RuntimeImpl/CMakeLists.txt'
--- test/gtest/unity/api/scopes/internal/RuntimeImpl/CMakeLists.txt 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/internal/RuntimeImpl/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -1,4 +1,3 @@
1configure_file(Factory.ini.in Factory.ini)
2configure_file(Zmq.ini.in Zmq.ini)1configure_file(Zmq.ini.in Zmq.ini)
3configure_file(Registry.ini.in Registry.ini)2configure_file(Registry.ini.in Registry.ini)
4configure_file(Runtime.ini.in Runtime.ini)3configure_file(Runtime.ini.in Runtime.ini)
54
=== removed file 'test/gtest/unity/api/scopes/internal/RuntimeImpl/Factory.ini.in'
--- test/gtest/unity/api/scopes/internal/RuntimeImpl/Factory.ini.in 2013-08-05 06:02:03 +0000
+++ test/gtest/unity/api/scopes/internal/RuntimeImpl/Factory.ini.in 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1[MiddlewareFactory]
2Ice.Configfile =
30
=== modified file 'test/gtest/unity/api/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp'
--- test/gtest/unity/api/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp 2013-12-03 14:09:20 +0000
@@ -29,7 +29,6 @@
2929
30TEST(RuntimeImpl, basic)30TEST(RuntimeImpl, basic)
31{31{
32try{
33 RuntimeImpl::UPtr rt = RuntimeImpl::create("testscope");32 RuntimeImpl::UPtr rt = RuntimeImpl::create("testscope");
3433
35 EXPECT_TRUE(rt->registry().get() != nullptr);34 EXPECT_TRUE(rt->registry().get() != nullptr);
@@ -61,11 +60,6 @@
61 e.to_string());60 e.to_string());
62 }61 }
63}62}
64catch(unity::Exception const& e)
65{
66 cout << e.to_string() << endl;
67}
68}
6963
70TEST(RuntimeImpl, error)64TEST(RuntimeImpl, error)
71{65{
7266
=== added directory 'test/gtest/unity/api/scopes/internal/ScopeMetadataImpl'
=== added file 'test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/CMakeLists.txt'
--- test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -0,0 +1,6 @@
1configure_file(Zmq.ini.in Zmq.ini)
2
3add_executable(ScopeMetadataImpl_test ScopeMetadataImpl_test.cpp)
4target_link_libraries(ScopeMetadataImpl_test ${TESTLIBS})
5
6add_test(ScopeMetadataImpl ScopeMetadataImpl_test)
07
=== added file 'test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/ScopeMetadataImpl_test.cpp'
--- test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/ScopeMetadataImpl_test.cpp 1970-01-01 00:00:00 +0000
+++ test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/ScopeMetadataImpl_test.cpp 2013-12-03 14:09:20 +0000
@@ -0,0 +1,388 @@
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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/lzmqnses/>.
15 *
16 * Authored by: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <scopes/internal/ScopeMetadataImpl.h>
20
21#include <scopes/internal/ScopeImpl.h>
22#include <scopes/internal/zmq_middleware/ZmqMiddleware.h>
23#include <scopes/ScopeExceptions.h>
24#include <unity/UnityExceptions.h>
25
26#include <boost/regex.hpp> // Use Boost implementation until http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 is fixed.
27#include <gtest/gtest.h>
28#include <scope-api-testconfig.h>
29
30using namespace std;
31using namespace unity;
32using namespace unity::api::scopes;
33using namespace unity::api::scopes::internal;
34using namespace unity::api::scopes::internal::zmq_middleware;
35
36TEST(ScopeMetadataImpl, basic)
37{
38 ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini",
39 (RuntimeImpl*)0x1);
40
41 unique_ptr<ScopeMetadataImpl> mi(new ScopeMetadataImpl(&mw));
42 mi->set_scope_name("scope_name");
43 auto mw_proxy = mw.create_scope_proxy("identity", "endpoint");
44 mi->set_proxy(ScopeImpl::create(mw_proxy, mw.runtime()));
45 mi->set_display_name("display_name");
46 mi->set_description("description");
47
48 // Keep a copy for tests below
49 unique_ptr<ScopeMetadataImpl> mi2(new ScopeMetadataImpl(*mi));
50
51 // Create the public instance and check that the values match
52 auto m = ScopeMetadataImpl::create(move(mi));
53 EXPECT_EQ("scope_name", m.scope_name());
54 EXPECT_EQ("identity", m.proxy()->identity());
55 EXPECT_EQ("endpoint", m.proxy()->endpoint());
56 EXPECT_EQ("display_name", m.display_name());
57 EXPECT_EQ("description", m.description());
58
59 // Check that optional fields that are not set throw
60 try
61 {
62 m.art();
63 FAIL();
64 }
65 catch (NotFoundException const& e)
66 {
67 EXPECT_EQ("unity::api::scopes::NotFoundException: attribute not set (name = art)", e.to_string());
68 }
69
70 try
71 {
72 m.icon();
73 FAIL();
74 }
75 catch (NotFoundException const& e)
76 {
77 EXPECT_EQ("unity::api::scopes::NotFoundException: attribute not set (name = icon)", e.to_string());
78 }
79
80 try
81 {
82 m.search_hint();
83 FAIL();
84 }
85 catch (NotFoundException const& e)
86 {
87 EXPECT_EQ("unity::api::scopes::NotFoundException: attribute not set (name = search_hint)", e.to_string());
88 }
89
90 try
91 {
92 m.hot_key();
93 FAIL();
94 }
95 catch (NotFoundException const& e)
96 {
97 EXPECT_EQ("unity::api::scopes::NotFoundException: attribute not set (name = hot_key)", e.to_string());
98 }
99
100 // Check that the copy has the same values as the original
101 EXPECT_EQ("scope_name", mi2->scope_name());
102 EXPECT_EQ("identity", mi2->proxy()->identity());
103 EXPECT_EQ("endpoint", mi2->proxy()->endpoint());
104 EXPECT_EQ("display_name", mi2->display_name());
105 EXPECT_EQ("description", mi2->description());
106
107 // Set optional fields on copy.
108 mi2->set_art("art");
109 mi2->set_icon("icon");
110 mi2->set_search_hint("search_hint");
111 mi2->set_hot_key("hot_key");
112
113 // Make another copy, so we get coverage on the entire copy constructor
114 unique_ptr<ScopeMetadataImpl> mi3(new ScopeMetadataImpl(*mi2));
115
116 // Check that optional fields are set correctly
117 m = ScopeMetadataImpl::create(move(mi2));
118 EXPECT_EQ("search_hint", m.search_hint());
119 EXPECT_EQ("hot_key", m.hot_key());
120
121 // Make another value
122 unique_ptr<ScopeMetadataImpl> ti(new ScopeMetadataImpl(&mw));
123 ti->set_scope_name("tmp scope_name");
124 mw_proxy = mw.create_scope_proxy("tmp identity", "tmp endpoint");
125 ti->set_proxy(ScopeImpl::create(mw_proxy, mw.runtime()));
126 ti->set_display_name("tmp display_name");
127 ti->set_description("tmp description");
128 ti->set_art("tmp art");
129 ti->set_icon("tmp icon");
130 ti->set_search_hint("tmp search_hint");
131 ti->set_hot_key("tmp hot_key");
132
133 // Check impl assignment operator
134 ScopeMetadataImpl ci(&mw);
135 ci = *ti;
136 EXPECT_EQ("tmp scope_name", ci.scope_name());
137 EXPECT_EQ("tmp identity", ci.proxy()->identity());
138 EXPECT_EQ("tmp endpoint", ci.proxy()->endpoint());
139 EXPECT_EQ("tmp display_name", ci.display_name());
140 EXPECT_EQ("tmp description", ci.description());
141 EXPECT_EQ("tmp art", ci.art());
142 EXPECT_EQ("tmp icon", ci.icon());
143 EXPECT_EQ("tmp search_hint", ci.search_hint());
144 EXPECT_EQ("tmp hot_key", ci.hot_key());
145
146 // Check public assignment operator
147 auto tmp = ScopeMetadataImpl::create(move(ti));
148 m = tmp;
149 EXPECT_EQ("tmp scope_name", m.scope_name());
150 EXPECT_EQ("tmp identity", m.proxy()->identity());
151 EXPECT_EQ("tmp endpoint", m.proxy()->endpoint());
152 EXPECT_EQ("tmp display_name", m.display_name());
153 EXPECT_EQ("tmp description", m.description());
154 EXPECT_EQ("tmp art", m.art());
155 EXPECT_EQ("tmp icon", m.icon());
156 EXPECT_EQ("tmp search_hint", m.search_hint());
157 EXPECT_EQ("tmp hot_key", m.hot_key());
158
159 // Self-assignment
160 tmp = tmp;
161 EXPECT_EQ("tmp scope_name", tmp.scope_name());
162 EXPECT_EQ("tmp identity", tmp.proxy()->identity());
163 EXPECT_EQ("tmp endpoint", tmp.proxy()->endpoint());
164 EXPECT_EQ("tmp display_name", tmp.display_name());
165 EXPECT_EQ("tmp description", tmp.description());
166 EXPECT_EQ("tmp art", tmp.art());
167 EXPECT_EQ("tmp icon", tmp.icon());
168 EXPECT_EQ("tmp search_hint", tmp.search_hint());
169 EXPECT_EQ("tmp hot_key", tmp.hot_key());
170
171 // Copy constructor
172 ScopeMetadata tmp2(tmp);
173 EXPECT_EQ("tmp scope_name", tmp2.scope_name());
174 EXPECT_EQ("tmp identity", tmp2.proxy()->identity());
175 EXPECT_EQ("tmp endpoint", tmp2.proxy()->endpoint());
176 EXPECT_EQ("tmp display_name", tmp2.display_name());
177 EXPECT_EQ("tmp description", tmp2.description());
178 EXPECT_EQ("tmp art", tmp2.art());
179 EXPECT_EQ("tmp icon", tmp2.icon());
180 EXPECT_EQ("tmp search_hint", tmp2.search_hint());
181 EXPECT_EQ("tmp hot_key", tmp2.hot_key());
182}
183
184TEST(ScopeMetadataImpl, serialize)
185{
186 ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini",
187 (RuntimeImpl*)0x1);
188
189 unique_ptr<ScopeMetadataImpl> mi(new ScopeMetadataImpl(&mw));
190 mi->set_scope_name("scope_name");
191 auto mw_proxy = mw.create_scope_proxy("identity", "endpoint");
192 mi->set_proxy(ScopeImpl::create(mw_proxy, mw.runtime()));
193 mi->set_display_name("display_name");
194 mi->set_description("description");
195 mi->set_art("art");
196 mi->set_icon("icon");
197 mi->set_search_hint("search_hint");
198 mi->set_hot_key("hot_key");
199
200 // Check that serialize() sets the map values correctly
201 auto m = ScopeMetadataImpl::create(move(mi));
202 auto var = m.serialize();
203 EXPECT_EQ(8, var.size());
204 EXPECT_EQ("scope_name", var["scope_name"].get_string());
205 EXPECT_EQ("display_name", var["display_name"].get_string());
206 EXPECT_EQ("description", var["description"].get_string());
207 EXPECT_EQ("art", var["art"].get_string());
208 EXPECT_EQ("icon", var["icon"].get_string());
209 EXPECT_EQ("search_hint", var["search_hint"].get_string());
210 EXPECT_EQ("hot_key", var["hot_key"].get_string());
211
212 // Make another instance from the VariantMap and check its fields
213 ScopeMetadataImpl c(var, &mw);
214 EXPECT_EQ("scope_name", c.scope_name());
215 EXPECT_EQ("identity", c.proxy()->identity());
216 EXPECT_EQ("endpoint", c.proxy()->endpoint());
217 EXPECT_EQ("display_name", c.display_name());
218 EXPECT_EQ("description", c.description());
219 EXPECT_EQ("art", c.art());
220 EXPECT_EQ("icon", c.icon());
221 EXPECT_EQ("search_hint", c.search_hint());
222 EXPECT_EQ("hot_key", c.hot_key());
223}
224
225TEST(ScopeMetadataImpl, serialize_exceptions)
226{
227 ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini",
228 (RuntimeImpl*)0x1);
229
230 ScopeMetadataImpl mi(&mw);
231 try
232 {
233 mi.serialize();
234 FAIL();
235 }
236 catch (InvalidArgumentException const&e)
237 {
238 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'scope_name' is empty",
239 e.to_string());
240 }
241
242 try
243 {
244 mi.set_scope_name("scope_name");
245 mi.serialize();
246 FAIL();
247 }
248 catch (InvalidArgumentException const&e)
249 {
250 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadataImpl::serialize(): required attribute 'proxy' is null",
251 e.to_string());
252 }
253
254 try
255 {
256 auto mw_proxy = mw.create_scope_proxy("identity", "endpoint");
257 mi.set_proxy(ScopeImpl::create(mw_proxy, mw.runtime()));
258 mi.serialize();
259 FAIL();
260 }
261 catch (InvalidArgumentException const&e)
262 {
263 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'display_name' is empty",
264 e.to_string());
265 }
266
267 try
268 {
269 mi.set_display_name("display_name");
270 mi.serialize();
271 FAIL();
272 }
273 catch (InvalidArgumentException const&e)
274 {
275 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'description' is empty",
276 e.to_string());
277 }
278}
279
280TEST(ScopeMetadataImpl, deserialize_exceptions)
281{
282 ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini",
283 (RuntimeImpl*)0x1);
284
285 VariantMap m;
286 try
287 {
288 ScopeMetadataImpl mi(m, &mw);
289 mi.deserialize(m);
290 FAIL();
291 }
292 catch (InvalidArgumentException const&e)
293 {
294 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
295 "'scope_name' is missing",
296 e.to_string());
297 }
298
299 m["scope_name"] = "scope_name";
300 try
301 {
302 ScopeMetadataImpl mi(m, &mw);
303 mi.deserialize(m);
304 FAIL();
305 }
306 catch (InvalidArgumentException const&e)
307 {
308 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
309 "'proxy' is missing",
310 e.to_string());
311 }
312
313 VariantMap proxy;
314 m["proxy"] = proxy;
315 try
316 {
317 ScopeMetadataImpl mi(m, &mw);
318 mi.deserialize(m);
319 FAIL();
320 }
321 catch (InvalidArgumentException const&e)
322 {
323 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadataImpl::deserialize(): missing 'proxy.identity'",
324 e.to_string());
325 }
326
327 proxy["identity"] = "identity";
328 m["proxy"] = proxy;
329 try
330 {
331 ScopeMetadataImpl mi(m, &mw);
332 mi.deserialize(m);
333 FAIL();
334 }
335 catch (InvalidArgumentException const&e)
336 {
337 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadataImpl::deserialize(): missing 'proxy.endpoint'",
338 e.to_string());
339 }
340
341 proxy["endpoint"] = "endpoint";
342 m["proxy"] = proxy;
343 try
344 {
345 ScopeMetadataImpl mi(m, &mw);
346 mi.deserialize(m);
347 FAIL();
348 }
349 catch (InvalidArgumentException const&e)
350 {
351 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
352 "'display_name' is missing",
353 e.to_string());
354 }
355
356 m["display_name"] = "display_name";
357 try
358 {
359 ScopeMetadataImpl mi(m, &mw);
360 mi.deserialize(m);
361 FAIL();
362 }
363 catch (InvalidArgumentException const&e)
364 {
365 EXPECT_EQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
366 "'description' is missing",
367 e.to_string());
368 }
369 m["description"] = "description";
370
371 // Optional attributes
372 m["art"] = "art";
373 m["icon"] = "icon";
374 m["search_hint"] = "search_hint";
375 m["hot_key"] = "hot_key";
376
377 ScopeMetadataImpl mi(m, &mw);
378 mi.deserialize(m);
379 EXPECT_EQ("scope_name", mi.scope_name());
380 EXPECT_EQ("identity", mi.proxy()->identity());
381 EXPECT_EQ("endpoint", mi.proxy()->endpoint());
382 EXPECT_EQ("display_name", mi.display_name());
383 EXPECT_EQ("description", mi.description());
384 EXPECT_EQ("art", mi.art());
385 EXPECT_EQ("icon", mi.icon());
386 EXPECT_EQ("search_hint", mi.search_hint());
387 EXPECT_EQ("hot_key", mi.hot_key());
388}
0389
=== added file 'test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini.in'
--- test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini.in 1970-01-01 00:00:00 +0000
+++ test/gtest/unity/api/scopes/internal/ScopeMetadataImpl/Zmq.ini.in 2013-12-03 14:09:20 +0000
@@ -0,0 +1,3 @@
1[Zmq]
2EndpointDir.Public = /tmp
3EndpointDir.Private = /tmp
04
=== modified file 'test/gtest/unity/api/scopes/internal/zmq_middleware/ObjectAdapter/Zmq.ini.in'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/ObjectAdapter/Zmq.ini.in 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/ObjectAdapter/Zmq.ini.in 2013-12-03 14:09:20 +0000
@@ -1,2 +1,3 @@
1[Zmq]1[Zmq]
2EndpointDir.Public = /tmp2EndpointDir.Public = /tmp
3EndpointDir.Private = /tmp
34
=== modified file 'test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/CMakeLists.txt'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/CMakeLists.txt 2013-11-19 02:51:46 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/CMakeLists.txt 2013-12-03 14:09:20 +0000
@@ -1,4 +1,3 @@
1configure_file(Factory.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Factory.ini)
2configure_file(Registry.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Registry.ini)1configure_file(Registry.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Registry.ini)
3configure_file(Runtime.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Runtime.ini)2configure_file(Runtime.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Runtime.ini)
4configure_file(Zmq.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Zmq.ini)3configure_file(Zmq.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Zmq.ini)
54
=== removed file 'test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Factory.ini.in'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Factory.ini.in 2013-09-23 06:13:06 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Factory.ini.in 1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
1[MiddlewareFactory]
2Zmq.Configfile = Zmq.ini
3REST.Configfile = REST.ini
40
=== modified file 'test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/RegistryI_test.cpp'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/RegistryI_test.cpp 2013-11-21 21:46:36 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/RegistryI_test.cpp 2013-12-03 14:09:20 +0000
@@ -20,6 +20,8 @@
2020
21#include <scopes/internal/RegistryConfig.h>21#include <scopes/internal/RegistryConfig.h>
22#include <scopes/internal/RuntimeImpl.h>22#include <scopes/internal/RuntimeImpl.h>
23#include <scopes/internal/ScopeMetadataImpl.h>
24#include <scopes/internal/ScopeImpl.h>
23#include <scopes/internal/UniqueID.h>25#include <scopes/internal/UniqueID.h>
24#include <internal/zmq_middleware/capnproto/Message.capnp.h>26#include <internal/zmq_middleware/capnproto/Message.capnp.h>
25#include <scopes/ScopeExceptions.h>27#include <scopes/ScopeExceptions.h>
@@ -37,33 +39,48 @@
37using namespace unity::api::scopes::internal;39using namespace unity::api::scopes::internal;
38using namespace unity::api::scopes::internal::zmq_middleware;40using namespace unity::api::scopes::internal::zmq_middleware;
3941
40TEST(RegistryI, find)42ScopeMetadata make_meta(const string& name, MWScopeProxy const& proxy, MiddlewareBase::SPtr const& mw)
41{43{
42try44 unique_ptr<ScopeMetadataImpl> mi(new ScopeMetadataImpl(mw.get()));
43{45 mi->set_scope_name(name);
44 RuntimeImpl::UPtr runtime = RuntimeImpl::create(46 mi->set_art("art " + name);
45 "Registry", TEST_BUILD_ROOT "/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Runtime.ini");47 mi->set_display_name("display name " + name);
4648 mi->set_description("description " + name);
47 string identity = runtime->registry_identity();49 mi->set_search_hint("search hint " + name);
48 RegistryConfig c(identity, runtime->registry_configfile());50 mi->set_hot_key("hot key " + name);
49 string mw_kind = c.mw_kind();51 ScopeProxy p = ScopeImpl::create(proxy, mw->runtime());
50 string mw_endpoint = c.endpoint();52 mi->set_proxy(p);
51 string mw_configfile = c.mw_configfile();53 return ScopeMetadataImpl::create(move(mi));
5254}
53 MiddlewareBase::SPtr middleware = runtime->factory()->create(identity, mw_kind, mw_configfile);55
54 RegistryObject::SPtr ro(make_shared<RegistryObject>());56TEST(RegistryI, get_metadata)
55 auto registry = middleware->add_registry_object(identity, ro);57{
56 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");58 try
57 EXPECT_TRUE(ro->add("scope1", proxy));59 {
5860 RuntimeImpl::UPtr runtime = RuntimeImpl::create(
59 auto r = runtime->registry();61 "Registry", TEST_BUILD_ROOT "/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Runtime.ini");
60 auto scope = r->find("scope1");62
61 EXPECT_TRUE(scope.get());63 string identity = runtime->registry_identity();
62}64 RegistryConfig c(identity, runtime->registry_configfile());
63catch(unity::Exception const& e)65 string mw_kind = c.mw_kind();
64{66 string mw_endpoint = c.endpoint();
65 cout << e.to_string() << endl;67 string mw_configfile = c.mw_configfile();
66}68
69 MiddlewareBase::SPtr middleware = runtime->factory()->create(identity, mw_kind, mw_configfile);
70 RegistryObject::SPtr ro(make_shared<RegistryObject>());
71 auto registry = middleware->add_registry_object(identity, ro);
72 auto p = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");
73 EXPECT_TRUE(ro->add("scope1", move(make_meta("scope1", p, middleware))));
74
75 auto r = runtime->registry();
76 auto scope = r->get_metadata("scope1");
77 EXPECT_EQ("scope1", scope.scope_name());
78 }
79 catch (unity::Exception const& e)
80 {
81 cerr << e.to_string() << endl;
82 FAIL();
83 }
67}84}
6885
69TEST(RegistryI, list)86TEST(RegistryI, list)
@@ -86,7 +103,7 @@
86 EXPECT_TRUE(scopes.empty());103 EXPECT_TRUE(scopes.empty());
87104
88 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");105 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");
89 EXPECT_TRUE(ro->add("scope1", proxy));106 EXPECT_TRUE(ro->add("scope1", move(make_meta("scope1", proxy, middleware))));
90 scopes = r->list();107 scopes = r->list();
91 EXPECT_EQ(1, scopes.size());108 EXPECT_EQ(1, scopes.size());
92 EXPECT_NE(scopes.end(), scopes.find("scope1"));109 EXPECT_NE(scopes.end(), scopes.find("scope1"));
@@ -96,14 +113,14 @@
96 EXPECT_EQ(0, scopes.size());113 EXPECT_EQ(0, scopes.size());
97114
98 set<string> ids;115 set<string> ids;
99 for (int i = 0; i < 1000; ++i)116 for (int i = 0; i < 10; ++i)
100 {117 {
101 string long_id = "0000000000000000000000000000000000000000000000" + to_string(i);118 string long_id = "0000000000000000000000000000000000000000000000" + to_string(i);
102 EXPECT_TRUE(ro->add(long_id, proxy));119 EXPECT_TRUE(ro->add(long_id, move(make_meta(long_id, proxy, middleware))));
103 ids.insert(long_id);120 ids.insert(long_id);
104 }121 }
105 scopes = r->list();122 scopes = r->list();
106 EXPECT_EQ(1000, scopes.size());123 EXPECT_EQ(10, scopes.size());
107 for (auto& id : ids)124 for (auto& id : ids)
108 {125 {
109 auto it = scopes.find(id);126 auto it = scopes.find(id);
@@ -132,11 +149,11 @@
132 EXPECT_TRUE(scopes.empty());149 EXPECT_TRUE(scopes.empty());
133150
134 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");151 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");
135 EXPECT_TRUE(ro->add("scope1", proxy));152 EXPECT_TRUE(ro->add("scope1", move(make_meta("scope1", proxy, middleware))));
136 scopes = r->list();153 scopes = r->list();
137 EXPECT_EQ(1, scopes.size());154 EXPECT_EQ(1, scopes.size());
138 EXPECT_NE(scopes.end(), scopes.find("scope1"));155 EXPECT_NE(scopes.end(), scopes.find("scope1"));
139 EXPECT_FALSE(ro->add("scope1", proxy));156 EXPECT_FALSE(ro->add("scope1", move(make_meta("scope1", proxy, middleware))));
140157
141 EXPECT_TRUE(ro->remove("scope1"));158 EXPECT_TRUE(ro->remove("scope1"));
142 scopes = r->list();159 scopes = r->list();
@@ -144,14 +161,14 @@
144 EXPECT_FALSE(ro->remove("scope1"));161 EXPECT_FALSE(ro->remove("scope1"));
145162
146 set<string> ids;163 set<string> ids;
147 for (int i = 0; i < 1000; ++i)164 for (int i = 0; i < 10; ++i)
148 {165 {
149 string long_id = "0000000000000000000000000000000000000000000000" + to_string(i);166 string long_id = "0000000000000000000000000000000000000000000000" + to_string(i);
150 ro->add(long_id, proxy);167 ro->add(long_id, move(make_meta(long_id, proxy, middleware)));
151 ids.insert(long_id);168 ids.insert(long_id);
152 }169 }
153 scopes = r->list();170 scopes = r->list();
154 EXPECT_EQ(1000, scopes.size());171 EXPECT_EQ(10, scopes.size());
155 for (auto& id : ids)172 for (auto& id : ids)
156 {173 {
157 auto it = scopes.find(id);174 auto it = scopes.find(id);
@@ -175,24 +192,24 @@
175 RegistryObject::SPtr ro(make_shared<RegistryObject>());192 RegistryObject::SPtr ro(make_shared<RegistryObject>());
176 auto registry = middleware->add_registry_object(identity, ro);193 auto registry = middleware->add_registry_object(identity, ro);
177 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");194 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");
178 ro->add("scope1", proxy);195 ro->add("scope1", move(make_meta("scope1", proxy, middleware)));
179196
180 auto r = runtime->registry();197 auto r = runtime->registry();
181198
182 try199 try
183 {200 {
184 r->find("fred");201 r->get_metadata("fred");
185 FAIL();202 FAIL();
186 }203 }
187 catch (NotFoundException const& e)204 catch (NotFoundException const& e)
188 {205 {
189 EXPECT_EQ("unity::api::scopes::NotFoundException: Registry::find(): no such scope (name = fred)",206 EXPECT_EQ("unity::api::scopes::NotFoundException: Registry::get_metadata(): no such scope (name = fred)",
190 e.to_string());207 e.to_string());
191 }208 }
192209
193 try210 try
194 {211 {
195 r->find("");212 r->get_metadata("");
196 FAIL();213 FAIL();
197 }214 }
198 catch (MiddlewareException const& e)215 catch (MiddlewareException const& e)
@@ -205,7 +222,7 @@
205 try222 try
206 {223 {
207 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");224 auto proxy = middleware->create_scope_proxy("scope1", "ipc:///tmp/scope1");
208 ro->add("", proxy);225 ro->add("", move(make_meta("blah", proxy, middleware)));
209 FAIL();226 FAIL();
210 }227 }
211 catch (InvalidArgumentException const& e)228 catch (InvalidArgumentException const& e)
212229
=== modified file 'test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Zmq.ini.in'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Zmq.ini.in 2013-11-19 21:12:39 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/RegistryI/Zmq.ini.in 2013-12-03 14:09:20 +0000
@@ -1,2 +1,3 @@
1[Zmq]1[Zmq]
2EndpointDir.Public = /tmp2EndpointDir.Public = /tmp
3EndpointDir.Private = /tmp
34
=== modified file 'test/gtest/unity/api/scopes/internal/zmq_middleware/ServantBase/Zmq.ini.in'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/ServantBase/Zmq.ini.in 2013-11-19 21:12:39 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/ServantBase/Zmq.ini.in 2013-12-03 14:09:20 +0000
@@ -1,2 +1,3 @@
1[Zmq]1[Zmq]
2EndpointDir.Public = /tmp2EndpointDir.Public = /tmp
3EndpointDir.Private = /tmp
34
=== modified file 'test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/Zmq.ini.in'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/Zmq.ini.in 2013-11-19 21:12:39 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/Zmq.ini.in 2013-12-03 14:09:20 +0000
@@ -1,2 +1,3 @@
1[Zmq]1[Zmq]
2EndpointDir.Public = /tmp2EndpointDir.Public = /tmp
3EndpointDir.Private = /tmp
34
=== modified file 'test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/ZmqMiddleware_test.cpp'
--- test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/ZmqMiddleware_test.cpp 2013-11-21 21:46:36 +0000
+++ test/gtest/unity/api/scopes/internal/zmq_middleware/ZmqMiddleware/ZmqMiddleware_test.cpp 2013-12-03 14:09:20 +0000
@@ -21,6 +21,7 @@
21#include <gtest/gtest.h>21#include <gtest/gtest.h>
22#include <scope-api-testconfig.h>22#include <scope-api-testconfig.h>
2323
24using namespace std;
24using namespace unity::api::scopes::internal;25using namespace unity::api::scopes::internal;
25using namespace unity::api::scopes::internal::zmq_middleware;26using namespace unity::api::scopes::internal::zmq_middleware;
2627

Subscribers

People subscribed via source and target branches

to all changes: