@@ -40,13 +40,21 @@ typedef std::function<void(CaliperMetadataAccessInterface&,const std::vector<cal
40
40
class Channel
41
41
{
42
42
struct ChannelImpl ;
43
-
44
43
std::shared_ptr<ChannelImpl> mP ;
45
44
46
45
Channel (cali_id_t id, const char * name, const RuntimeConfig& cfg);
47
46
48
47
public:
49
48
49
+ constexpr Channel ()
50
+ : mP { nullptr } { }
51
+
52
+ Channel (const Channel&) = default ;
53
+ Channel (Channel&&) = default ;
54
+
55
+ Channel& operator = (const Channel&) = default ;
56
+ Channel& operator = (Channel&&) = default ;
57
+
50
58
~Channel ();
51
59
52
60
// --- Events (callback functions)
@@ -175,9 +183,22 @@ class Channel
175
183
176
184
cali_id_t id () const ;
177
185
186
+ operator bool () const { return mP .use_count () > 0 ; }
187
+
178
188
friend class Caliper ;
189
+ friend bool operator == (const Channel&, const Channel&);
190
+ friend bool operator != (const Channel&, const Channel&);
179
191
};
180
192
193
+ inline bool operator == (const Channel& a, const Channel& b)
194
+ {
195
+ return a.mP == b.mP ;
196
+ }
197
+
198
+ inline bool operator != (const Channel& a, const Channel& b)
199
+ {
200
+ return a.mP != b.mP ;
201
+ }
181
202
182
203
// / \class Caliper
183
204
// / \brief The main interface for the caliper runtime system
@@ -493,7 +514,7 @@ class Caliper : public CaliperMetadataAccessInterface
493
514
// / \brief Return all global attributes for \a channel
494
515
// /
495
516
// /
496
- std::vector<Entry> get_globals (Channel* channel);
517
+ std::vector<Entry> get_globals (const Channel& channel);
497
518
498
519
// / \}
499
520
// / \name Explicit snapshot record manipulation
@@ -630,38 +651,32 @@ class Caliper : public CaliperMetadataAccessInterface
630
651
// / \param name Name of the channel. This is used to identify the channel
631
652
// / in %Caliper log output.
632
653
// / \param cfg The channel's runtime configuration.
633
- // / \return Pointer to the channel. Null pointer if the channel could
634
- // / not be created.
635
- Channel* create_channel (const char * name, const RuntimeConfig& cfg);
654
+ // / \return The channel
655
+ Channel create_channel (const char * name, const RuntimeConfig& cfg);
636
656
637
657
// / \brief Return all existing channels
638
- std::vector<Channel* > get_all_channels ();
658
+ std::vector<Channel> get_all_channels ();
639
659
640
- // / \brief Return pointer to channel object with the given ID.
641
- // /
642
- // / The call returns a pointer to the created channel object. %Caliper
643
- // / retains ownership of the channel object. This pointer becomes invalid
644
- // / when the channel is deleted. %Caliper notifies users with the
645
- // / finish_evt callback when an channel is about to be deleted.
646
- Channel* get_channel (cali_id_t id);
660
+ // / \brief Return the channel with the given ID or an empty Channel object.
661
+ Channel get_channel (cali_id_t id);
647
662
648
663
// / \brief Delete the given channel.
649
664
// /
650
665
// / Deleting channels is \b not thread-safe.
651
- void delete_channel (Channel* chn);
666
+ void delete_channel (Channel& chn);
652
667
653
668
// / \brief Activate the given channel.
654
669
// /
655
670
// / Inactive channels will not track or process annotations and other
656
671
// / blackboard updates.
657
- void activate_channel (Channel* chn);
672
+ void activate_channel (Channel& chn);
658
673
659
674
// / \brief Deactivate the given channel.
660
675
// / \copydetails Caliper::activate_channel
661
- void deactivate_channel (Channel* chn);
676
+ void deactivate_channel (Channel& chn);
662
677
663
678
// / \brief Flush and delete all channels
664
- void finalize ();
679
+ void finalize ();
665
680
666
681
// / \}
667
682
0 commit comments