]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Response.cc
Completed protos.h split and code refactoring
[thirdparty/squid.git] / src / mgr / Response.cc
1 /*
2 * DEBUG: section 16 Cache Manager API
3 *
4 */
5
6 #include "squid.h"
7 #include "base/TextException.h"
8 #include "CacheManager.h"
9 #include "ipc/Messages.h"
10 #include "ipc/TypedMsgHdr.h"
11 #include "mgr/ActionCreator.h"
12 #include "mgr/ActionProfile.h"
13 #include "mgr/Response.h"
14
15 Mgr::Response::Response(unsigned int aRequestId, Action::Pointer anAction):
16 Ipc::Response(aRequestId), action(anAction)
17 {
18 Must(!action || action->name()); // if there is an action, it must be named
19 }
20
21 Mgr::Response::Response(const Response& response):
22 Ipc::Response(response.requestId), action(response.action)
23 {
24 }
25
26 Mgr::Response::Response(const Ipc::TypedMsgHdr& msg):
27 Ipc::Response(0)
28 {
29 msg.checkType(Ipc::mtCacheMgrResponse);
30 msg.getPod(requestId);
31 Must(requestId != 0);
32
33 if (msg.hasMoreData()) {
34 String actionName;
35 msg.getString(actionName);
36 action = CacheManager::GetInstance()->createNamedAction(actionName.termedBuf());
37 Must(hasAction());
38 action->unpack(msg);
39 }
40 }
41
42 void
43 Mgr::Response::pack(Ipc::TypedMsgHdr& msg) const
44 {
45 Must(requestId != 0);
46 msg.setType(Ipc::mtCacheMgrResponse);
47 msg.putPod(requestId);
48 if (hasAction()) {
49 msg.putString(action->name());
50 action->pack(msg);
51 }
52 }
53
54 Ipc::Response::Pointer
55 Mgr::Response::clone() const
56 {
57 return new Response(*this);
58 }
59
60 bool
61 Mgr::Response::hasAction() const
62 {
63 return action != NULL;
64 }
65
66 const Mgr::Action&
67 Mgr::Response::getAction() const
68 {
69 Must(hasAction());
70 return *action;
71 }