BPicture: Fix archive constructor.
[haiku.git] / src / kits / network / libnetapi / notifications.cpp
blob21aec197327e6e7e7829f1f084a7d843be6dfd30
1 /*
2 * Copyright 2008, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 /*! The notifications API uses the generic syscall interface of the
7 network's stack notification module.
8 */
10 #include <net_notifications.h>
12 #include <MessengerPrivate.h>
13 #include <generic_syscall_defs.h>
14 #include <syscalls.h>
17 static status_t
18 check_for_notifications_syscall(void)
20 uint32 version = 0;
21 return _kern_generic_syscall(NET_NOTIFICATIONS_SYSCALLS, B_SYSCALL_INFO,
22 &version, sizeof(version));
26 // #pragma mark -
29 status_t
30 start_watching_network(uint32 flags, const BMessenger& target)
32 if (check_for_notifications_syscall() != B_OK)
33 return B_NOT_SUPPORTED;
35 BMessenger::Private targetPrivate(const_cast<BMessenger&>(target));
36 net_notifications_control control;
37 control.flags = flags;
38 control.port = targetPrivate.Port();
39 control.token = targetPrivate.Token();
41 return _kern_generic_syscall(NET_NOTIFICATIONS_SYSCALLS,
42 NET_NOTIFICATIONS_CONTROL_WATCHING, &control,
43 sizeof(net_notifications_control));
47 status_t
48 start_watching_network(uint32 flags, const BHandler* handler,
49 const BLooper* looper)
51 const BMessenger target(handler, looper);
52 return start_watching_network(flags, target);
55 status_t
56 stop_watching_network(const BMessenger& target)
58 return start_watching_network(0, target);
59 // start_watching_network() without flags just stops everything
63 status_t
64 stop_watching_network(const BHandler* handler, const BLooper* looper)
66 const BMessenger target(handler, looper);
67 return stop_watching_network(target);