Branch data Line data Source code
1 : : /*
2 : : * Copyright 2006-2009 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * https://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : /**
18 : : * @file
19 : : * This header defines the DictionaryService class.
20 : : */
21 : :
22 : : #ifndef __SSRC_WSPR_INDEX_DICTIONARY_SERVICE_H
23 : : #define __SSRC_WSPR_INDEX_DICTIONARY_SERVICE_H
24 : :
25 : : #include <ssrc/wispers/index/IndexService.h>
26 : :
27 : : __BEGIN_NS_SSRC_WSPR_INDEX
28 : :
29 : : /**
30 : : *
31 : : */
32 : : template<typename ProtocolTraits,
33 : : bool group_membership = GroupMembershipDisable>
34 : : class DictionaryService :
35 : : public IndexService<typename ProtocolTraits::map_type,
36 : : typename ProtocolTraits::index_scheme,
37 : : group_membership>
38 : : {
39 : : public:
40 : : typedef ProtocolTraits protocol_traits;
41 : :
42 : : WISP_IMPORT_T(protocol_traits, packing_traits);
43 : : WISP_IMPORT_T(protocol_traits, map_type);
44 : : WISP_IMPORT_T(protocol_traits, index_scheme);
45 : :
46 : : WISP_IMPORT_T(protocol_traits, MessageInsert);
47 : : WISP_IMPORT_T(protocol_traits, MessageErase);
48 : : WISP_IMPORT_T(protocol_traits, MessageQueryResult);
49 : : WISP_IMPORT_T(protocol_traits, MessageQueryAll);
50 : : WISP_IMPORT_T(protocol_traits, MessageQueryByDefault);
51 : : WISP_IMPORT_T(protocol_traits, MessageSingleQueryResult);
52 : : WISP_IMPORT_T(protocol_traits, MessageSingleQueryByDefault);
53 : :
54 : : WISP_IMPORT_T(protocol_traits, CallQueryResult);
55 : : WISP_IMPORT_T(protocol_traits, CallSingleQueryResult);
56 : :
57 : : private:
58 : : friend class NS_SSRC_WISP_SERVICE::ServiceProtocolProcessor<packing_traits>;
59 : : typedef IndexService<map_type, index_scheme, group_membership> super;
60 : :
61 : : protected:
62 : :
63 : 1 : virtual void process_request(const MessageInsert & msg,
64 : : const MessageInfo &)
65 : : {
66 : 1 : unsigned int i = msg.values.size();
67 : :
68 [ + + ]: 3 : while(i-- > 0) {
69 : : std::pair<typename map_type::iterator, bool> result =
70 : 1 : super::template insert<protocol_traits::ByDefault>(msg.values[i]);
71 : :
72 [ - + ]: 1 : if(!result.second)
73 : 0 : super::template
74 : : replace<protocol_traits::ByDefault>(result.first, msg.values[i]);
75 : : }
76 : 1 : }
77 : :
78 : 2 : void process_request(const MessageErase & msg, const MessageInfo &) {
79 : 2 : unsigned int i = msg.keys.size();
80 : :
81 [ + + ]: 6 : while(i-- > 0)
82 : 2 : super::template erase<protocol_traits::ByDefault>(msg.keys[i]);
83 : 2 : }
84 : :
85 : 1 : void process_request(const MessageSingleQueryByDefault & msg,
86 : : const MessageInfo & msginfo)
87 : : {
88 : 1 : super::template process_single_query<protocol_traits::ByDefault, CallSingleQueryResult>(msg, msginfo);
89 : 1 : }
90 : :
91 : 1 : void process_request(const MessageQueryByDefault & msg,
92 : : const MessageInfo & msginfo)
93 : : {
94 : 1 : super::template
95 : : process_query<protocol_traits::ByDefault, CallQueryResult>(msg, msginfo);
96 : 1 : }
97 : :
98 : 4 : void process_request(const MessageQueryAll & msg, const MessageInfo & msginfo)
99 : : {
100 : 4 : super::_caller.template
101 : : reply<CallQueryResult>(Message::FIFOSelfDiscard, msginfo.sender(),
102 : : msginfo.token(), super::_index);
103 : 4 : }
104 : :
105 : : public:
106 : :
107 : 13 : explicit DictionaryService(typename super::caller_type & caller) :
108 : 13 : super(caller)
109 : : {
110 [ + - ]: 13 : WISP_SERVICE_REQUEST_T(MessageInsert);
111 [ + - ]: 13 : WISP_SERVICE_REQUEST_T(MessageErase);
112 [ + - ]: 13 : WISP_SERVICE_REQUEST_T(MessageQueryAll);
113 [ + - ]: 13 : WISP_SERVICE_REQUEST_T(MessageQueryByDefault);
114 [ + - ]: 13 : WISP_SERVICE_REQUEST_T(MessageSingleQueryByDefault);
115 : 13 : }
116 : :
117 [ - + ]: 13 : virtual ~DictionaryService() { }
118 : :
119 : : };
120 : :
121 : : __END_NS_SSRC_WSPR_INDEX
122 : :
123 : : #endif
|