Skip to content

Commit

Permalink
Add clang format (#9)
Browse files Browse the repository at this point in the history
* Add clang-format

* Format files using clang-format
  • Loading branch information
jfantinhardesty authored Jun 11, 2024
1 parent e47bddc commit 54cc918
Show file tree
Hide file tree
Showing 21 changed files with 812 additions and 759 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: Microsoft
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "settings/plugin.h"

extern "C" NX_PLUGIN_API nx::sdk::IPlugin* createNxPlugin()
extern "C" NX_PLUGIN_API nx::sdk::IPlugin *createNxPlugin()
{
using namespace nx::vms_server_plugins::analytics::stub;
return new settings::Plugin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

#include "actions.h"

#include <nx/kit/utils.h>
#include <nx/kit/debug.h>
#include <nx/kit/utils.h>

#include "settings_model.h"

namespace nx {
namespace vms_server_plugins {
namespace analytics {
namespace stub {
namespace settings {

namespace nx
{
namespace vms_server_plugins
{
namespace analytics
{
namespace stub
{
namespace settings
{

void dumpStringMap(
const char* prefix, const char* appendix, const nx::sdk::IStringMap* stringMap);
void dumpStringMap(const char *prefix, const char *appendix, const nx::sdk::IStringMap *stringMap);

nx::sdk::Ptr<nx::sdk::ActionResponse> generateActionResponse(
const std::string& settingId,
nx::sdk::Ptr<const nx::sdk::IStringMap> params)
nx::sdk::Ptr<nx::sdk::ActionResponse> generateActionResponse(const std::string &settingId,
nx::sdk::Ptr<const nx::sdk::IStringMap> params)
{
using namespace nx::sdk;
NX_PRINT << "cloudfuse actions.cpp:generateActionResponse(" << settingId << ")" << std::endl;
Expand All @@ -29,7 +31,7 @@ nx::sdk::Ptr<nx::sdk::ActionResponse> generateActionResponse(
{
// run Cloudfuse --dry-run to check credentials
// hard-coding a response for now
const char* cloudfuseOutput = "Cloudfuse call not implemented!";
const char *cloudfuseOutput = "Cloudfuse call not implemented!";
bool success = false;
// possible responses to user
std::string successMessage = "✅ Credentials verified";
Expand All @@ -38,22 +40,24 @@ nx::sdk::Ptr<nx::sdk::ActionResponse> generateActionResponse(

// build action response
const auto actionResponse = makePtr<ActionResponse>();
if (success) {
if (success)
{
resultMessage = successMessage;
} else {
}
else
{
resultMessage = failureMessage;
}
actionResponse->setMessageToUser(
resultMessage + " \nCheck Output: " + nx::kit::utils::toString(cloudfuseOutput));
actionResponse->setMessageToUser(resultMessage +
" \nCheck Output: " + nx::kit::utils::toString(cloudfuseOutput));

return actionResponse;
}

return nullptr;
}

void dumpStringMap(
const char* prefix, const char* appendix, const nx::sdk::IStringMap* stringMap)
void dumpStringMap(const char *prefix, const char *appendix, const nx::sdk::IStringMap *stringMap)
{
if (!stringMap)
{
Expand All @@ -65,8 +69,7 @@ void dumpStringMap(
for (int i = 0; i < stringMap->count(); ++i)
{
NX_PRINT << prefix << " " << nx::kit::utils::toString(stringMap->key(i)) << ": "
<< nx::kit::utils::toString(stringMap->value(i))
<< ((i == stringMap->count() - 1) ? "" : ",");
<< nx::kit::utils::toString(stringMap->value(i)) << ((i == stringMap->count() - 1) ? "" : ",");
}
NX_PRINT << prefix << "}" << appendix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
#include <nx/sdk/i_string_map.h>
#include <nx/sdk/ptr.h>

namespace nx {
namespace vms_server_plugins {
namespace analytics {
namespace stub {
namespace settings {
namespace nx
{
namespace vms_server_plugins
{
namespace analytics
{
namespace stub
{
namespace settings
{

nx::sdk::Ptr<nx::sdk::ActionResponse> generateActionResponse(
const std::string& settingId,
nx::sdk::Ptr<const nx::sdk::IStringMap> params);
nx::sdk::Ptr<nx::sdk::ActionResponse> generateActionResponse(const std::string &settingId,
nx::sdk::Ptr<const nx::sdk::IStringMap> params);

} // namespace settings
} // namespace stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@

#include "active_settings_builder.h"

namespace nx {
namespace vms_server_plugins {
namespace analytics {
namespace stub {
namespace settings {
namespace nx
{
namespace vms_server_plugins
{
namespace analytics
{
namespace stub
{
namespace settings
{

using namespace nx::sdk;

void ActiveSettingsBuilder::addRule(
const std::string& activeSettingName,
const std::string& activeSettingValue,
ActiveSettingHandler activeSettingHandler)
void ActiveSettingsBuilder::addRule(const std::string &activeSettingName, const std::string &activeSettingValue,
ActiveSettingHandler activeSettingHandler)
{
ActiveSettingKey key{activeSettingName, activeSettingValue};
m_rules[key] = activeSettingHandler;
}

void ActiveSettingsBuilder::addDefaultRule(
const std::string& activeSettingName,
ActiveSettingHandler activeSettingHandler)
void ActiveSettingsBuilder::addDefaultRule(const std::string &activeSettingName,
ActiveSettingHandler activeSettingHandler)
{
m_defaultRules[activeSettingName] = activeSettingHandler;
}

void ActiveSettingsBuilder::updateSettings(
const std::string& activeSettingName,
nx::kit::Json* inOutSettingsModel,
std::map<std::string, std::string>* inOutSettingsValues) const
void ActiveSettingsBuilder::updateSettings(const std::string &activeSettingName, nx::kit::Json *inOutSettingsModel,
std::map<std::string, std::string> *inOutSettingsValues) const
{
ActiveSettingKey key{activeSettingName, (*inOutSettingsValues)[activeSettingName]};

Expand All @@ -42,7 +42,7 @@ void ActiveSettingsBuilder::updateSettings(
defaultRulesIt->second(inOutSettingsModel, inOutSettingsValues);
}

bool ActiveSettingsBuilder::ActiveSettingKey::operator<(const ActiveSettingKey& other) const
bool ActiveSettingsBuilder::ActiveSettingKey::operator<(const ActiveSettingKey &other) const
{
if (activeSettingName != other.activeSettingName)
return activeSettingName < other.activeSettingName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,43 @@
#include <nx/sdk/i_string_map.h>
#include <nx/sdk/result.h>

namespace nx {
namespace vms_server_plugins {
namespace analytics {
namespace stub {
namespace settings {
namespace nx
{
namespace vms_server_plugins
{
namespace analytics
{
namespace stub
{
namespace settings
{

class ActiveSettingsBuilder
{
public:
using ActiveSettingHandler = std::function<void(
nx::kit::Json* /*inOutModel*/,
std::map<std::string, std::string>* /*inOutValues*/)>;
public:
using ActiveSettingHandler =
std::function<void(nx::kit::Json * /*inOutModel*/, std::map<std::string, std::string> * /*inOutValues*/)>;

struct ActiveSettingKey
{
std::string activeSettingName;
std::string activeSettingValue;

bool operator<(const ActiveSettingKey& other) const;
bool operator<(const ActiveSettingKey &other) const;
};

public:
public:
ActiveSettingsBuilder() = default;

void addRule(
const std::string& activeSettingName,
const std::string& activeSettingValue,
ActiveSettingHandler activeSettingHandler);
void addRule(const std::string &activeSettingName, const std::string &activeSettingValue,
ActiveSettingHandler activeSettingHandler);

void addDefaultRule(
const std::string& activeSettingName,
ActiveSettingHandler activeSettingHandler);
void addDefaultRule(const std::string &activeSettingName, ActiveSettingHandler activeSettingHandler);

void updateSettings(
const std::string& activeSettingName,
nx::kit::Json* inOutSettingsModel,
std::map<std::string, std::string>* inOutSettingsValues) const;
void updateSettings(const std::string &activeSettingName, nx::kit::Json *inOutSettingsModel,
std::map<std::string, std::string> *inOutSettingsValues) const;

private:
private:
std::map<ActiveSettingKey, ActiveSettingHandler> m_rules;
std::map</*activeSettingName*/ std::string, ActiveSettingHandler> m_defaultRules;
};
Expand Down
Loading

0 comments on commit 54cc918

Please sign in to comment.