Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Finish v1.1-r27
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Dec 11, 2019
2 parents 4a925ea + adc952c commit 2bbe0a6
Show file tree
Hide file tree
Showing 30 changed files with 353 additions and 337 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Overview
========
# VaRest

[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_ClangFormatCheck)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_ClangFormatCheck&guest=1)

VaRest is the plugin for [Unreal Engine 4](https://www.unrealengine.com/) that makes REST server communications easier to use.

Expand All @@ -11,7 +12,7 @@ Key features:
* Blueprintable FJsonValue wrapper - **full Json features made for blueprints!**
* Both bindable events and **latent functions** are provided to control the asynchronous requests

Check the [Wiki](https://hiazma.atlassian.net/wiki/display/VAR) for plugin usage examples and installation notes.
Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes.

Current version: **1.1 R 26** (UE 4.19-4.23)

Expand Down
96 changes: 96 additions & 0 deletions Source/VaRest/Private/VaRest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRest.h"

#include "VaRestDefines.h"
#include "VaRestJsonObject.h"
#include "VaRestJsonValue.h"
#include "VaRestRequestController.h"
#include "VaRestRequestJSON.h"
#include "VaRestSettings.h"

#include "Developer/Settings/Public/ISettingsModule.h"

#define LOCTEXT_NAMESPACE "FVaRestModule"

void FVaRestModule::StartupModule()
{
// @HACK Force classes to be compiled on shipping build
UVaRestJsonObject::StaticClass();
UVaRestJsonValue::StaticClass();
UVaRestRequestJSON::StaticClass();

VaRestSettings = NewObject<UVaRestSettings>(GetTransientPackage(), "VaRestSettings", RF_Standalone);
VaRestSettings->AddToRoot();

// Register settings
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->RegisterSettings("Project", "Plugins", "VaRest",
LOCTEXT("RuntimeSettingsName", "VaRest"),
LOCTEXT("RuntimeSettingsDescription", "Configure VaRest plugin settings"),
VaRestSettings);
}

FWorldDelegates::OnWorldCleanup.AddLambda([this](UWorld* World, bool bSessionEnded, bool bCleanupResources) {
RequestControllers.Remove(World);

UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is removed for: %s"), *VA_FUNC_LINE, *World->GetName());
});

FWorldDelegates::OnPostWorldInitialization.AddLambda([this](UWorld* World, const UWorld::InitializationValues IVS) {
auto Controller = NewObject<UVaRestRequestController>(GetTransientPackage());
Controller->SetFlags(RF_Standalone);
Controller->AddToRoot();

Controller->Initialize();

RequestControllers.Add(World, Controller);

UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is created for: %s"), *VA_FUNC_LINE, *World->GetName());
});

UE_LOG(LogVaRest, Log, TEXT("%s: VaRest module started"), *VA_FUNC_LINE);
}

void FVaRestModule::ShutdownModule()
{
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->UnregisterSettings("Project", "Plugins", "VaRest");
}

if (!GExitPurge)
{
VaRestSettings->RemoveFromRoot();

// If we're in exit purge, this object has already been destroyed
for (auto Controller : RequestControllers)
{
Controller.Value->RemoveFromRoot();
}
}
else
{
VaRestSettings = nullptr;
}

RequestControllers.Empty();
}

UVaRestSettings* FVaRestModule::GetSettings() const
{
check(VaRestSettings);
return VaRestSettings;
}

UVaRestRequestController* FVaRestModule::GetRequestController(UWorld* World) const
{
return RequestControllers.FindChecked(World);
}

IMPLEMENT_MODULE(FVaRestModule, VaRest)

DEFINE_LOG_CATEGORY(LogVaRest);

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#pragma once

Expand All @@ -15,12 +15,10 @@
#include "Engine.h"
#endif

#include "Containers/Map.h"
#include "Http.h"
#include "Json.h"

#include "LatentActions.h"
#include "Templates/SharedPointer.h"
#include "Delegates/DelegateCombinations.h"
#include "Logging/LogCategory.h"
#include "Logging/LogMacros.h"
#include "Logging/LogVerbosity.h"

// You should place include statements to your module's private header files here. You only need to
// add includes for headers that are used in most of your module's source files though.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Copyright 2014 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestJsonObject.h"

#include "VaRestDefines.h"
#include "VaRestJsonParser.h"
#include "VaRestJsonValue.h"
#include "VaRestPluginPrivatePCH.h"

#include "Runtime/Launch/Resources/Version.h"

typedef TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriterFactory;
typedef TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriter;

