session/protocol.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_SESSION_PROTOCOL_H 00023 #define __SSRC_WSPR_SESSION_PROTOCOL_H 00024 00025 #include <ssrc/wispers/index/DictionaryProtocol.h> 00026 #include <ssrc/wispers/session/SessionData.h> 00027 00028 __BEGIN_NS_SSRC_WSPR_PROTOCOL 00029 00030 WSPR_DEFINE_PROTOCOL(Session,session); 00031 00032 __END_NS_SSRC_WSPR_PROTOCOL 00033 00034 __BEGIN_NS_SSRC_WSPR_SESSION 00035 00036 using namespace NS_SSRC_WSPR_INDEX; 00037 00038 enum SessionIndexScheme { BySID, ByUID, ByLastAccess }; 00039 00040 typedef boost::multi_index_container< 00041 SessionData, 00042 boost::multi_index::indexed_by< 00043 boost::multi_index::hashed_unique< 00044 boost::multi_index::member<SessionData, sid_type, &SessionData::sid> >, 00045 boost::multi_index::hashed_unique< 00046 boost::multi_index::member<SessionData, uid_type, &SessionData::uid> >, 00047 boost::multi_index::ordered_non_unique< 00048 boost::multi_index::member<SessionData, idle_count_type, 00049 &SessionData::idle_count> > 00050 > > session_map; 00051 00052 typedef session_map::nth_index<BySID>::type index_by_sid; 00053 typedef session_map::nth_index<ByUID>::type index_by_uid; 00054 typedef session_map::nth_index<ByLastAccess>::type index_by_access; 00055 00056 struct SessionProtocol : 00057 public DictionaryProtocol<protocol::MessageSession, session_map, 00058 SessionIndexScheme> 00059 { 00060 static string event_group_expire() { 00061 return WSPR_EVENT_GROUP("session", "expire"); 00062 } 00063 00064 static string event_group_login() { 00065 return WSPR_EVENT_GROUP("session", "login"); 00066 } 00067 00068 static string event_group_logout() { 00069 return WSPR_EVENT_GROUP("session", "logout"); 00070 } 00071 00072 enum { 00073 CreateSession = MaxDictionaryMessageID + 1, 00074 GetSession, 00075 ExpireSession, 00076 SetAttributes, 00077 UpdateSession, 00078 LoginSession, 00079 LogoutSession 00080 }; 00081 00082 00083 WISP_PROTOCOL_MESSAGE_WITH_INIT(CreateSession, protocol::MessageSession, 00084 ((sid_type, sid)), ("")); 00085 WISP_PROTOCOL_MESSAGE_WITH_INIT(GetSession, protocol::MessageSession, 00086 ((sid_type, sid))((bool, update_access_time)), 00087 ("")(true)); 00088 00089 struct MessageExpireSession : public protocol::MessageSession<ExpireSession> 00090 { 00091 typedef uid_type session_value; 00092 typedef std::vector<session_value> session_container; 00093 session_container sessions; 00094 00095 template<class Archive> 00096 void serialize(Archive & ar, const unsigned int) { 00097 ar & sessions; 00098 } 00099 }; 00100 00101 struct MessageSetAttributes : public protocol::MessageSession<ExpireSession> 00102 { 00103 sid_type sid; 00104 Properties attributes; 00105 00106 MessageSetAttributes(const sid_type & sid = sid_type()) : 00107 sid(sid), attributes() 00108 { } 00109 00110 MessageSetAttributes(const sid_type & sid, Properties && attributes) : 00111 sid(sid), attributes(attributes) 00112 { } 00113 00114 template<class Archive> 00115 void serialize(Archive & ar, const unsigned int) { 00116 ar & sid & attributes; 00117 } 00118 }; 00119 00120 WISP_PROTOCOL_MESSAGE(UpdateSession, protocol::MessageSession, 00121 ((SessionData, session))); 00122 00123 WISP_PROTOCOL_MESSAGE(LoginSession, protocol::MessageSession, 00124 ((SessionData, session))); 00125 00126 WISP_PROTOCOL_MESSAGE(LogoutSession, protocol::MessageSession, 00127 ((SessionData, session))); 00128 00129 WISP_ONE_WAY_CALL(caller_type, ExpireSession); 00130 WISP_ONE_WAY_CALL(caller_type, SetAttributes); 00131 WISP_ONE_WAY_CALL(caller_type, UpdateSession); 00132 WISP_ONE_WAY_CALL(caller_type, LoginSession); 00133 WISP_ONE_WAY_CALL(caller_type, LogoutSession); 00134 00135 WISP_TWO_WAY_CALL(caller_type, CreateSession, SingleQueryResult); 00136 WISP_TWO_WAY_CALL(caller_type, GetSession, SingleQueryResult); 00137 }; 00138 00139 __END_NS_SSRC_WSPR_SESSION 00140 00141 #endif
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.