Files
UnrealEngineUWP/Engine/Source/Runtime/Messaging/Private/MessagingModule.cpp
Max Preussner 3aece47882 Docs: Removed file comments and added missing code documentation
Please note that file comments had no purpose in nearly all cases and just added visual clutter. The two files that had meaningful file comments had their comments moved into the corresponding classes. There are still hundreds of file comments left in other files that will be removed over time.

Also cleaned up some random stuff along the way:
- relative paths to public headers within the same module are no longer necessary (automatically discovered by UBT now)
- header guards are deprecated, use #pragma once instead (all compilers support it now)
- space between multiple template brackets is no longer required (all compilers support >> now)
- NULL to nullptr, OVERRIDE to override
- spelling errors, whitespace, line breaks

[CL 2104067 by Max Preussner in Main branch]
2014-06-12 23:22:18 -04:00

168 lines
3.4 KiB
C++

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "MessagingPrivatePCH.h"
#include "ModuleManager.h"
#ifndef PLATFORM_SUPPORTS_MESSAGEBUS
#define PLATFORM_SUPPORTS_MESSAGEBUS 1
#endif
/**
* Implements the Messaging module.
*/
class FMessagingModule
: public FSelfRegisteringExec
, public IMessagingModule
{
public:
// FSelfRegisteringExec interface
virtual bool Exec( UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar ) override
{
if (FParse::Command(&Cmd, TEXT("MESSAGING")))
{
if (FParse::Command(&Cmd, TEXT("STATUS")))
{
if (DefaultBus.IsValid())
{
Ar.Log(TEXT("Default message bus has been initialized."));
}
else
{
Ar.Log(TEXT("Default message bus has NOT been initialized yet."));
}
}
else
{
// show usage
Ar.Log(TEXT("Usage: MESSAGING <Command>"));
Ar.Log(TEXT(""));
Ar.Log(TEXT("Command"));
Ar.Log(TEXT(" STATUS = Displays the status of the default message bus"));
}
return true;
}
return false;
}
public:
// IMessagingModule interface
virtual IMessageBridgePtr CreateBridge( const FMessageAddress& Address, const IMessageBusRef& Bus, const ISerializeMessagesRef& Serializer, const ITransportMessagesRef& Transport ) override
{
return MakeShareable(new FMessageBridge(Address, Bus, Serializer, Transport));
}
virtual IMessageBusPtr CreateBus( const IAuthorizeMessageRecipientsPtr& RecipientAuthorizer ) override
{
return MakeShareable(new FMessageBus(RecipientAuthorizer));
}
virtual ISerializeMessagesPtr CreateJsonMessageSerializer( ) override
{
return MakeShareable(new FJsonMessageSerializer());
}
virtual IMessageBusPtr GetDefaultBus( ) const override
{
return DefaultBus;
}
public:
// IModuleInterface interface
virtual void StartupModule( ) override
{
#if PLATFORM_SUPPORTS_MESSAGEBUS
FCoreDelegates::OnPreExit.AddRaw(this, &FMessagingModule::HandleCorePreExit);
DefaultBus = CreateBus(nullptr);
#endif //PLATFORM_SUPPORTS_MESSAGEBUS
}
virtual void ShutdownModule( ) override
{
ShutdownDefaultBus();
}
virtual bool SupportsDynamicReloading( ) override
{
return false;
}
protected:
void ShutdownDefaultBus( )
{
if (!DefaultBus.IsValid())
{
return;
}
IMessageBusWeakPtr DefaultBusPtr = DefaultBus;
DefaultBus->Shutdown();
DefaultBus.Reset();
// wait for the bus to shut down
int32 SleepCount = 0;
while (DefaultBusPtr.IsValid())
{
check(SleepCount < 10); // something is holding on to the message bus
++SleepCount;
FPlatformProcess::Sleep(0.1f);
}
}
private:
// Callback for Core shutdown.
void HandleCorePreExit( )
{
ShutdownDefaultBus();
}
private:
// Holds the message bus.
IMessageBusPtr DefaultBus;
};
/* Misc static functions
*****************************************************************************/
TStatId FMessageForwardTask::GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FMessageForwardTask, STATGROUP_TaskGraphTasks);
}
TStatId FMessageDispatchTask::GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FMessageDispatchTask, STATGROUP_TaskGraphTasks);
}
TStatId FMessageSerializeTask::GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FMessageSerializeTask, STATGROUP_TaskGraphTasks);
}
TStatId FMessageDeserializeTask::GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FMessageDeserializeTask, STATGROUP_TaskGraphTasks);
}
IMPLEMENT_MODULE(FMessagingModule, Messaging);