Home | History | Annotate | Download | only in rxcpp
      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 {
     16     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 
     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, class ErrorPtr>
     97     inline void on_error_enter(const Subscriber&, const ErrorPtr&) {}
     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
    115