PetaVision  Alpha
CheckpointerDataInterface.cpp
1 /*
2  * CheckpointerDataInterface.cpp
3  *
4  * Created on Feb 22, 2018
5  * Author: Pete Schultz
6  */
7 
8 #include "CheckpointerDataInterface.hpp"
9 
10 namespace PV {
11 
12 Response::Status CheckpointerDataInterface::respond(std::shared_ptr<BaseMessage const> message) {
13  auto status = Response::NO_ACTION;
14  if (message == nullptr) {
15  return status;
16  }
17  else if (
18  auto castMessage =
19  std::dynamic_pointer_cast<RegisterDataMessage<Checkpointer> const>(message)) {
20  return respondRegisterData(castMessage);
21  }
22  else if (
23  auto castMessage =
24  std::dynamic_pointer_cast<ReadStateFromCheckpointMessage<Checkpointer> const>(
25  message)) {
26  return respondReadStateFromCheckpoint(castMessage);
27  }
28  else if (
29  auto castMessage =
30  std::dynamic_pointer_cast<ProcessCheckpointReadMessage const>(message)) {
31  return respondProcessCheckpointRead(castMessage);
32  }
33  else if (
34  auto castMessage =
35  std::dynamic_pointer_cast<PrepareCheckpointWriteMessage const>(message)) {
36  return respondPrepareCheckpointWrite(castMessage);
37  }
38  else {
39  return status;
40  }
41 }
42 
43 Response::Status CheckpointerDataInterface::respondRegisterData(
44  std::shared_ptr<RegisterDataMessage<Checkpointer> const> message) {
45  auto status = registerData(message->mDataRegistry);
46  if (!Response::completed(status)) {
47  Fatal() << getDescription() << ": registerData failed.\n";
48  }
49  return status;
50 }
51 
52 Response::Status CheckpointerDataInterface::respondReadStateFromCheckpoint(
53  std::shared_ptr<ReadStateFromCheckpointMessage<Checkpointer> const> message) {
54  return readStateFromCheckpoint(message->mDataRegistry);
55 }
56 
57 Response::Status CheckpointerDataInterface::respondProcessCheckpointRead(
58  std::shared_ptr<ProcessCheckpointReadMessage const> message) {
59  return processCheckpointRead();
60 }
61 
62 Response::Status CheckpointerDataInterface::respondPrepareCheckpointWrite(
63  std::shared_ptr<PrepareCheckpointWriteMessage const> message) {
64  return prepareCheckpointWrite();
65 }
66 
67 Response::Status CheckpointerDataInterface::registerData(Checkpointer *checkpointer) {
68  if (mMPIBlock) {
69  return Response::NO_ACTION;
70  }
71  else {
72  mMPIBlock = checkpointer->getMPIBlock();
73  checkpointer->addObserver(this);
74  return Response::SUCCESS;
75  }
76 }
77 
78 } // namespace PV
static bool completed(Status &a)
Definition: Response.hpp:49