Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
network_task.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_netio/target_libuv/roc_netio/network_task.h
10 //! @brief Network task.
11 
12 #ifndef ROC_NETIO_NETWORK_TASK_H_
13 #define ROC_NETIO_NETWORK_TASK_H_
14 
15 #include "roc_core/atomic.h"
17 #include "roc_core/optional.h"
18 #include "roc_core/semaphore.h"
19 #include "roc_core/shared_ptr.h"
20 #include "roc_netio/basic_port.h"
21 
22 namespace roc {
23 namespace netio {
24 
25 class NetworkLoop;
26 class INetworkTaskCompleter;
27 
28 //! Base class for network loop tasks.
30 public:
31  ~NetworkTask();
32 
33  //! Check that the task finished and succeeded.
34  bool success() const;
35 
36 protected:
37  friend class NetworkLoop;
38 
39  NetworkTask();
40 
41  //! Task state.
42  enum State {
43  StateInitialized,
44  StatePending,
45  StateClosingPort,
46  StateFinishing,
47  StateFinished
48  };
49 
50  //! Task implementation method.
52 
53  //! Task state, defines whether task is finished already.
54  //! The task becomes immutable after setting state to Finished.
56 
57  //! Task result, defines wether finished task succeeded or failed.
58  //! Makes sense only after setting state_ to Finished.
59  //! This atomic should be assigned before setting state_ to Finished.
61 
62  core::SharedPtr<BasicPort> port_; //!< On which port the task operates.
63  void* port_handle_; //!< Port handle.
64 
65  INetworkTaskCompleter* completer_; //!< Completion handler.
66  core::Optional<core::Semaphore> sem_; //!< Completion semaphore.
67 };
68 
69 } // namespace netio
70 } // namespace roc
71 
72 #endif // ROC_NETIO_NETWORK_TASK_H_
Atomic.
Base class for ports.
Optionally constructed object.
Definition: optional.h:25
Shared ownership intrusive pointer.
Definition: shared_ptr.h:32
Network task completion handler.
Network event loop thread.
Definition: network_loop.h:53
Base class for network loop tasks.
Definition: network_task.h:29
core::SharedPtr< BasicPort > port_
On which port the task operates.
Definition: network_task.h:62
void(NetworkLoop::* func_)(NetworkTask &)
Task implementation method.
Definition: network_task.h:51
void * port_handle_
Port handle.
Definition: network_task.h:63
INetworkTaskCompleter * completer_
Completion handler.
Definition: network_task.h:65
core::Atomic< int > state_
Task state, defines whether task is finished already. The task becomes immutable after setting state ...
Definition: network_task.h:55
bool success() const
Check that the task finished and succeeded.
core::Optional< core::Semaphore > sem_
Completion semaphore.
Definition: network_task.h:66
core::Atomic< int > success_
Task result, defines wether finished task succeeded or failed. Makes sense only after setting state_ ...
Definition: network_task.h:60
MpscQueue node.
Root namespace.
Optionally constructed object.
Shared ownership intrusive pointer.