Response.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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/RequestId.h"
16 #include "ipc/TypedMsgHdr.h"
17 #include "mgr/ActionCreator.h"
18 #include "mgr/ActionProfile.h"
19 #include "mgr/Response.h"
20 
21 Mgr::Response::Response(const Ipc::RequestId aRequestId, const Action::Pointer anAction):
22  Ipc::Response(aRequestId), action(anAction)
23 {
24  Must(!action || action->name()); // if there is an action, it must be named
25 }
26 
28 {
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
44 {
45  Must(requestId != 0);
47  msg.putPod(requestId);
48  if (hasAction()) {
49  msg.putString(action->name());
50  action->pack(msg);
51  }
52 }
53 
56 {
57  return new Response(*this);
58 }
59 
60 bool
62 {
63  return action != nullptr;
64 }
65 
66 const Mgr::Action&
68 {
69  Must(hasAction());
70  return *action;
71 }
72 
Action::Pointer action
action relating to response
Definition: Response.h:39
Mgr::Action::Pointer createNamedAction(const char *actionName)
bool hasMoreData() const
returns true if there is data to extract; handy for optional parts
Definition: TypedMsgHdr.h:66
void setType(int aType)
sets message type; use MessageType enum
Definition: TypedMsgHdr.cc:100
void checkType(int aType) const
Definition: TypedMsgHdr.cc:94
@ mtCacheMgrResponse
Definition: Messages.h:36
static CacheManager * GetInstance()
void pack(Ipc::TypedMsgHdr &msg) const override
prepare for sendmsg()
Definition: Response.cc:43
void putPod(const Pod &pod)
store POD
Definition: TypedMsgHdr.h:126
const Action & getAction() const
returns action object
Definition: Response.cc:67
bool hasAction() const
whether response contain action object
Definition: Response.cc:61
Ipc::Response::Pointer clone() const override
returns a copy of this
Definition: Response.cc:55
void getString(String &s) const
load variable-length string
Definition: TypedMsgHdr.cc:125
const char * termedBuf() const
Definition: SquidString.h:92
#define Must(condition)
Definition: TextException.h:75
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:34
Response()=default
recipient's constructor
void getPod(Pod &pod) const
load POD
Definition: TypedMsgHdr.h:118
void putString(const String &s)
store variable-length string
Definition: TypedMsgHdr.cc:143
Definition: IpcIoFile.h:23

 

Introduction

Documentation

Support

Miscellaneous