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