UVaRestJsonObject::UVaRestJsonObject(const class FObjectInitializer& PCIP)
: Super(PCIP)
UVaRestJsonObject::UVaRestJsonObject(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, JsonObj(MakeShared<FJsonObject>())
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ uint32 FUtf8Helper::CodepointFromUtf8(const ANSICHAR*& SourceString, const uint3
Codepoint = (((Octet << 12)) | ((Octet2 - 128) << 6) | ((Octet3 - 128)));

// UTF-8 characters cannot be in the UTF-16 surrogates range
if (UE4StringConv_Private::IsHighSurrogate(Codepoint) || UE4StringConv_Private::IsLowSurrogate(Codepoint))
if (StringConv::IsHighSurrogate(Codepoint) || StringConv::IsLowSurrogate(Codepoint))
{
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2014 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestJsonValue.h"

#include "VaRestDefines.h"
#include "VaRestJsonObject.h"
#include "VaRestPluginPrivatePCH.h"

UVaRestJsonValue::UVaRestJsonValue(const class FObjectInitializer& PCIP)
: Super(PCIP)
UVaRestJsonValue::UVaRestJsonValue(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}

Expand Down
72 changes: 72 additions & 0 deletions Source/VaRest/Private/VaRestLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestLibrary.h"

#include "VaRestDefines.h"
#include "VaRestJsonObject.h"
#include "VaRestRequestJSON.h"

#include "Misc/Base64.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"

//////////////////////////////////////////////////////////////////////////
// Helpers

FString UVaRestLibrary::PercentEncode(const FString& Source)
{
return FGenericPlatformHttp::UrlEncode(Source);
}

FString UVaRestLibrary::Base64Encode(const FString& Source)
{
return FBase64::Encode(Source);
}

bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest)
{
return FBase64::Decode(Source, Dest);
}

bool UVaRestLibrary::Base64EncodeData(const TArray<uint8>& Data, FString& Dest)
{
if (Data.Num() > 0)
{
Dest = FBase64::Encode(Data);
return true;
}

return false;
}

bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray<uint8>& Dest)
{
return FBase64::Decode(Source, Dest);
}

//////////////////////////////////////////////////////////////////////////
// File system integration

class UVaRestJsonObject* UVaRestLibrary::LoadJsonFromFile(UObject* WorldContextObject, const FString& Path, const bool bIsRelativeToContentDir)
{
UVaRestJsonObject* Json = UVaRestJsonObject::ConstructJsonObject(WorldContextObject);

FString JSONString;
if (FFileHelper::LoadFileToString(JSONString, *(bIsRelativeToContentDir ? FPaths::ProjectContentDir() / Path : Path)))
{
if (Json->DecodeJson(JSONString))
{
return Json;
}
else
{
UE_LOG(LogVaRest, Error, TEXT("%s: Can't decode json from file %s"), *VA_FUNC_LINE, *Path);
}
}
else
{
UE_LOG(LogVaRest, Error, TEXT("%s: Can't open file %s"), *VA_FUNC_LINE, *Path);
}

return nullptr;
}
14 changes: 14 additions & 0 deletions Source/VaRest/Private/VaRestRequestController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestRequestController.h"

#include "VaRestDefines.h"

UVaRestRequestController::UVaRestRequestController(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}

void UVaRestRequestController::Initialize()
{
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright 2014 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestRequestJSON.h"

#include "VaRestDefines.h"
#include "VaRestJsonObject.h"
#include "VaRestLibrary.h"
#include "VaRestPluginPrivatePCH.h"
#include "VaRestSettings.h"

#include "Json.h"
#include "Misc/CoreMisc.h"
#include "Runtime/Launch/Resources/Version.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestSettings.h"

Expand Down
50 changes: 50 additions & 0 deletions Source/VaRest/Public/VaRest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#pragma once

#include "Modules/ModuleManager.h"

class UVaRestRequestController;
class UVaRestSettings;

class FVaRestModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;

/**
* Singleton-like access to this module's interface. This is just for convenience!
* Beware of calling this during the shutdown phase, though. Your module might have been unloaded already.
*
* @return Returns singleton instance, loading the module on demand if needed
*/
static inline FVaRestModule& Get()
{
return FModuleManager::LoadModuleChecked<FVaRestModule>("VaRest");
}

/**
* Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true.
*
* @return True if the module is loaded and ready to use
*/
static inline bool IsAvailable()
{
return FModuleManager::Get().IsModuleLoaded("VaRest");
}

/** Getter for internal settings object to support runtime configuration changes */
UVaRestSettings* GetSettings() const;

/** Get global request controller */
UVaRestRequestController* GetRequestController(UWorld* World) const;

protected:
/** Module settings */
UVaRestSettings* VaRestSettings;

/** Request controllers (one for each World we have) */
TMap<UWorld*, UVaRestRequestController*> RequestControllers;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
// Copyright 2014 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#pragma once

Expand All @@ -13,12 +12,12 @@ class UVaRestJsonValue;
* Blueprintable FJsonObject wrapper
*/
UCLASS(BlueprintType, Blueprintable)
class VARESTPLUGIN_API UVaRestJsonObject : public UObject
class VAREST_API UVaRestJsonObject : public UObject
{
GENERATED_UCLASS_BODY()

/** Create new Json object */
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Object", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json")
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Object", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json")
static UVaRestJsonObject* ConstructJsonObject(UObject* WorldContextObject);

/** Reset all internal data */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
// Copyright 2014 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#pragma once

#include "VaRestDefines.h"

#include "VaRestJsonValue.generated.h"

class UVaRestJsonObject;
Expand All @@ -27,7 +28,7 @@ enum class EVaJson : uint8
* Blueprintable FJsonValue wrapper
*/
UCLASS(BlueprintType, Blueprintable)
class VARESTPLUGIN_API UVaRestJsonValue : public UObject
class VAREST_API UVaRestJsonValue : public UObject
{
GENERATED_UCLASS_BODY()

Expand Down
Loading

0 comments on commit 2bbe0a6

Please sign in to comment.