]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mgr/Response.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mgr / Response.cc
CommitLineData
8822ebee 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
8822ebee 3 *
bbc27441
AJ
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.
8822ebee
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 16 Cache Manager API */
10
f7f3304a 11#include "squid.h"
8822ebee
AR
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
51ea0904 20Mgr::Response::Response(unsigned int aRequestId, Action::Pointer anAction):
f53969cc 21 Ipc::Response(aRequestId), action(anAction)
8822ebee 22{
51ea0904 23 Must(!action || action->name()); // if there is an action, it must be named
8822ebee
AR
24}
25
51ea0904 26Mgr::Response::Response(const Response& response):
f53969cc 27 Ipc::Response(response.requestId), action(response.action)
8822ebee 28{
8822ebee
AR
29}
30
51ea0904 31Mgr::Response::Response(const Ipc::TypedMsgHdr& msg):
f53969cc 32 Ipc::Response(0)
8822ebee
AR
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
47void
48Mgr::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
51ea0904
CT
59Ipc::Response::Pointer
60Mgr::Response::clone() const
61{
62 return new Response(*this);
63}
64
8822ebee
AR
65bool
66Mgr::Response::hasAction() const
67{
68 return action != NULL;
69}
70
71const Mgr::Action&
72Mgr::Response::getAction() const
73{
74 Must(hasAction());
75 return *action;
76}
f53969cc 77