pub struct ServiceControlAccept(/* private fields */);
Expand description
Flags describing accepted types of service control events.
Implementations§
Source§impl ServiceControlAccept
impl ServiceControlAccept
Sourcepub const NETBIND_CHANGE: Self
pub const NETBIND_CHANGE: Self
The service is a network component that can accept changes in its binding without being
stopped and restarted. This allows service to receive ServiceControl::Netbind*
family of events.
Sourcepub const PARAM_CHANGE: Self
pub const PARAM_CHANGE: Self
The service can reread its startup parameters without being stopped and restarted.
Sourcepub const PAUSE_CONTINUE: Self
pub const PAUSE_CONTINUE: Self
The service can be paused and continued.
Sourcepub const PRESHUTDOWN: Self
pub const PRESHUTDOWN: Self
The service can perform preshutdown tasks. Mutually exclusive with shutdown.
Sourcepub const SHUTDOWN: Self
pub const SHUTDOWN: Self
The service is notified when system shutdown occurs. Mutually exclusive with preshutdown.
Sourcepub const HARDWARE_PROFILE_CHANGE: Self
pub const HARDWARE_PROFILE_CHANGE: Self
The service is notified when the computer’s hardware profile has changed. This enables the system to send SERVICE_CONTROL_HARDWAREPROFILECHANGE notifications to the service.
Sourcepub const POWER_EVENT: Self
pub const POWER_EVENT: Self
The service is notified when the computer’s power status has changed. This enables the system to send SERVICE_CONTROL_POWEREVENT notifications to the service.
Sourcepub const SESSION_CHANGE: Self
pub const SESSION_CHANGE: Self
The service is notified when the computer’s session status has changed. This enables the system to send SERVICE_CONTROL_SESSIONCHANGE notifications to the service.
Sourcepub const TIME_CHANGE: Self
pub const TIME_CHANGE: Self
The service is notified when the system time has changed. This enables the system to send SERVICE_CONTROL_TIMECHANGE notifications to the service.
Sourcepub const TRIGGER_EVENT: Self
pub const TRIGGER_EVENT: Self
The service is notified when an event for which the service has registered occurs. This enables the system to send SERVICE_CONTROL_TRIGGEREVENT notifications to the service.
Source§impl ServiceControlAccept
impl ServiceControlAccept
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Get a flags value with all bits unset.
Examples found in repository?
71 pub fn run_service() -> Result<()> {
72 // Create a channel to be able to poll a stop event from the service worker loop.
73 let (shutdown_tx, shutdown_rx) = mpsc::channel();
74
75 // Define system service event handler that will be receiving service events.
76 let event_handler = move |control_event| -> ServiceControlHandlerResult {
77 match control_event {
78 // Notifies a service to report its current status information to the service
79 // control manager. Always return NoError even if not implemented.
80 ServiceControl::Interrogate => ServiceControlHandlerResult::NoError,
81
82 // Handle stop
83 ServiceControl::Stop => {
84 shutdown_tx.send(()).unwrap();
85 ServiceControlHandlerResult::NoError
86 }
87
88 // treat the UserEvent as a stop request
89 ServiceControl::UserEvent(code) => {
90 if code.to_raw() == 130 {
91 shutdown_tx.send(()).unwrap();
92 }
93 ServiceControlHandlerResult::NoError
94 }
95
96 _ => ServiceControlHandlerResult::NotImplemented,
97 }
98 };
99
100 // Register system service event handler.
101 // The returned status handle should be used to report service status changes to the system.
102 let status_handle = service_control_handler::register(SERVICE_NAME, event_handler)?;
103
104 // Tell the system that service is running
105 status_handle.set_service_status(ServiceStatus {
106 service_type: SERVICE_TYPE,
107 current_state: ServiceState::Running,
108 controls_accepted: ServiceControlAccept::STOP,
109 exit_code: ServiceExitCode::Win32(0),
110 checkpoint: 0,
111 wait_hint: Duration::default(),
112 process_id: None,
113 })?;
114
115 // For demo purposes this service sends a UDP packet once a second.
116 let loopback_ip = IpAddr::from(LOOPBACK_ADDR);
117 let sender_addr = SocketAddr::new(loopback_ip, 0);
118 let receiver_addr = SocketAddr::new(loopback_ip, RECEIVER_PORT);
119 let msg = PING_MESSAGE.as_bytes();
120 let socket = UdpSocket::bind(sender_addr).unwrap();
121
122 loop {
123 let _ = socket.send_to(msg, receiver_addr);
124
125 // Poll shutdown event.
126 match shutdown_rx.recv_timeout(Duration::from_secs(1)) {
127 // Break the loop either upon stop or channel disconnect
128 Ok(_) | Err(mpsc::RecvTimeoutError::Disconnected) => break,
129
130 // Continue work if no events were received within the timeout
131 Err(mpsc::RecvTimeoutError::Timeout) => (),
132 };
133 }
134
135 // Tell the system that service has stopped.
136 status_handle.set_service_status(ServiceStatus {
137 service_type: SERVICE_TYPE,
138 current_state: ServiceState::Stopped,
139 controls_accepted: ServiceControlAccept::empty(),
140 exit_code: ServiceExitCode::Win32(0),
141 checkpoint: 0,
142 wait_hint: Duration::default(),
143 process_id: None,
144 })?;
145
146 Ok(())
147 }
Sourcepub const fn bits(&self) -> u32
pub const fn bits(&self) -> u32
Get the underlying bits value.
The returned value is exactly the bits set in this flags value.
Sourcepub const fn from_bits(bits: u32) -> Option<Self>
pub const fn from_bits(bits: u32) -> Option<Self>
Convert from a bits value.
This method will return None
if any unknown bits are set.
Sourcepub const fn from_bits_truncate(bits: u32) -> Self
pub const fn from_bits_truncate(bits: u32) -> Self
Convert from a bits value, unsetting any unknown bits.
Sourcepub const fn from_bits_retain(bits: u32) -> Self
pub const fn from_bits_retain(bits: u32) -> Self
Convert from a bits value exactly.
Sourcepub fn from_name(name: &str) -> Option<Self>
pub fn from_name(name: &str) -> Option<Self>
Get a flags value with the bits of a flag with the given name set.
This method will return None
if name
is empty or doesn’t
correspond to any named flag.
Sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Whether any set bits in a source flags value are also set in a target flags value.
Sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Whether all set bits in a source flags value are also set in a target flags value.
Sourcepub fn remove(&mut self, other: Self)
pub fn remove(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
remove
won’t truncate other
, but the !
operator will.
Sourcepub fn toggle(&mut self, other: Self)
pub fn toggle(&mut self, other: Self)
The bitwise exclusive-or (^
) of the bits in two flags values.
Sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Call insert
when value
is true
or remove
when value
is false
.
Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
The bitwise and (&
) of the bits in two flags values.
Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
The bitwise or (|
) of the bits in two flags values.
Sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
difference
won’t truncate other
, but the !
operator will.
Sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
The bitwise exclusive-or (^
) of the bits in two flags values.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
The bitwise negation (!
) of the bits in a flags value, truncating the result.
Source§impl ServiceControlAccept
impl ServiceControlAccept
Sourcepub const fn iter(&self) -> Iter<ServiceControlAccept>
pub const fn iter(&self) -> Iter<ServiceControlAccept>
Yield a set of contained flags values.
Each yielded flags value will correspond to a defined named flag. Any unknown bits will be yielded together as a final flags value.
Sourcepub const fn iter_names(&self) -> IterNames<ServiceControlAccept>
pub const fn iter_names(&self) -> IterNames<ServiceControlAccept>
Yield a set of contained named flags values.
This method is like iter
, except only yields bits in contained named flags.
Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
Trait Implementations§
Source§impl Binary for ServiceControlAccept
impl Binary for ServiceControlAccept
Source§impl BitAnd for ServiceControlAccept
impl BitAnd for ServiceControlAccept
Source§impl BitAndAssign for ServiceControlAccept
impl BitAndAssign for ServiceControlAccept
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
The bitwise and (&
) of the bits in two flags values.
Source§impl BitOr for ServiceControlAccept
impl BitOr for ServiceControlAccept
Source§fn bitor(self, other: ServiceControlAccept) -> Self
fn bitor(self, other: ServiceControlAccept) -> Self
The bitwise or (|
) of the bits in two flags values.
Source§type Output = ServiceControlAccept
type Output = ServiceControlAccept
|
operator.Source§impl BitOrAssign for ServiceControlAccept
impl BitOrAssign for ServiceControlAccept
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
The bitwise or (|
) of the bits in two flags values.
Source§impl BitXor for ServiceControlAccept
impl BitXor for ServiceControlAccept
Source§impl BitXorAssign for ServiceControlAccept
impl BitXorAssign for ServiceControlAccept
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
The bitwise exclusive-or (^
) of the bits in two flags values.
Source§impl Clone for ServiceControlAccept
impl Clone for ServiceControlAccept
Source§fn clone(&self) -> ServiceControlAccept
fn clone(&self) -> ServiceControlAccept
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ServiceControlAccept
impl Debug for ServiceControlAccept
Source§impl Extend<ServiceControlAccept> for ServiceControlAccept
impl Extend<ServiceControlAccept> for ServiceControlAccept
Source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
The bitwise or (|
) of the bits in each flags value.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Flags for ServiceControlAccept
impl Flags for ServiceControlAccept
Source§const FLAGS: &'static [Flag<ServiceControlAccept>]
const FLAGS: &'static [Flag<ServiceControlAccept>]
Source§fn from_bits_retain(bits: u32) -> ServiceControlAccept
fn from_bits_retain(bits: u32) -> ServiceControlAccept
Source§fn from_bits_truncate(bits: Self::Bits) -> Self
fn from_bits_truncate(bits: Self::Bits) -> Self
Source§fn from_name(name: &str) -> Option<Self>
fn from_name(name: &str) -> Option<Self>
Source§fn iter_names(&self) -> IterNames<Self>
fn iter_names(&self) -> IterNames<Self>
Source§fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn contains(&self, other: Self) -> boolwhere
Self: Sized,
fn contains(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn insert(&mut self, other: Self)where
Self: Sized,
fn insert(&mut self, other: Self)where
Self: Sized,
|
) of the bits in two flags values.Source§fn remove(&mut self, other: Self)where
Self: Sized,
fn remove(&mut self, other: Self)where
Self: Sized,
&!
). Read moreSource§fn toggle(&mut self, other: Self)where
Self: Sized,
fn toggle(&mut self, other: Self)where
Self: Sized,
^
) of the bits in two flags values.Source§fn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
&
) of the bits in two flags values.Source§fn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
&!
). Read moreSource§fn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
^
) of the bits in two flags values.Source§fn complement(self) -> Self
fn complement(self) -> Self
!
) of the bits in a flags value, truncating the result.Source§impl FromIterator<ServiceControlAccept> for ServiceControlAccept
impl FromIterator<ServiceControlAccept> for ServiceControlAccept
Source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
The bitwise or (|
) of the bits in each flags value.
Source§impl Hash for ServiceControlAccept
impl Hash for ServiceControlAccept
Source§impl IntoIterator for ServiceControlAccept
impl IntoIterator for ServiceControlAccept
Source§impl LowerHex for ServiceControlAccept
impl LowerHex for ServiceControlAccept
Source§impl Not for ServiceControlAccept
impl Not for ServiceControlAccept
Source§impl Octal for ServiceControlAccept
impl Octal for ServiceControlAccept
Source§impl Ord for ServiceControlAccept
impl Ord for ServiceControlAccept
Source§fn cmp(&self, other: &ServiceControlAccept) -> Ordering
fn cmp(&self, other: &ServiceControlAccept) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ServiceControlAccept
impl PartialEq for ServiceControlAccept
Source§impl PartialOrd for ServiceControlAccept
impl PartialOrd for ServiceControlAccept
Source§impl PublicFlags for ServiceControlAccept
impl PublicFlags for ServiceControlAccept
Source§impl Sub for ServiceControlAccept
impl Sub for ServiceControlAccept
Source§fn sub(self, other: Self) -> Self
fn sub(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
difference
won’t truncate other
, but the !
operator will.
Source§type Output = ServiceControlAccept
type Output = ServiceControlAccept
-
operator.Source§impl SubAssign for ServiceControlAccept
impl SubAssign for ServiceControlAccept
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
difference
won’t truncate other
, but the !
operator will.