• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
make_next_id_subscriberrxcpp::trace_id16     static inline trace_id make_next_id_subscriber() {
17         static std::atomic<unsigned long> id(0xB0000000);
18         return trace_id{++id};
19     }
20     unsigned long id;
21 };
22 
operator ==(const trace_id & lhs,const trace_id & rhs)23 inline bool operator==(const trace_id& lhs, const trace_id& rhs) {
24     return lhs.id == rhs.id;
25 }
operator !=(const trace_id & lhs,const trace_id & rhs)26 inline bool operator!=(const trace_id& lhs, const trace_id& rhs) {
27     return !(lhs==rhs);
28 }
29 
operator <(const trace_id & lhs,const trace_id & rhs)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 }
operator >(const trace_id & lhs,const trace_id & rhs)34 inline bool operator>(const trace_id& lhs, const trace_id& rhs) {
35     return rhs<lhs;
36 }
37 
operator <<(std::ostream & os,const trace_id & id)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>
schedule_enterrxcpp::trace_noop45     inline void schedule_enter(const Worker&, const Schedulable&) {}
46     template<class Worker>
schedule_returnrxcpp::trace_noop47     inline void schedule_return(const Worker&) {}
48     template<class Worker, class When, class Schedulable>
schedule_when_enterrxcpp::trace_noop49     inline void schedule_when_enter(const Worker&, const When&, const Schedulable&) {}
50     template<class Worker>
schedule_when_returnrxcpp::trace_noop51     inline void schedule_when_return(const Worker&) {}
52 
53     template<class Schedulable>
action_enterrxcpp::trace_noop54     inline void action_enter(const Schedulable&) {}
55     template<class Schedulable>
action_returnrxcpp::trace_noop56     inline void action_return(const Schedulable&) {}
57     template<class Schedulable>
action_recurserxcpp::trace_noop58     inline void action_recurse(const Schedulable&) {}
59 
60     template<class Observable, class Subscriber>
subscribe_enterrxcpp::trace_noop61     inline void subscribe_enter(const Observable& , const Subscriber& ) {}
62     template<class Observable>
subscribe_returnrxcpp::trace_noop63     inline void subscribe_return(const Observable& ) {}
64 
65     template<class SubscriberFrom, class SubscriberTo>
connectrxcpp::trace_noop66     inline void connect(const SubscriberFrom&, const SubscriberTo&) {}
67 
68     template<class OperatorSource, class OperatorChain, class Subscriber, class SubscriberLifted>
lift_enterrxcpp::trace_noop69     inline void lift_enter(const OperatorSource&, const OperatorChain&, const Subscriber&, const SubscriberLifted&) {}
70     template<class OperatorSource, class OperatorChain>
lift_returnrxcpp::trace_noop71     inline void lift_return(const OperatorSource&, const OperatorChain&) {}
72 
73     template<class SubscriptionState>
unsubscribe_enterrxcpp::trace_noop74     inline void unsubscribe_enter(const SubscriptionState&) {}
75     template<class SubscriptionState>
unsubscribe_returnrxcpp::trace_noop76     inline void unsubscribe_return(const SubscriptionState&) {}
77 
78     template<class SubscriptionState, class Subscription>
subscription_add_enterrxcpp::trace_noop79     inline void subscription_add_enter(const SubscriptionState&, const Subscription&) {}
80     template<class SubscriptionState>
subscription_add_returnrxcpp::trace_noop81     inline void subscription_add_return(const SubscriptionState&) {}
82 
83     template<class SubscriptionState, class WeakSubscription>
subscription_remove_enterrxcpp::trace_noop84     inline void subscription_remove_enter(const SubscriptionState&, const WeakSubscription&) {}
85     template<class SubscriptionState>
subscription_remove_returnrxcpp::trace_noop86     inline void subscription_remove_return(const SubscriptionState&) {}
87 
88     template<class Subscriber>
create_subscriberrxcpp::trace_noop89     inline void create_subscriber(const Subscriber&) {}
90 
91     template<class Subscriber, class T>
on_next_enterrxcpp::trace_noop92     inline void on_next_enter(const Subscriber&, const T&) {}
93     template<class Subscriber>
on_next_returnrxcpp::trace_noop94     inline void on_next_return(const Subscriber&) {}
95 
96     template<class Subscriber, class ErrorPtr>
on_error_enterrxcpp::trace_noop97     inline void on_error_enter(const Subscriber&, const ErrorPtr&) {}
98     template<class Subscriber>
on_error_returnrxcpp::trace_noop99     inline void on_error_return(const Subscriber&) {}
100 
101     template<class Subscriber>
on_completed_enterrxcpp::trace_noop102     inline void on_completed_enter(const Subscriber&) {}
103     template<class Subscriber>
on_completed_returnrxcpp::trace_noop104     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
115