progressnotifier.cpp
Go to the documentation of this file.
1 /*
2 ** Copyright (C) 2012 Aldebaran Robotics
3 ** See COPYING for the license
4 */
5 
6 #include <qicore/file.hpp>
7 #include <qi/macro.hpp>
8 #include <qi/anymodule.hpp>
9 
10 qiLogCategory("qicore.file.progressnotifierimpl");
11 
12 namespace qi
13 {
15  : public ProgressNotifier
16  {
17  public:
18  explicit ProgressNotifierImpl(Future<void> operationFuture)
19  : _opFuture(std::move(operationFuture))
20  {
22  }
23 
24  void reset() override
25  {
27  this->progress.set(0.0);
28  }
29 
30  void notifyRunning() override
31  {
32  if (this->status.get().value() != ProgressNotifier::Status_Idle)
33  qiLogError()
34  << "ProgressNotifier must be Idle to be allowed to switch to Running status.";
35 
37  }
38 
39  void notifyFinished() override
40  {
41  if (!isRunning())
42  qiLogError()
43  << "ProgressNotifier must be Running to be allowed to switch to Finished status.";
44 
46  }
47 
48  void notifyCanceled() override
49  {
50  if (!isRunning())
51  qiLogError()
52  << "ProgressNotifier must be Running to be allowed to switch to Canceled status.";
54  }
55 
56  void notifyFailed() override
57  {
58  if (!isRunning())
59  qiLogError()
60  << "ProgressNotifier must be Running to be allowed to switch to Failed status.";
62  }
63 
64  void notifyProgressed(double newProgress) override
65  {
66  if (!isRunning())
67  qiLogError()
68  << "ProgressNotifier must be Running to be allowed to notify any progress.";
69  this->progress.set(newProgress);
70  }
71 
72  bool isRunning() const override
73  {
74  return this->status.get().value() == ProgressNotifier::Status_Running;
75  }
76 
77  Future<void> waitForFinished() override
78  {
79  return _opFuture;
80  }
81 
82  Future<void> _opFuture;
83 
84  // Deprecated members:
85  void _reset() override
86  {
87  return reset();
88  }
89 
90  void _notifyRunning() override
91  {
92  return notifyRunning();
93  }
94 
95  void _notifyFinished() override
96  {
97  return notifyFinished();
98  }
99 
100  void _notifyCanceled() override
101  {
102  return notifyCanceled();
103  }
104 
105  void _notifyFailed() override
106  {
107  return notifyFailed();
108  }
109 
110  void _notifyProgressed(double newProgress) override
111  {
112  return notifyProgressed(newProgress);
113  }
114  };
115 
116 
118 {
119  ::qi::ObjectTypeBuilder<ProgressNotifier> builder;
120  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, notifyRunning);
121  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, notifyFinished);
122  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, notifyCanceled);
123  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, notifyFailed);
124  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, notifyProgressed);
125  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, waitForFinished);
126  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, isRunning);
127  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, reset);
128  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, progress);
129  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, status);
130 
131  // Deprecated members:
132 QI_WARNING_PUSH()
133 QI_WARNING_DISABLE(4996, deprecated-declarations)
134  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, _reset);
135  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, _notifyRunning);
136  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, _notifyFinished);
137  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, _notifyCanceled);
138  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, _notifyFailed);
139  QI_OBJECT_BUILDER_ADVERTISE(builder, ProgressNotifier, _notifyProgressed);
140 QI_WARNING_POP()
141 
142  builder.registerType();
143 
144  {
145  qi::detail::ForceProxyInclusion<ProgressNotifier>().dummyCall();
146  qi::registerType(typeid(ProgressNotifierImpl), qi::typeOf<ProgressNotifier>());
147  ProgressNotifierImpl* ptr = static_cast<ProgressNotifierImpl*>(reinterpret_cast<void*>(0x10000));
148  ProgressNotifier* pptr = ptr;
149  intptr_t offset = reinterpret_cast<intptr_t>(pptr)-reinterpret_cast<intptr_t>(ptr);
150  if (offset)
151  {
152  qiLogError("qitype.register") << "non-zero offset for implementation ProgressNotifierImpl of ProgressNotifier,"
153  "call will fail at runtime";
154  throw std::runtime_error("non-zero offset between implementation and interface");
155  }
156  }
157 
158 }
159 
160 ProgressNotifierPtr createProgressNotifier(Future<void> operationFuture)
161 {
162  return boost::make_shared<ProgressNotifierImpl>(std::move(operationFuture));
163 }
164 
165 void registerProgressNotifierCreation(qi::ModuleBuilder& mb)
166 {
167  mb.advertiseMethod("createProgressNotifier", &createProgressNotifier);
168 }
169 }
qi::ProgressNotifierPtr
qi::Object< ProgressNotifier > ProgressNotifierPtr
Pointer to a ProgressNotifier with shared/remote semantic.
Definition: file.hpp:114
qi::ProgressNotifier::Status_Running
@ Status_Running
The operation is currently running.
Definition: file.hpp:38
qi::ProgressNotifierImpl::_reset
void _reset() override
Definition: progressnotifier.cpp:85
qi::ProgressNotifierImpl::_notifyFinished
void _notifyFinished() override
Definition: progressnotifier.cpp:95
qi::ProgressNotifierImpl::notifyProgressed
void notifyProgressed(double newProgress) override
Definition: progressnotifier.cpp:64
qi::ProgressNotifierImpl::notifyCanceled
void notifyCanceled() override
Definition: progressnotifier.cpp:48
qi::ProgressNotifierImpl::ProgressNotifierImpl
ProgressNotifierImpl(Future< void > operationFuture)
Definition: progressnotifier.cpp:18
qi::ProgressNotifierImpl::_notifyCanceled
void _notifyCanceled() override
Definition: progressnotifier.cpp:100
qi::ProgressNotifier::Status_Canceled
@ Status_Canceled
The operation has been canceled by the user.
Definition: file.hpp:41
qi::ProgressNotifierImpl::_notifyProgressed
void _notifyProgressed(double newProgress) override
Definition: progressnotifier.cpp:110
qi::registerProgressNotifierCreation
void registerProgressNotifierCreation(qi::ModuleBuilder &mb)
Definition: progressnotifier.cpp:165
file.hpp
qi::ProgressNotifier::Status_Failed
@ Status_Failed
The operation has failed.
Definition: file.hpp:40
qi::ProgressNotifierImpl
Definition: progressnotifier.cpp:14
qi::ProgressNotifierImpl::_notifyFailed
void _notifyFailed() override
Definition: progressnotifier.cpp:105
qi::ProgressNotifier
Definition: file.hpp:26
qi::_qiregisterProgressNotifier
void _qiregisterProgressNotifier()
Definition: progressnotifier.cpp:117
qi::ProgressNotifierImpl::waitForFinished
Future< void > waitForFinished() override
Definition: progressnotifier.cpp:77
qi::ProgressNotifierImpl::isRunning
bool isRunning() const override
Definition: progressnotifier.cpp:72
qi::ProgressNotifierImpl::reset
void reset() override
Definition: progressnotifier.cpp:24
qi
Definition: file.hpp:21
qi::createProgressNotifier
QICORE_API ProgressNotifierPtr createProgressNotifier(Future< void > operationFuture={})
Definition: progressnotifier.cpp:160
qi::ProgressNotifier::progress
Property< double > progress
Definition: file.hpp:55
qi::ProgressNotifierImpl::notifyFailed
void notifyFailed() override
Definition: progressnotifier.cpp:56
qi::ProgressNotifierImpl::notifyRunning
void notifyRunning() override
Definition: progressnotifier.cpp:30
qi::ProgressNotifier::Status_Idle
@ Status_Idle
The operation has not start yet.
Definition: file.hpp:37
qi::ProgressNotifierImpl::_opFuture
Future< void > _opFuture
Definition: progressnotifier.cpp:82
qi::ProgressNotifier::status
Property< Status > status
Definition: file.hpp:47
qi::ProgressNotifier::Status_Finished
@ Status_Finished
The operation finished successfully.
Definition: file.hpp:39
qi::ProgressNotifierImpl::_notifyRunning
void _notifyRunning() override
Definition: progressnotifier.cpp:90
qiLogCategory
qiLogCategory("qicore.file.progressnotifierimpl")
qi::ProgressNotifierImpl::notifyFinished
void notifyFinished() override
Definition: progressnotifier.cpp:39


naoqi_libqicore
Author(s): Aldebaran
autogenerated on Wed Sep 14 2022 02:22:41