PetaVision  Alpha
BaseConnection.hpp
1 /*
2  * BaseConnection.hpp
3  *
4  *
5  * Created on Sep 19, 2014
6  * Author: Pete Schultz
7  */
8 
9 #ifndef BASECONNECTION_HPP_
10 #define BASECONNECTION_HPP_
11 
12 #include "columns/BaseObject.hpp"
13 #include "components/ConnectionData.hpp"
14 #include "delivery/BaseDelivery.hpp"
15 #include "observerpattern/Subject.hpp"
16 #include "utils/MapLookupByType.hpp"
17 #include "utils/Timer.hpp"
18 
19 namespace PV {
20 
21 class HyPerCol;
22 
23 class BaseConnection : public BaseObject, public Subject {
24  public:
25  BaseConnection(char const *name, HyPerCol *hc);
26 
27  virtual ~BaseConnection();
28 
29  virtual void addObserver(Observer *observer) override;
30 
31  template <typename S>
32  S *getComponentByType();
33 
34  virtual Response::Status respond(std::shared_ptr<BaseMessage const> message) override;
35 
39  int deliver() {
40  mDeliveryObject->deliver();
41  return PV_SUCCESS;
42  }
43 
44  void deliverUnitInput(float *recvBuffer) { mDeliveryObject->deliverUnitInput(recvBuffer); }
45 
46  bool isAllInputReady() { return mDeliveryObject->isAllInputReady(); }
47 
48  HyPerLayer *getPre() const { return mConnectionData->getPre(); }
49  HyPerLayer *getPost() const { return mConnectionData->getPost(); }
50  char const *getPreLayerName() const { return mConnectionData->getPreLayerName(); }
51  char const *getPostLayerName() const { return mConnectionData->getPostLayerName(); }
52 
53  ChannelType getChannelCode() const { return mDeliveryObject->getChannelCode(); }
54  bool getReceiveGpu() const { return mDeliveryObject->getReceiveGpu(); }
55 
56  protected:
58 
59  int initialize(char const *name, HyPerCol *hc);
60 
61  virtual void defineComponents();
62 
63  virtual ConnectionData *createConnectionData();
64  virtual BaseDelivery *createDeliveryObject();
65 
66  int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
67 
68  Response::Status
69  respondConnectionWriteParams(std::shared_ptr<ConnectionWriteParamsMessage const> message);
70 
71  Response::Status
72  respondConnectionFinalizeUpdate(std::shared_ptr<ConnectionFinalizeUpdateMessage const> message);
73 
74  Response::Status respondConnectionOutput(std::shared_ptr<ConnectionOutputMessage const> message);
75 
76  virtual Response::Status
77  communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) override;
78 
79 #ifdef PV_USE_CUDA
80  virtual Response::Status
81  setCudaDevice(std::shared_ptr<SetCudaDeviceMessage const> message) override;
82 #endif // PV_USE_CUDA
83 
84  virtual Response::Status allocateDataStructures() override;
85 
86  virtual Response::Status registerData(Checkpointer *checkpointer) override;
87 
88  virtual void deleteComponents();
89 
90  protected:
91  ObserverTable mComponentTable;
92 
93  private:
94  ConnectionData *mConnectionData = nullptr;
95  BaseDelivery *mDeliveryObject = nullptr;
96 
97  Timer *mIOTimer = nullptr;
98 
99 }; // class BaseConnection
100 
101 template <typename S>
102 S *BaseConnection::getComponentByType() {
103  return mapLookupByType<S>(mComponentTable.getObjectMap(), getDescription());
104 }
105 
106 } // namespace PV
107 
108 #endif // BASECONNECTION_HPP_
char const * getPostLayerName() const
HyPerLayer * getPre()
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void addObserver(Observer *observer) override
char const * getPreLayerName() const
HyPerLayer * getPost()
virtual bool isAllInputReady()