DictionaryService.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 2006-2009 Savarese Software Research Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * https://www.savarese.com/software/ApacheLicense-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 #ifndef __SSRC_WSPR_INDEX_DICTIONARY_SERVICE_H 00023 #define __SSRC_WSPR_INDEX_DICTIONARY_SERVICE_H 00024 00025 #include <ssrc/wispers/index/IndexService.h> 00026 00027 __BEGIN_NS_SSRC_WSPR_INDEX 00028 00032 template<typename ProtocolTraits, 00033 bool group_membership = GroupMembershipDisable> 00034 class DictionaryService : 00035 public IndexService<typename ProtocolTraits::map_type, 00036 typename ProtocolTraits::index_scheme, 00037 group_membership> 00038 { 00039 public: 00040 typedef ProtocolTraits protocol_traits; 00041 00042 WISP_IMPORT_T(protocol_traits, packing_traits); 00043 WISP_IMPORT_T(protocol_traits, map_type); 00044 WISP_IMPORT_T(protocol_traits, index_scheme); 00045 00046 WISP_IMPORT_T(protocol_traits, MessageInsert); 00047 WISP_IMPORT_T(protocol_traits, MessageErase); 00048 WISP_IMPORT_T(protocol_traits, MessageQueryResult); 00049 WISP_IMPORT_T(protocol_traits, MessageQueryAll); 00050 WISP_IMPORT_T(protocol_traits, MessageQueryByDefault); 00051 WISP_IMPORT_T(protocol_traits, MessageSingleQueryResult); 00052 WISP_IMPORT_T(protocol_traits, MessageSingleQueryByDefault); 00053 00054 WISP_IMPORT_T(protocol_traits, CallQueryResult); 00055 WISP_IMPORT_T(protocol_traits, CallSingleQueryResult); 00056 00057 private: 00058 friend class NS_SSRC_WISP_SERVICE::ServiceProtocolProcessor<packing_traits>; 00059 typedef IndexService<map_type, index_scheme, group_membership> super; 00060 00061 protected: 00062 00063 virtual void process_request(const MessageInsert & msg, 00064 const MessageInfo &) 00065 { 00066 unsigned int i = msg.values.size(); 00067 00068 while(i-- > 0) { 00069 std::pair<typename map_type::iterator, bool> result = 00070 super::template insert<protocol_traits::ByDefault>(msg.values[i]); 00071 00072 if(!result.second) 00073 super::template 00074 replace<protocol_traits::ByDefault>(result.first, msg.values[i]); 00075 } 00076 } 00077 00078 void process_request(const MessageErase & msg, const MessageInfo &) { 00079 unsigned int i = msg.keys.size(); 00080 00081 while(i-- > 0) 00082 super::template erase<protocol_traits::ByDefault>(msg.keys[i]); 00083 } 00084 00085 void process_request(const MessageSingleQueryByDefault & msg, 00086 const MessageInfo & msginfo) 00087 { 00088 super::template process_single_query<protocol_traits::ByDefault, CallSingleQueryResult>(msg, msginfo); 00089 } 00090 00091 void process_request(const MessageQueryByDefault & msg, 00092 const MessageInfo & msginfo) 00093 { 00094 super::template 00095 process_query<protocol_traits::ByDefault, CallQueryResult>(msg, msginfo); 00096 } 00097 00098 void process_request(const MessageQueryAll & msg, const MessageInfo & msginfo) 00099 { 00100 super::_caller.template 00101 reply<CallQueryResult>(Message::FIFOSelfDiscard, msginfo.sender(), 00102 msginfo.token(), super::_index); 00103 } 00104 00105 public: 00106 00107 explicit DictionaryService(typename super::caller_type & caller) : 00108 super(caller) 00109 { 00110 WISP_SERVICE_REQUEST_T(MessageInsert); 00111 WISP_SERVICE_REQUEST_T(MessageErase); 00112 WISP_SERVICE_REQUEST_T(MessageQueryAll); 00113 WISP_SERVICE_REQUEST_T(MessageQueryByDefault); 00114 WISP_SERVICE_REQUEST_T(MessageSingleQueryByDefault); 00115 } 00116 00117 virtual ~DictionaryService() { } 00118 00119 }; 00120 00121 __END_NS_SSRC_WSPR_INDEX 00122 00123 #endif
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.