]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Response.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mgr / Response.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 16 Cache Manager API */
10
11 #include "squid.h"
12 #include "base/TextException.h"
13 #include "CacheManager.h"
14 #include "ipc/Messages.h"
15 #include "ipc/TypedMsgHdr.h"
16 #include "mgr/ActionCreator.h"
17 #include "mgr/ActionProfile.h"
18 #include "mgr/Response.h"
19
20 Mgr::Response::Response(unsigned int aRequestId, Action::Pointer anAction):
21 Ipc::Response(aRequestId), action(anAction)
22 {
23 Must(!action || action->name()); // if there is an action, it must be named
24 }
25
26 Mgr::Response::Response(const Response& response):
27 Ipc::Response(response.requestId), action(response.action)
28 {
29 }
30
31 Mgr::Response::Response(const Ipc::TypedMsgHdr& msg):
32 Ipc::Response(0)
33 {
34 msg.checkType(Ipc::mtCacheMgrResponse);
35 msg.getPod(requestId);
36 Must(requestId != 0);
37
38 if (msg.hasMoreData()) {
39 String actionName;
40 msg.getString(actionName);
41 action = CacheManager::GetInstance()->createNamedAction(actionName.termedBuf());
42 Must(hasAction());
43 action->unpack(msg);
44 }
45 }
46
47 void
48 Mgr::Response::pack(Ipc::TypedMsgHdr& msg) const
49 {
50 Must(requestId != 0);
51 msg.setType(Ipc::mtCacheMgrResponse);
52 msg.putPod(requestId);
53 if (hasAction()) {
54 msg.putString(action->name());
55 action->pack(msg);
56 }
57 }
58
59 Ipc::Response::Pointer
60 Mgr::Response::clone() const
61 {
62 return new Response(*this);
63 }
64
65 bool
66 Mgr::Response::hasAction() const
67 {
68 return action != NULL;
69 }
70
71 const Mgr::Action&
72 Mgr::Response::getAction() const
73 {
74 Must(hasAction());
75 return *action;
76 }
77