status_t MessageAdapter::_ConvertKMessage(const KMessage *fromMessage, BMessage *toMessage) { if (!fromMessage || !toMessage) return B_BAD_VALUE; // make empty and init what of the target message toMessage->MakeEmpty(); toMessage->what = fromMessage->What(); BMessage::Private toPrivate(toMessage); toPrivate.SetTarget(fromMessage->TargetToken()); toPrivate.SetReply(B_SYSTEM_TEAM, fromMessage->ReplyPort(), fromMessage->ReplyToken()); // iterate through the fields and import them in the target message KMessageField field; while (fromMessage->GetNextField(&field) == B_OK) { int32 elementCount = field.CountElements(); if (elementCount > 0) { for (int32 i = 0; i < elementCount; i++) { int32 size; const void *data = field.ElementAt(i, &size); status_t result; if (field.TypeCode() == B_MESSAGE_TYPE) { // message type: if it's a KMessage, convert it KMessage message; if (message.SetTo(data, size) == B_OK) { BMessage bMessage; result = _ConvertKMessage(&message, &bMessage); if (result < B_OK) return result; result = toMessage->AddMessage(field.Name(), &bMessage); } else { // just add it result = toMessage->AddData(field.Name(), field.TypeCode(), data, size, field.HasFixedElementSize(), 1); } } else { result = toMessage->AddData(field.Name(), field.TypeCode(), data, size, field.HasFixedElementSize(), 1); } if (result < B_OK) return result; } } } return B_OK; }
void Notify(uint32 eventCode, struct image* image) { char eventBuffer[128]; KMessage event; event.SetTo(eventBuffer, sizeof(eventBuffer), IMAGE_MONITOR); event.AddInt32("event", eventCode); event.AddInt32("image", image->info.id); event.AddPointer("imageStruct", image); DefaultNotificationService::Notify(event, eventCode); }
void PortNotificationService::Notify(uint32 opcode, port_id port) { char eventBuffer[64]; KMessage event; event.SetTo(eventBuffer, sizeof(eventBuffer), PORT_MONITOR); event.AddInt32("event", opcode); event.AddInt32("port", port); DefaultNotificationService::Notify(event, opcode); }
status_t NotificationManager::UpdateListener(const char* serviceName, uint32 eventMask, NotificationListener& listener) { char buffer[96]; KMessage specifier; specifier.SetTo(buffer, sizeof(buffer), 0); specifier.AddInt32(kEventMaskString, eventMask); return UpdateListener(serviceName, &specifier, listener); }
status_t notify_interface_removed(net_interface* interface) { if (sNotificationModule == NULL) return B_NOT_SUPPORTED; char messageBuffer[512]; KMessage message; message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR); message.AddInt32("opcode", B_NETWORK_INTERFACE_REMOVED); message.AddString("interface", interface->name); return sNotificationModule->send_notification(&message); }
status_t MessageAdapter::Unflatten(uint32 format, BMessage *into, const char *buffer) { if (format == KMessage::kMessageHeaderMagic) { KMessage message; status_t result = message.SetTo(buffer, ((KMessage::Header *)buffer)->size); if (result != B_OK) return result; return _ConvertKMessage(&message, into); } try { switch (format) { case MESSAGE_FORMAT_R5: { r5_message_header *header = (r5_message_header *)buffer; BMemoryIO stream(buffer + sizeof(uint32), header->flattened_size - sizeof(uint32)); return _UnflattenR5Message(format, into, &stream); } case MESSAGE_FORMAT_R5_SWAPPED: { r5_message_header *header = (r5_message_header *)buffer; BMemoryIO stream(buffer + sizeof(uint32), __swap_int32(header->flattened_size) - sizeof(uint32)); return _UnflattenR5Message(format, into, &stream); } case MESSAGE_FORMAT_DANO: case MESSAGE_FORMAT_DANO_SWAPPED: { dano_section_header *header = (dano_section_header *)buffer; ssize_t size = header->size; if (header->code == MESSAGE_FORMAT_DANO_SWAPPED) size = __swap_int32(size); BMemoryIO stream(buffer + sizeof(uint32), size - sizeof(uint32)); return _UnflattenDanoMessage(format, into, &stream); } } } catch (status_t error) { into->MakeEmpty(); return error; } return B_NOT_A_MESSAGE; }
status_t LocalDebuggerInterface::GetNextDebugEvent(DebugEvent*& _event) { while (true) { char buffer[2048]; int32 messageCode; ssize_t size = read_port(fDebuggerPort, &messageCode, buffer, sizeof(buffer)); if (size < 0) { if (size == B_INTERRUPTED) continue; return size; } if (messageCode <= B_DEBUGGER_MESSAGE_HANDED_OVER) { debug_debugger_message_data message; memcpy(&message, buffer, size); if (message.origin.team != fTeamID) continue; bool ignore = false; status_t error = _CreateDebugEvent(messageCode, message, ignore, _event); if (error != B_OK) return error; if (ignore) { if (message.origin.thread >= 0 && message.origin.nub_port >= 0) error = continue_thread(message.origin.nub_port, message.origin.thread); if (error != B_OK) return error; continue; } return B_OK; } KMessage message; size = message.SetTo(buffer); if (size != B_OK) return size; return _GetNextSystemWatchEvent(_event, message); } return B_OK; }
void _SendMessage(messaging_target* targets, int32 targetCount, int32 object, uint32 opcode) { // prepare the message char buffer[128]; KMessage message; message.SetTo(buffer, sizeof(buffer), B_SYSTEM_OBJECT_UPDATE); message.AddInt32("opcode", opcode); if (opcode < B_THREAD_CREATED) message.AddInt32("team", object); else message.AddInt32("thread", object); // send it send_message(message.Buffer(), message.ContentSize(), targets, targetCount); }
status_t notify_link_changed(net_device* device) { if (sNotificationModule == NULL) return B_NOT_SUPPORTED; char messageBuffer[512]; KMessage message; message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR); message.AddInt32("opcode", B_NETWORK_DEVICE_LINK_CHANGED); message.AddString("device", device->name); message.AddInt32("media", device->media); message.AddInt64("link speed", device->link_speed); message.AddInt32("link quality", device->link_quality); return sNotificationModule->send_notification(&message); }
void ieee80211_notify_scan_done(struct ieee80211vap* vap) { release_sem_etc(vap->iv_ifp->scan_done_sem, 1, B_DO_NOT_RESCHEDULE | B_RELEASE_ALL); TRACE("%s\n", __FUNCTION__); if (sNotificationModule != NULL) { char messageBuffer[512]; KMessage message; message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR); message.AddInt32("opcode", B_NETWORK_WLAN_SCANNED); message.AddString("interface", vap->iv_ifp->device_name); sNotificationModule->send_notification(&message); } }
status_t notify_interface_changed(net_interface* interface, uint32 oldFlags, uint32 newFlags) { if (sNotificationModule == NULL) return B_NOT_SUPPORTED; char messageBuffer[512]; KMessage message; message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR); message.AddInt32("opcode", B_NETWORK_INTERFACE_CHANGED); message.AddString("interface", interface->name); if (oldFlags != newFlags) { message.AddInt32("old flags", oldFlags); message.AddInt32("new flags", newFlags); } return sNotificationModule->send_notification(&message); }
void ieee80211_notify_node_leave(struct ieee80211_node* ni) { struct ieee80211vap* vap = ni->ni_vap; struct ifnet* ifp = vap->iv_ifp; if (ni == vap->iv_bss) if_link_state_change(ifp, LINK_STATE_DOWN); TRACE("%s\n", __FUNCTION__); if (sNotificationModule != NULL) { char messageBuffer[512]; KMessage message; message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR); message.AddInt32("opcode", B_NETWORK_WLAN_LEFT); message.AddString("interface", ifp->device_name); // TODO: add data about the node sNotificationModule->send_notification(&message); } }