RxCpp
The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
rx-trace.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2 
3 #pragma once
4 
5 #if !defined(RXCPP_RX_TRACE_HPP)
6 #define RXCPP_RX_TRACE_HPP
7 
8 #include <iostream>
9 #include <exception>
10 #include <atomic>
11 
12 namespace rxcpp {
13 
14 struct trace_id
15 {
17  static std::atomic<unsigned long> id(0xB0000000);
18  return trace_id{++id};
19  }
20  unsigned long id;
21 };
22 
23 inline bool operator==(const trace_id& lhs, const trace_id& rhs) {
24  return lhs.id == rhs.id;
25 }
26 inline bool operator!=(const trace_id& lhs, const trace_id& rhs) {
27  return !(lhs==rhs);
28 }
29 
30 inline bool operator<(const trace_id& lhs, const trace_id& rhs) {
31  if ((lhs.id & 0xF0000000) != (rhs.id & 0xF0000000)) std::terminate();
32  return lhs.id < rhs.id;
33 }
34 inline bool operator>(const trace_id& lhs, const trace_id& rhs) {
35  return rhs<lhs;
36 }
37 
38 inline std::ostream& operator<< (std::ostream& os, const trace_id& id) {
39  return os << std::hex << id.id << std::dec;
40 }
41 
42 struct trace_noop
43 {
44  template<class Worker, class Schedulable>
45  inline void schedule_enter(const Worker&, const Schedulable&) {}
46  template<class Worker>
47  inline void schedule_return(const Worker&) {}
48  template<class Worker, class When, class Schedulable>
49  inline void schedule_when_enter(const Worker&, const When&, const Schedulable&) {}
50  template<class Worker>
51  inline void schedule_when_return(const Worker&) {}
52 
53  template<class Schedulable>
54  inline void action_enter(const Schedulable&) {}
55  template<class Schedulable>
56  inline void action_return(const Schedulable&) {}
57  template<class Schedulable>
58  inline void action_recurse(const Schedulable&) {}
59 
60  template<class Observable, class Subscriber>
61  inline void subscribe_enter(const Observable& , const Subscriber& ) {}
62  template<class Observable>
63  inline void subscribe_return(const Observable& ) {}
64 
65  template<class SubscriberFrom, class SubscriberTo>
66  inline void connect(const SubscriberFrom&, const SubscriberTo&) {}
67 
68  template<class OperatorSource, class OperatorChain, class Subscriber, class SubscriberLifted>
69  inline void lift_enter(const OperatorSource&, const OperatorChain&, const Subscriber&, const SubscriberLifted&) {}
70  template<class OperatorSource, class OperatorChain>
71  inline void lift_return(const OperatorSource&, const OperatorChain&) {}
72 
73  template<class SubscriptionState>
74  inline void unsubscribe_enter(const SubscriptionState&) {}
75  template<class SubscriptionState>
76  inline void unsubscribe_return(const SubscriptionState&) {}
77 
78  template<class SubscriptionState, class Subscription>
79  inline void subscription_add_enter(const SubscriptionState&, const Subscription&) {}
80  template<class SubscriptionState>
81  inline void subscription_add_return(const SubscriptionState&) {}
82 
83  template<class SubscriptionState, class WeakSubscription>
84  inline void subscription_remove_enter(const SubscriptionState&, const WeakSubscription&) {}
85  template<class SubscriptionState>
86  inline void subscription_remove_return(const SubscriptionState&) {}
87 
88  template<class Subscriber>
89  inline void create_subscriber(const Subscriber&) {}
90 
91  template<class Subscriber, class T>
92  inline void on_next_enter(const Subscriber&, const T&) {}
93  template<class Subscriber>
94  inline void on_next_return(const Subscriber&) {}
95 
96  template<class Subscriber>
97  inline void on_error_enter(const Subscriber&, const std::exception_ptr&) {}
98  template<class Subscriber>
99  inline void on_error_return(const Subscriber&) {}
100 
101  template<class Subscriber>
102  inline void on_completed_enter(const Subscriber&) {}
103  template<class Subscriber>
104  inline void on_completed_return(const Subscriber&) {}
105 };
106 
107 struct trace_tag {};
108 
109 }
110 
111 inline auto rxcpp_trace_activity(...) -> rxcpp::trace_noop;
112 
113 
114 #endif
void action_recurse(const Schedulable &)
Definition: rx-trace.hpp:58
Definition: rx-trace.hpp:42
void schedule_enter(const Worker &, const Schedulable &)
Definition: rx-trace.hpp:45
bool operator>(const trace_id &lhs, const trace_id &rhs)
Definition: rx-trace.hpp:34
Definition: rx-all.hpp:26
void subscribe_return(const Observable &)
Definition: rx-trace.hpp:63
bool operator<(const subscription &lhs, const subscription &rhs)
Definition: rx-subscription.hpp:186
void subscription_add_return(const SubscriptionState &)
Definition: rx-trace.hpp:81
void create_subscriber(const Subscriber &)
Definition: rx-trace.hpp:89
void subscription_remove_return(const SubscriptionState &)
Definition: rx-trace.hpp:86
void schedule_return(const Worker &)
Definition: rx-trace.hpp:47
void schedule_when_return(const Worker &)
Definition: rx-trace.hpp:51
void lift_enter(const OperatorSource &, const OperatorChain &, const Subscriber &, const SubscriberLifted &)
Definition: rx-trace.hpp:69
auto rxcpp_trace_activity(...) -> rxcpp::trace_noop
Definition: rx-trace.hpp:14
std::ostream & operator<<(std::ostream &os, const trace_id &id)
Definition: rx-trace.hpp:38
void on_error_return(const Subscriber &)
Definition: rx-trace.hpp:99
void on_next_enter(const Subscriber &, const T &)
Definition: rx-trace.hpp:92
unsigned long id
Definition: rx-trace.hpp:20
void subscription_add_enter(const SubscriptionState &, const Subscription &)
Definition: rx-trace.hpp:79
void subscription_remove_enter(const SubscriptionState &, const WeakSubscription &)
Definition: rx-trace.hpp:84
void on_completed_enter(const Subscriber &)
Definition: rx-trace.hpp:102
bool operator!=(const dynamic_grouped_observable< K, T > &lhs, const dynamic_grouped_observable< K, T > &rhs)
Definition: rx-grouped_observable.hpp:103
void action_return(const Schedulable &)
Definition: rx-trace.hpp:56
bool operator==(const dynamic_grouped_observable< K, T > &lhs, const dynamic_grouped_observable< K, T > &rhs)
Definition: rx-grouped_observable.hpp:99
void unsubscribe_return(const SubscriptionState &)
Definition: rx-trace.hpp:76
void lift_return(const OperatorSource &, const OperatorChain &)
Definition: rx-trace.hpp:71
void schedule_when_enter(const Worker &, const When &, const Schedulable &)
Definition: rx-trace.hpp:49
Definition: rx-trace.hpp:107
void action_enter(const Schedulable &)
Definition: rx-trace.hpp:54
static trace_id make_next_id_subscriber()
Definition: rx-trace.hpp:16
void on_next_return(const Subscriber &)
Definition: rx-trace.hpp:94
void subscribe_enter(const Observable &, const Subscriber &)
Definition: rx-trace.hpp:61
void on_error_enter(const Subscriber &, const std::exception_ptr &)
Definition: rx-trace.hpp:97
void on_completed_return(const Subscriber &)
Definition: rx-trace.hpp:104
void unsubscribe_enter(const SubscriptionState &)
Definition: rx-trace.hpp:74
void connect(const SubscriberFrom &, const SubscriberTo &)
Definition: rx-trace.hpp:66