template <typename T> void constructMessage(RoutableMessage&output, const ObjectReference*source, const ObjectReference*destination, const char* messageName, const T&opaqueMessage, const void *optionalSerializedSubMessage, size_t optionalSerializedSubMessageSize) { DidAlterMessage alteration=addressMessage(output,source,destination); if (optionalSerializedSubMessage&&optionalSerializedSubMessageSize) { output.body().add_message(messageName, optionalSerializedSubMessage,optionalSerializedSubMessageSize); }else { opaqueMessage.SerializeToString(output.body().add_message(messageName)); } }
void TeamWindow::MessageReceived(BMessage* message) { switch (message->what) { case MSG_TEAM_RESTART_REQUESTED: { fListener->TeamRestartRequested(); break; } case MSG_CHOOSE_DEBUG_REPORT_LOCATION: { try { char filename[B_FILE_NAME_LENGTH]; UiUtils::ReportNameForTeam(fTeam, filename, sizeof(filename)); BMessenger msgr(this); fFilePanel = new BFilePanel(B_SAVE_PANEL, &msgr, NULL, 0, false, new BMessage(MSG_GENERATE_DEBUG_REPORT)); fFilePanel->SetSaveText(filename); fFilePanel->Show(); } catch (...) { delete fFilePanel; fFilePanel = NULL; } break; } case MSG_GENERATE_DEBUG_REPORT: { delete fFilePanel; fFilePanel = NULL; BPath path; entry_ref ref; if (message->FindRef("directory", &ref) == B_OK && message->HasString("name")) { path.SetTo(&ref); path.Append(message->FindString("name")); if (get_ref_for_path(path.Path(), &ref) == B_OK) fListener->DebugReportRequested(&ref); } break; } case MSG_DEBUG_REPORT_SAVED: { BString data; data.SetToFormat("Debug report successfully saved to '%s'", message->FindString("path")); BAlert *alert = new(std::nothrow) BAlert("Report saved", data.String(), "Close"); if (alert == NULL) break; alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); break; } case MSG_SHOW_INSPECTOR_WINDOW: { if (fInspectorWindow) { fInspectorWindow->Activate(true); } else { try { fInspectorWindow = InspectorWindow::Create(fTeam, fListener, this); if (fInspectorWindow != NULL) { BMessage settings; fInspectorWindow->LoadSettings(fUiSettings); fInspectorWindow->Show(); } } catch (...) { // TODO: notify user } } target_addr_t address; if (message->FindUInt64("address", &address) == B_OK) { BMessage addressMessage(MSG_INSPECT_ADDRESS); addressMessage.AddUInt64("address", address); fInspectorWindow->PostMessage(&addressMessage); } break; } case MSG_INSPECTOR_WINDOW_CLOSED: { _SaveInspectorSettings(CurrentMessage()); fInspectorWindow = NULL; break; } case MSG_SHOW_BREAK_CONDITION_CONFIG_WINDOW: { if (fBreakConditionConfigWindow) { fBreakConditionConfigWindow->Activate(true); } else { try { fBreakConditionConfigWindow = BreakConditionConfigWindow::Create( fTeam, fListener, this); if (fBreakConditionConfigWindow != NULL) fBreakConditionConfigWindow->Show(); } catch (...) { // TODO: notify user } } break; } case MSG_BREAK_CONDITION_CONFIG_WINDOW_CLOSED: { fBreakConditionConfigWindow = NULL; break; } case MSG_SHOW_WATCH_VARIABLE_PROMPT: { target_addr_t address; uint32 type; int32 length; if (message->FindUInt64("address", &address) != B_OK || message->FindUInt32("type", &type) != B_OK || message->FindInt32("length", &length) != B_OK) { break; } try { WatchPromptWindow* window = WatchPromptWindow::Create( fTeam->GetArchitecture(), address, type, length, fListener); window->Show(); } catch (...) { // TODO: notify user } break; } case B_REFS_RECEIVED: { entry_ref locatedPath; if (message->FindRef("refs", &locatedPath) != B_OK) break; _HandleResolveMissingSourceFile(locatedPath); break; } case MSG_LOCATE_SOURCE_IF_NEEDED: { if (fActiveFunction != NULL && fActiveFunction->GetFunctionDebugInfo() ->SourceFile() != NULL && fActiveSourceCode != NULL && fActiveSourceCode->GetSourceFile() == NULL && fActiveFunction->GetFunction()->SourceCodeState() != FUNCTION_SOURCE_NOT_LOADED) { try { if (fFilePanel == NULL) { fFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this)); } fFilePanel->Show(); } catch (...) { delete fFilePanel; fFilePanel = NULL; } } break; } case MSG_THREAD_RUN: case MSG_THREAD_STOP: case MSG_THREAD_STEP_OVER: case MSG_THREAD_STEP_INTO: case MSG_THREAD_STEP_OUT: if (fActiveThread != NULL && fTraceUpdateRunner == NULL) { fListener->ThreadActionRequested(fActiveThread->ID(), message->what); } break; case MSG_CLEAR_STACK_TRACE: { if (fTraceUpdateRunner != NULL) { _SetActiveStackTrace(NULL); _UpdateRunButtons(); } break; } case MSG_THREAD_STATE_CHANGED: { int32 threadID; if (message->FindInt32("thread", &threadID) != B_OK) break; _HandleThreadStateChanged(threadID); break; } case MSG_THREAD_CPU_STATE_CHANGED: { int32 threadID; if (message->FindInt32("thread", &threadID) != B_OK) break; _HandleCpuStateChanged(threadID); break; } case MSG_THREAD_STACK_TRACE_CHANGED: { int32 threadID; if (message->FindInt32("thread", &threadID) != B_OK) break; _HandleStackTraceChanged(threadID); break; } case MSG_IMAGE_DEBUG_INFO_CHANGED: { int32 imageID; if (message->FindInt32("image", &imageID) != B_OK) break; _HandleImageDebugInfoChanged(imageID); break; } case MSG_CONSOLE_OUTPUT_RECEIVED: { int32 fd; BString output; if (message->FindInt32("fd", &fd) != B_OK || message->FindString("output", &output) != B_OK) { break; } fConsoleOutputView->ConsoleOutputReceived(fd, output); break; } case MSG_USER_BREAKPOINT_CHANGED: { UserBreakpoint* breakpoint; if (message->FindPointer("breakpoint", (void**)&breakpoint) != B_OK) break; BReference<UserBreakpoint> breakpointReference(breakpoint, true); _HandleUserBreakpointChanged(breakpoint); break; } case MSG_WATCHPOINT_CHANGED: { Watchpoint* watchpoint; if (message->FindPointer("watchpoint", (void**)&watchpoint) != B_OK) break; BReference<Watchpoint> watchpointReference(watchpoint, true); _HandleWatchpointChanged(watchpoint); break; } case MSG_FUNCTION_SOURCE_CODE_CHANGED: { _HandleSourceCodeChanged(); break; } default: BWindow::MessageReceived(message); break; } }
/** * Process a message that may be meant for the proximity system * \returns true if object was deleted */ OpaqueMessageReturnValue internalProcessOpaqueProximityMessage( const ObjectReference*object, const RoutableMessageHeader& hdr, const void *serializedMessageBody, size_t serializedMessageBodySize, bool trusted) { try { RoutableMessage msg(hdr,serializedMessageBody,serializedMessageBodySize); MessageBundle sendState=DELIVER_TO_UNKNOWN; bool deliverAllMessages=true; int len=msg.body().message_size(); OpaqueMessageReturnValue obj_is_deleted=OBJECT_NOT_DESTROYED; bool disconnection=false; bool registration=false; for (int i=0;i<len;++i) { if (trusted||(hdr.has_source_object()&&hdr.source_object()==ObjectReference::spaceServiceID()&&hdr.source_port()==mRegistrationPort)) { if(msg.body().message_names(i)=="DelObj") { disconnection=true; obj_is_deleted=OBJECT_DELETED; } if(msg.body().message_names(i)=="RetObj") { registration=true; Sirikata::Protocol::RetObj ro; ro.ParseFromString(msg.body().message_arguments(i)); newObj(ro,msg.body().message_arguments(i).data(),msg.body().message_arguments(i).size()); } } if (!forwardThisName(disconnection,msg.body().message_names(i))) { if (len==1) return obj_is_deleted; deliverAllMessages=false; }else { if (msg.body().message_names(i)==proxCallbackName()) { if (sendState==DELIVER_TO_UNKNOWN||sendState==DELIVER_TO_OBJECT) sendState=DELIVER_TO_OBJECT; else sendState=DELIVER_TO_BOTH; }else{ if (sendState==DELIVER_TO_UNKNOWN||sendState==DELIVER_TO_PROX) sendState=DELIVER_TO_PROX; else sendState=DELIVER_TO_BOTH; } } } if (sendState==DELIVER_TO_UNKNOWN) return obj_is_deleted;//no messages considered worth forwarding to the proximity system if (sendState==DELIVER_TO_BOTH) { SILOG(prox,info,"Message with recipients both proximity and object bundled into the same message: not delivering."); return obj_is_deleted; } /* NOT SURE THIS IS NECESSARY -- do these messages already have addresses on them?*/ DidAlterMessage alteration; if (sendState==DELIVER_TO_PROX) alteration=addressMessage(msg,object,NULL); else alteration=addressMessage(msg,NULL,object); if (deliverAllMessages&&sendState==DELIVER_TO_PROX) { sendMessage(*object,msg,serializedMessageBody,serializedMessageBodySize); } else if (deliverAllMessages&&sendState==DELIVER_TO_OBJECT) { deliverMessage(*object,msg,serializedMessageBody,serializedMessageBodySize); }else { //some messages are not considered worth forwarding to the proximity system or there's a mishmash of destinations if (msg.body().message_size()<len) { len=msg.body().message_size(); } RoutableMessage newMsg (msg); newMsg.body().clear_message(); for (int i=0;i<len;++i) { if (forwardThisName(registration||disconnection,msg.body().message_names(i))) { newMsg.body().add_message(msg.body().message_names(i), msg.body().message_arguments(i)); } } if (sendState==DELIVER_TO_OBJECT) deliverMessage(*object,newMsg,NULL,0); if (sendState==DELIVER_TO_PROX) sendMessage(*object,newMsg,NULL,0); } return obj_is_deleted; }catch(std::invalid_argument&ia) { SILOG(proximity,warning,"Could not parse message"); return OBJECT_NOT_DESTROYED; } }