MotionLib  1.0.0
SamBuCa motion library
NotificationWorker.hpp
1 /*
2 ** Copyright (C) 2022 CERN
3 **
4 ** This software is provided 'as-is', without any express or implied
5 ** warranty. In no event will the authors be held liable for any damages
6 ** arising from the use of this software.
7 **
8 ** Permission is granted to anyone to use this software for any purpose,
9 ** including commercial applications, and to alter it and redistribute it
10 ** freely, subject to the following restrictions:
11 **
12 ** 1. The origin of this software must not be misrepresented; you must not
13 ** claim that you wrote the original software. If you use this software
14 ** in a product, an acknowledgment in the product documentation would be
15 ** appreciated but is not required.
16 ** 2. Altered source versions must be plainly marked as such, and must not be
17 ** misrepresented as being the original software.
18 ** 3. This notice may not be removed or altered from any source distribution.
19 **
20 ** Created on: 2022-07-21T16:37:09
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #ifndef NOTIFICATIONWORKER_HPP__
25 #define NOTIFICATIONWORKER_HPP__
26 
27 #include <memory>
28 #include <set>
29 
30 #include <ccut/Worker.hpp>
31 
32 #include "device/DeviceBase.hpp"
33 
34 namespace smc {
35 namespace internal {
36 
37 class DeviceStore;
38 
44 class NotificationWorker : public ccut::Worker
45 {
46 public:
47  typedef std::shared_ptr<NotificationWorker> Shared;
48 
49  explicit NotificationWorker(const std::shared_ptr<DeviceStore> &store,
50  std::size_t numThreads = 3,
51  std::size_t maxSize = 2048);
53 
54  template<typename T>
55  void post(T fun)
56  {
57  ccut::Worker::post([this, fun]() { fun(m_store.lock()); });
58  }
59 
60  void notify(const std::shared_ptr<std::set<DeviceId>> &updates);
61 
62 protected:
63  std::weak_ptr<DeviceStore> m_store;
64 };
65 
68 } // namespace internal
69 } // namespace smc
70 
71 #endif
main motion-lib namespace
Definition: Client.cpp:30