|
1 /** |
|
2 This file is part of CWRT package ** |
|
3 |
|
4 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** |
|
5 |
|
6 This program is free software: you can redistribute it and/or modify |
|
7 it under the terms of the GNU (Lesser) General Public License as |
|
8 published by the Free Software Foundation, version 2.1 of the License. |
|
9 This program is distributed in the hope that it will be useful, but |
|
10 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 (Lesser) General Public License for more details. You should have |
|
13 received a copy of the GNU (Lesser) General Public License along |
|
14 with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 */ |
|
16 |
|
17 |
|
18 #include "serviceipcserversession.h" |
|
19 #include "serviceipcobserver.h" |
|
20 #include "serviceipcrequest.h" |
|
21 #include "serviceipcserver_p.h" |
|
22 |
|
23 namespace WRT |
|
24 { |
|
25 /*! |
|
26 \class ServiceIPCSession |
|
27 Session class to hold the state of each connected client |
|
28 */ |
|
29 |
|
30 /*! |
|
31 Constructor |
|
32 @param aObserver observer to the session |
|
33 */ |
|
34 ServiceIPCSession::ServiceIPCSession(MServiceIPCObserver* aObserver) |
|
35 : m_isPendingRequest(false) |
|
36 , m_observer(aObserver) |
|
37 , m_curRequest(NULL) |
|
38 , m_clientInfo(NULL) |
|
39 , m_appendToBList(false) |
|
40 , m_readyToSend(false) |
|
41 { |
|
42 |
|
43 } |
|
44 |
|
45 /*! |
|
46 Destructor |
|
47 */ |
|
48 ServiceIPCSession::~ServiceIPCSession() |
|
49 { |
|
50 m_messageList.clear(); |
|
51 } |
|
52 |
|
53 |
|
54 void ServiceIPCSession::handleReq() |
|
55 { |
|
56 if (m_curRequest->getOperation() == GETSESSIONID) { |
|
57 QByteArray sessionId; |
|
58 sessionId.setNum(m_clientInfo->sessionId()); |
|
59 m_curRequest->write(sessionId); |
|
60 |
|
61 m_curRequest->completeRequest(); |
|
62 m_observer->handleClientConnect(m_clientInfo); |
|
63 } |
|
64 else if (m_curRequest->getOperation() == SETSESSIONINFO) { |
|
65 qint32 sessionId = m_curRequest->getData().toInt(); |
|
66 // release session id which allocate during new session. |
|
67 // 3 ipc client in one client wrapper share same session id |
|
68 releaseSessionId(m_clientInfo->sessionId()); |
|
69 m_clientInfo->setSessionId(sessionId); |
|
70 |
|
71 m_curRequest->completeRequest(); |
|
72 m_observer->handleClientConnect(m_clientInfo); |
|
73 } |
|
74 else if (m_curRequest->getOperation() == SUBSCRIBEBROADCASTMSG) { |
|
75 m_readyToSend = true; |
|
76 if (!m_appendToBList) { |
|
77 //add to broadcast list |
|
78 appendBroadcastList(m_clientInfo->sessionId(), this); |
|
79 m_appendToBList = true; |
|
80 } |
|
81 if (!m_messageList.isEmpty()) { |
|
82 write(m_messageList.takeFirst()); |
|
83 completeRequest(); |
|
84 m_readyToSend = false; |
|
85 } |
|
86 } |
|
87 else { |
|
88 m_observer->handleRequest(m_curRequest); |
|
89 } |
|
90 } |
|
91 |
|
92 /*! |
|
93 \fn WRT::ServiceIPCSession::write( const QByteArray& aData ) |
|
94 |
|
95 Write some data in response to a request |
|
96 @param aData some data to write as response |
|
97 @return bool if write was successful |
|
98 */ |
|
99 |
|
100 /*! |
|
101 \fn WRT::ServiceIPCSession::completeRequest() |
|
102 |
|
103 Complete a Request |
|
104 @return bool if request completed |
|
105 */ |
|
106 |
|
107 /*! |
|
108 \fn WRT::ServiceIPCSession::close() |
|
109 |
|
110 Close a session and gracefully shutdown |
|
111 */ |
|
112 } |
|
113 // END OF FILE |