BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / network / stack / notifications.cpp
blobab152a4567ebd44ad4a5c3aaccaec63505615793
1 /*
2 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 /*! Provides the stack internal notification API.
9 The actual message sending happens in another module to make the
10 notification listeners independent from the stack status.
14 #include <net_device.h>
15 #include <net_notifications.h>
17 #include <util/KMessage.h>
19 #include "stack_private.h"
22 static net_notifications_module_info* sNotificationModule;
25 status_t
26 notify_interface_added(net_interface* interface)
28 if (sNotificationModule == NULL)
29 return B_NOT_SUPPORTED;
31 char messageBuffer[512];
32 KMessage message;
33 message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
34 message.AddInt32("opcode", B_NETWORK_INTERFACE_ADDED);
35 message.AddString("interface", interface->name);
37 return sNotificationModule->send_notification(&message);
41 status_t
42 notify_interface_removed(net_interface* interface)
44 if (sNotificationModule == NULL)
45 return B_NOT_SUPPORTED;
47 char messageBuffer[512];
48 KMessage message;
49 message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
50 message.AddInt32("opcode", B_NETWORK_INTERFACE_REMOVED);
51 message.AddString("interface", interface->name);
53 return sNotificationModule->send_notification(&message);
57 status_t
58 notify_interface_changed(net_interface* interface, uint32 oldFlags,
59 uint32 newFlags)
61 if (sNotificationModule == NULL)
62 return B_NOT_SUPPORTED;
64 char messageBuffer[512];
65 KMessage message;
66 message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
67 message.AddInt32("opcode", B_NETWORK_INTERFACE_CHANGED);
68 message.AddString("interface", interface->name);
69 if (oldFlags != newFlags) {
70 message.AddInt32("old flags", oldFlags);
71 message.AddInt32("new flags", newFlags);
74 return sNotificationModule->send_notification(&message);
78 status_t
79 notify_link_changed(net_device* device)
81 if (sNotificationModule == NULL)
82 return B_NOT_SUPPORTED;
84 char messageBuffer[512];
85 KMessage message;
86 message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
87 message.AddInt32("opcode", B_NETWORK_DEVICE_LINK_CHANGED);
88 message.AddString("device", device->name);
89 message.AddInt32("media", device->media);
90 message.AddInt64("link speed", device->link_speed);
91 message.AddInt32("link quality", device->link_quality);
93 return sNotificationModule->send_notification(&message);
97 status_t
98 init_notifications()
100 return get_module(NET_NOTIFICATIONS_MODULE_NAME,
101 (module_info**)&sNotificationModule);
105 void
106 uninit_notifications()
108 if (sNotificationModule != NULL)
109 put_module(NET_NOTIFICATIONS_MODULE_NAME);