Struct windows_service::service::ServiceControlAccept
source · 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.
sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Returns an empty set of flags.
Examples found in repository?
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
pub fn run_service() -> Result<()> {
// Create a channel to be able to poll a stop event from the service worker loop.
let (shutdown_tx, shutdown_rx) = mpsc::channel();
// Define system service event handler that will be receiving service events.
let event_handler = move |control_event| -> ServiceControlHandlerResult {
match control_event {
// Notifies a service to report its current status information to the service
// control manager. Always return NoError even if not implemented.
ServiceControl::Interrogate => ServiceControlHandlerResult::NoError,
// Handle stop
ServiceControl::Stop => {
shutdown_tx.send(()).unwrap();
ServiceControlHandlerResult::NoError
}
_ => ServiceControlHandlerResult::NotImplemented,
}
};
// Register system service event handler.
// The returned status handle should be used to report service status changes to the system.
let status_handle = service_control_handler::register(SERVICE_NAME, event_handler)?;
// Tell the system that service is running
status_handle.set_service_status(ServiceStatus {
service_type: SERVICE_TYPE,
current_state: ServiceState::Running,
controls_accepted: ServiceControlAccept::STOP,
exit_code: ServiceExitCode::Win32(0),
checkpoint: 0,
wait_hint: Duration::default(),
process_id: None,
})?;
// For demo purposes this service sends a UDP packet once a second.
let loopback_ip = IpAddr::from(LOOPBACK_ADDR);
let sender_addr = SocketAddr::new(loopback_ip, 0);
let receiver_addr = SocketAddr::new(loopback_ip, RECEIVER_PORT);
let msg = PING_MESSAGE.as_bytes();
let socket = UdpSocket::bind(sender_addr).unwrap();
loop {
let _ = socket.send_to(msg, receiver_addr);
// Poll shutdown event.
match shutdown_rx.recv_timeout(Duration::from_secs(1)) {
// Break the loop either upon stop or channel disconnect
Ok(_) | Err(mpsc::RecvTimeoutError::Disconnected) => break,
// Continue work if no events were received within the timeout
Err(mpsc::RecvTimeoutError::Timeout) => (),
};
}
// Tell the system that service has stopped.
status_handle.set_service_status(ServiceStatus {
service_type: SERVICE_TYPE,
current_state: ServiceState::Stopped,
controls_accepted: ServiceControlAccept::empty(),
exit_code: ServiceExitCode::Win32(0),
checkpoint: 0,
wait_hint: Duration::default(),
process_id: None,
})?;
Ok(())
}sourcepub const fn from_bits(bits: u32) -> Option<Self>
pub const fn from_bits(bits: u32) -> Option<Self>
Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.
sourcepub const fn from_bits_truncate(bits: u32) -> Self
pub const fn from_bits_truncate(bits: u32) -> Self
Convert from underlying bit representation, dropping any bits that do not correspond to flags.
sourcepub const unsafe fn from_bits_unchecked(bits: u32) -> Self
pub const unsafe fn from_bits_unchecked(bits: u32) -> Self
Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
Safety
The caller of the bitflags! macro can chose to allow or
disallow extra bits for their bitflags type.
The caller of from_bits_unchecked() has to ensure that
all bits correspond to a defined flag or that extra bits
are valid for this bitflags type.
sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Returns true if there are flags common to both self and other.
sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Returns true if all of the flags in other are contained within self.
sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Inserts or removes the specified flags depending on the passed value.
sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
Returns the intersection between the flags in self and
other.
Specifically, the returned set contains only the flags which are
present in both self and other.
This is equivalent to using the & operator (e.g.
ops::BitAnd), as in flags & other.
sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
Returns the union of between the flags in self and other.
Specifically, the returned set contains all flags which are
present in either self or other, including any which are
present in both (see Self::symmetric_difference if that
is undesirable).
This is equivalent to using the | operator (e.g.
ops::BitOr), as in flags | other.
sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
Returns the difference between the flags in self and other.
Specifically, the returned set contains all flags present in
self, except for the ones present in other.
It is also conceptually equivalent to the “bit-clear” operation:
flags & !other (and this syntax is also supported).
This is equivalent to using the - operator (e.g.
ops::Sub), as in flags - other.
sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
Returns the symmetric difference between the flags
in self and other.
Specifically, the returned set contains the flags present which
are present in self or other, but that are not present in
both. Equivalently, it contains the flags present in exactly
one of the sets self and other.
This is equivalent to using the ^ operator (e.g.
ops::BitXor), as in flags ^ other.
sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
Returns the complement of this set of flags.
Specifically, the returned set contains all the flags which are
not set in self, but which are allowed for this type.
Alternatively, it can be thought of as the set difference
between Self::all() and self (e.g. Self::all() - self)
This is equivalent to using the ! operator (e.g.
ops::Not), as in !flags.
Trait Implementations§
source§impl Binary for ServiceControlAccept
impl Binary for ServiceControlAccept
source§impl BitAndAssign<ServiceControlAccept> for ServiceControlAccept
impl BitAndAssign<ServiceControlAccept> for ServiceControlAccept
source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
Disables all flags disabled in the set.
source§impl BitOr<ServiceControlAccept> for ServiceControlAccept
impl BitOr<ServiceControlAccept> for ServiceControlAccept
source§fn bitor(self, other: ServiceControlAccept) -> Self
fn bitor(self, other: ServiceControlAccept) -> Self
Returns the union of the two sets of flags.
§type Output = ServiceControlAccept
type Output = ServiceControlAccept
| operator.source§impl BitOrAssign<ServiceControlAccept> for ServiceControlAccept
impl BitOrAssign<ServiceControlAccept> for ServiceControlAccept
source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
Adds the set of flags.
source§impl BitXorAssign<ServiceControlAccept> for ServiceControlAccept
impl BitXorAssign<ServiceControlAccept> for ServiceControlAccept
source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
Toggles the set of flags.
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)
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 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
source§impl Hash for ServiceControlAccept
impl Hash 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<ServiceControlAccept> for ServiceControlAccept
impl PartialEq<ServiceControlAccept> for ServiceControlAccept
source§fn eq(&self, other: &ServiceControlAccept) -> bool
fn eq(&self, other: &ServiceControlAccept) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd<ServiceControlAccept> for ServiceControlAccept
impl PartialOrd<ServiceControlAccept> for ServiceControlAccept
source§fn partial_cmp(&self, other: &ServiceControlAccept) -> Option<Ordering>
fn partial_cmp(&self, other: &ServiceControlAccept) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl SubAssign<ServiceControlAccept> for ServiceControlAccept
impl SubAssign<ServiceControlAccept> for ServiceControlAccept
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Disables all flags enabled in the set.