login/ws.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 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_LOGIN_WS_H 00023 #define __SSRC_WSPR_LOGIN_WS_H 00024 00025 #include <ssrc/wispers/login/protocol.h> 00026 #include <ssrc/wispers/ws/protocol.h> 00027 #include <ssrc/wispers/group_session/protocol.h> 00028 #include <ssrc/wispers/utility/ToString.h> 00029 00030 __BEGIN_NS_SSRC_WSPR_LOGIN 00031 00032 using NS_SSRC_WSPR_GROUP_SESSION::GroupSessionProtocol; 00033 using NS_SSRC_WSPR_WS::WebServiceProtocol; 00034 using NS_SSRC_WSPR_WS::WebServiceCallContextTwoWay; 00035 using NS_SSRC_WSPR_UTILITY::properties_ptr; 00036 using NS_SSRC_WSPR_UTILITY::ToString; 00037 00038 // The representation of a uid_to_login map entry is as an array: 00039 // { login, is_logged_in } 00040 // This is more compact than: 00041 // { login = value, is_logged_in = value } 00042 // which requires that key strings be allocated for each entry. 00043 inline const properties_ptr & 00044 set_uid_to_login(const properties_ptr & template_data, 00045 const uid_login_map & login_map, 00046 ToString & to_string) 00047 { 00048 using NS_SSRC_WSPR_UTILITY::Properties; 00049 using NS_SSRC_WSPR_UTILITY::primitive_property_vector; 00050 Properties * logins = template_data->create_node("uid_to_login"); 00051 00052 for(uid_login_map::const_iterator && it = login_map.begin(), 00053 && end = login_map.end(); it != end; ++it) 00054 { 00055 // We store login/status pair as array to avoid overhead of storing 00056 // extra keys for each entry since generating uid_login_maps is such 00057 // a common operation. 00058 primitive_property_vector & values = 00059 logins->create_primitive_property_vector(to_string(it->first)); 00060 values.push_back(it->second.login); 00061 values.push_back(it->second.is_logged_in); 00062 } 00063 00064 return template_data; 00065 } 00066 00067 namespace detail { 00068 00069 template<typename caller_type> 00070 inline void 00071 continue_find_logins(caller_type & caller, ToString & to_string, 00072 const WebServiceCallContextTwoWay & context, 00073 const properties_ptr & template_data, 00074 const LoginProtocol::CallFindLoginForUID::return_type & result) 00075 { 00076 caller.template reply<WebServiceProtocol::CallResponse>(ssrc::spread::Message::FIFOSelfDiscard, context.sender, context.token, context.session, set_uid_to_login(template_data, result.logins, to_string)); 00077 } 00078 00079 template<typename caller_type> 00080 inline void 00081 continue_find_logins2(caller_type & caller, ToString & to_string, 00082 const std::string & relay_group, 00083 const GroupSessionProtocol::MessageRelayEvent & mre, 00084 const LoginProtocol::CallFindLoginForUID::return_type & result) 00085 { 00086 set_uid_to_login(mre.event, result.logins, to_string); 00087 caller.template send<GroupSessionProtocol::CallRelayEvent>(relay_group, mre); 00088 } 00089 00090 template<typename caller_type> 00091 inline void 00092 continue_find_logins3(caller_type & caller, ToString & to_string, 00093 const std::string & event_queue, 00094 const WebServiceProtocol::MessageDeliverEvent & mde, 00095 const LoginProtocol::CallFindLoginForUID::return_type & result) 00096 { 00097 set_uid_to_login(mde.template_data, result.logins, to_string); 00098 caller.template send<WebServiceProtocol::CallDeliverEvent>(event_queue, mde); 00099 } 00100 00101 } 00102 00103 template<typename caller_type> 00104 inline void find_logins(caller_type & caller, 00105 ToString & to_string, 00106 const std::string & login_service, 00107 const LoginProtocol::MessageFindLoginForUID & msg, 00108 const WebServiceCallContextTwoWay & context, 00109 const properties_ptr & template_data) 00110 { 00111 auto continuation = 00112 [&caller, &to_string, context, template_data](const LoginProtocol::CallFindLoginForUID::return_type & result)->void { 00113 detail::continue_find_logins<caller_type>(caller, to_string, context, 00114 template_data, result); 00115 }; 00116 caller.template 00117 future_call<LoginProtocol::CallFindLoginForUID>(std::move(continuation), 00118 login_service, msg); 00119 } 00120 00121 template<typename caller_type> 00122 inline void find_logins(caller_type & caller, 00123 ToString & to_string, 00124 const std::string & login_service, 00125 const LoginProtocol::MessageFindLoginForUID & msg, 00126 const std::string & relay_group, 00127 const GroupSessionProtocol::MessageRelayEvent & mre) 00128 { 00129 auto continuation = 00130 [&caller, &to_string, relay_group, mre](const LoginProtocol::CallFindLoginForUID::return_type & result)->void { 00131 detail::continue_find_logins2<caller_type>(caller, to_string, relay_group, 00132 mre, result); 00133 }; 00134 caller.template 00135 future_call<LoginProtocol::CallFindLoginForUID>(std::move(continuation), 00136 login_service, msg); 00137 } 00138 00139 template<typename caller_type> 00140 inline void find_logins(caller_type & caller, 00141 ToString & to_string, 00142 const std::string & login_service, 00143 const LoginProtocol::MessageFindLoginForUID & msg, 00144 const std::string & event_queue, 00145 const WebServiceProtocol::MessageDeliverEvent & mde) 00146 { 00147 auto continuation = 00148 [&caller, &to_string, event_queue, mde](const LoginProtocol::CallFindLoginForUID::return_type & result)->void { 00149 detail::continue_find_logins3<caller_type>(caller, to_string, event_queue, 00150 mde, result); 00151 }; 00152 caller.template 00153 future_call<LoginProtocol::CallFindLoginForUID>(std::move(continuation), 00154 login_service, msg); 00155 } 00156 00157 __END_NS_SSRC_WSPR_LOGIN 00158 00159 #endif
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.