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 Session messaging protocol.
20 : : */
21 : :
22 : : #ifndef __SSRC_WSPR_SESSION_PROTOCOL_H
23 : : #define __SSRC_WSPR_SESSION_PROTOCOL_H
24 : :
25 : : #include <ssrc/wispers/index/DictionaryProtocol.h>
26 : : #include <ssrc/wispers/session/SessionData.h>
27 : :
28 : : __BEGIN_NS_SSRC_WSPR_PROTOCOL
29 : :
30 [ + - ]: 55 : WSPR_DEFINE_PROTOCOL(Session,session);
31 : :
32 : : __END_NS_SSRC_WSPR_PROTOCOL
33 : :
34 : : __BEGIN_NS_SSRC_WSPR_SESSION
35 : :
36 : : using namespace NS_SSRC_WSPR_INDEX;
37 : :
38 : : enum SessionIndexScheme { BySID, ByUID, ByLastAccess };
39 : :
40 : : typedef boost::multi_index_container<
41 : : SessionData,
42 : : boost::multi_index::indexed_by<
43 : : boost::multi_index::hashed_unique<
44 : : boost::multi_index::member<SessionData, sid_type, &SessionData::sid> >,
45 : : boost::multi_index::hashed_unique<
46 : : boost::multi_index::member<SessionData, uid_type, &SessionData::uid> >,
47 : : boost::multi_index::ordered_non_unique<
48 : : boost::multi_index::member<SessionData, idle_count_type,
49 : : &SessionData::idle_count> >
50 : : > > session_map;
51 : :
52 : : typedef session_map::nth_index<BySID>::type index_by_sid;
53 : : typedef session_map::nth_index<ByUID>::type index_by_uid;
54 : : typedef session_map::nth_index<ByLastAccess>::type index_by_access;
55 : :
56 : : struct SessionProtocol :
57 : : public DictionaryProtocol<protocol::MessageSession, session_map,
58 : : SessionIndexScheme>
59 : : {
60 : 2 : static string event_group_expire() {
61 [ + - ]: 2 : return WSPR_EVENT_GROUP("session", "expire");
62 : : }
63 : :
64 : 10 : static string event_group_login() {
65 [ + - ]: 10 : return WSPR_EVENT_GROUP("session", "login");
66 : : }
67 : :
68 : 10 : static string event_group_logout() {
69 [ + - ]: 10 : return WSPR_EVENT_GROUP("session", "logout");
70 : : }
71 : :
72 : : enum {
73 : : CreateSession = MaxDictionaryMessageID + 1,
74 : : GetSession,
75 : : ExpireSession,
76 : : SetAttributes,
77 : : UpdateSession,
78 : : LoginSession,
79 : : LogoutSession
80 : : };
81 : :
82 : :
83 : : WISP_PROTOCOL_MESSAGE_WITH_INIT(CreateSession, protocol::MessageSession,
84 : 24 : ((sid_type, sid)), (""));
85 : : WISP_PROTOCOL_MESSAGE_WITH_INIT(GetSession, protocol::MessageSession,
86 : : ((sid_type, sid))((bool, update_access_time)),
87 : 18 : ("")(true));
88 : :
89 : 2 : struct MessageExpireSession : public protocol::MessageSession<ExpireSession>
90 : : {
91 : : typedef uid_type session_value;
92 : : typedef std::vector<session_value> session_container;
93 : : session_container sessions;
94 : :
95 : : template<class Archive>
96 : 1 : void serialize(Archive & ar, const unsigned int) {
97 : 1 : ar & sessions;
98 : 1 : }
99 : : };
100 : :
101 [ + - ]: 2 : struct MessageSetAttributes : public protocol::MessageSession<ExpireSession>
102 : : {
103 : : sid_type sid;
104 : : Properties attributes;
105 : :
106 : 2 : MessageSetAttributes(const sid_type & sid = sid_type()) :
107 [ + - ]: 2 : sid(sid), attributes()
108 : 2 : { }
109 : :
110 : : MessageSetAttributes(const sid_type & sid, Properties && attributes) :
111 : : sid(sid), attributes(attributes)
112 : : { }
113 : :
114 : : template<class Archive>
115 : 2 : void serialize(Archive & ar, const unsigned int) {
116 : 2 : ar & sid & attributes;
117 : 2 : }
118 : : };
119 : :
120 : : WISP_PROTOCOL_MESSAGE(UpdateSession, protocol::MessageSession,
121 : 0 : ((SessionData, session)));
122 : :
123 : : WISP_PROTOCOL_MESSAGE(LoginSession, protocol::MessageSession,
124 : 0 : ((SessionData, session)));
125 : :
126 : : WISP_PROTOCOL_MESSAGE(LogoutSession, protocol::MessageSession,
127 : 0 : ((SessionData, session)));
128 : :
129 : : WISP_ONE_WAY_CALL(caller_type, ExpireSession);
130 : : WISP_ONE_WAY_CALL(caller_type, SetAttributes);
131 : : WISP_ONE_WAY_CALL(caller_type, UpdateSession);
132 : : WISP_ONE_WAY_CALL(caller_type, LoginSession);
133 : : WISP_ONE_WAY_CALL(caller_type, LogoutSession);
134 : :
135 : : WISP_TWO_WAY_CALL(caller_type, CreateSession, SingleQueryResult);
136 : : WISP_TWO_WAY_CALL(caller_type, GetSession, SingleQueryResult);
137 : : };
138 : :
139 : : __END_NS_SSRC_WSPR_SESSION
140 : :
141 : : #endif
|