m2etis  0.4
TimeValidity.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
22 #ifndef __M2ETIS_PUBSUB_VALIDITY_TIMEVALIDITY_H__
23 #define __M2ETIS_PUBSUB_VALIDITY_TIMEVALIDITY_H__
24 
25 #include <string>
26 
29 
30 namespace m2etis {
31 namespace pubsub {
32 namespace validity {
33 
34  template<uint64_t MIN, uint64_t MAX>
35  class TimeValidity : public BaseValidity {
36  public:
38 
39  explicit TimeValidity(PubSubSystemEnvironment * pssi) : BaseValidity(pssi), _pssi(pssi) {}
40  virtual ~TimeValidity() {}
41 
43  message::TimeValidityInfo::Ptr info = boost::static_pointer_cast<message::TimeValidityInfo>(vInfo);
44  if (info->_timeStamp == UINT64_MAX) {
45  info->_timeStamp = _pssi->clock_.getTime();
46  }
47  }
48 
50 
52 
53  bool isValid(typename message::ValidityInfo::Ptr vInfo) {
54  message::TimeValidityInfo::Ptr info = boost::static_pointer_cast<message::TimeValidityInfo>(vInfo);
55  uint64_t cT = _pssi->clock_.getTime();
56  if (info->_timeStamp < cT && (cT - info->_timeStamp > MAX || cT - info->_timeStamp < MIN)) {
57  return false;
58  }
59  return true;
60  }
61 
62  private:
64  };
65 
66 } /* namespace validity */
67 } /* namespace pubsub */
68 } /* namespace m2etis */
69 
70 #endif /* __M2ETIS_PUBSUB_VALIDITY_TIMEVALIDITY_H__ */
71 
void processNotifyPayload(typename message::ValidityInfo::Ptr vInfo)
processes received Notify message
Definition: TimeValidity.h:51
bool isValid(typename message::ValidityInfo::Ptr vInfo)
checks whether a message is valid or has to be stopped
Definition: TimeValidity.h:53
message::TimeValidityInfo ValidityInfoType
Definition: TimeValidity.h:37
void configureValidityInfo(typename message::ValidityInfo::Ptr vInfo)
configures ValidityInfo before sending
Definition: TimeValidity.h:42
void processPublishPayload(typename message::ValidityInfo::Ptr vInfo)
processes received Publish message
Definition: TimeValidity.h:49
util::Clock< util::RealTimeClock > clock_
uint64_t getTime() const
Will return the time since the Clock on the rendezvouz node has started.
Definition: Clock.h:68
boost::shared_ptr< TimeValidityInfo > Ptr
TimeValidity(PubSubSystemEnvironment *pssi)
Definition: TimeValidity.h:39
boost::shared_ptr< ValidityInfo > Ptr
Definition: ValidityInfo.h:31