1 #include <sdeventplus/exception.hpp> 2 #include <sdeventplus/source/child.hpp> 3 #include <type_traits> 4 #include <utility> 5 6 namespace sdeventplus 7 { 8 namespace source 9 { 10 11 Child::Child(const Event& event, pid_t pid, int options, Callback&& callback) : 12 Base(event, create_source(event, pid, options), std::false_type()), 13 callback(std::move(callback)) 14 { 15 } 16 17 pid_t Child::get_pid() const 18 { 19 pid_t pid; 20 int r = 21 event.getSdEvent()->sd_event_source_get_child_pid(source.get(), &pid); 22 if (r < 0) 23 { 24 throw SdEventError(-r, "sd_event_source_get_child_pid"); 25 } 26 return pid; 27 } 28 29 const Child::Callback& Child::get_callback() const 30 { 31 return callback; 32 } 33 34 sd_event_source* Child::create_source(const Event& event, pid_t pid, 35 int options) 36 { 37 sd_event_source* source; 38 int r = event.getSdEvent()->sd_event_add_child( 39 event.get(), &source, pid, options, childCallback, nullptr); 40 if (r < 0) 41 { 42 throw SdEventError(-r, "sd_event_add_child"); 43 } 44 return source; 45 } 46 47 int Child::childCallback(sd_event_source* source, const siginfo_t* si, 48 void* userdata) 49 { 50 return sourceCallback<Callback, Child, &Child::get_callback>( 51 "childCallback", source, userdata, si); 52 } 53 54 } // namespace source 55 } // namespace sdeventplus 56