Skip to content

Commit 45045e6

Browse files
Major UI Code Refactoring
1 parent db2acf8 commit 45045e6

13 files changed

+141
-24
lines changed

Implementation/API/amc_api_auth.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939
using namespace AMC;
4040

4141

42-
CAPIAuth::CAPIAuth(const std::string& sSessionUUID, const std::string& sSessionKey, PUserInformation pUserInformation, bool bIsAuthorized, PUIFrontendState pFrontendState, AMCCommon::PChrono pGlobalChrono)
42+
CAPIAuth::CAPIAuth(const std::string& sSessionUUID, const std::string& sSessionKey, PUserInformation pUserInformation, bool bIsAuthorized, PUIFrontendState pFrontendState)
4343
: m_sSessionUUID(AMCCommon::CUtils::normalizeUUIDString(sSessionUUID)),
4444
m_sSessionKey (AMCCommon::CUtils::normalizeSHA256String(sSessionKey)),
4545
m_pUserInformation(pUserInformation),

Implementation/API/amc_api_auth.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace AMC {
7171

7272
public:
7373

74-
CAPIAuth(const std::string& sSessionUUID, const std::string& sSessionKey, PUserInformation pUserInformation, bool bIsAuthorized, PUIFrontendState pFrontendState, AMCCommon::PChrono pGlobalChrono);
74+
CAPIAuth(const std::string& sSessionUUID, const std::string& sSessionKey, PUserInformation pUserInformation, bool bIsAuthorized, PUIFrontendState pFrontendState);
7575

7676
virtual ~CAPIAuth();
7777

Implementation/API/amc_api_session.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using namespace AMC;
4242

4343
#define APISESSION_RANDOMKEYITERATIONS 16
4444

45-
CAPISession::CAPISession(AMCCommon::PChrono pGlobalChrono)
45+
CAPISession::CAPISession(PUIFrontendDefinition pFrontendDefinition)
4646
: m_sUUID(AMCCommon::CUtils::createUUID()),
4747
m_sKey(AMCCommon::CUtils::calculateRandomSHA256String(APISESSION_RANDOMKEYITERATIONS)),
4848
m_sToken(AMCCommon::CUtils::calculateRandomSHA256String(APISESSION_RANDOMKEYITERATIONS)),
@@ -51,7 +51,7 @@ CAPISession::CAPISession(AMCCommon::PChrono pGlobalChrono)
5151
m_bAuthenticated(false)
5252
{
5353

54-
m_pFrontendState = std::make_shared<CUIFrontendState>(pGlobalChrono);
54+
m_pFrontendState = std::make_shared<CUIFrontendState>(pFrontendDefinition);
5555

5656

5757
}

Implementation/API/amc_api_session.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace AMC {
4949
amcDeclareDependingClass(CUserInformation, PUserInformation);
5050
amcDeclareDependingClass(CParameterHandler, PParameterHandler);
5151
amcDeclareDependingClass(CUIFrontendState, PUIFrontendState);
52+
amcDeclareDependingClass(CUIFrontendDefinition, PUIFrontendDefinition);
5253

5354
class CAPISession {
5455
private:
@@ -72,7 +73,7 @@ namespace AMC {
7273

7374
public:
7475

75-
CAPISession(AMCCommon::PChrono pGlobalChrono);
76+
CAPISession(PUIFrontendDefinition pFrontendDefinition);
7677
virtual ~CAPISession();
7778

7879
std::string getUUID ();

Implementation/API/amc_api_sessionhandler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ PAPIAuth CAPISessionHandler::createAuthentication(const std::string& sAuthorizat
7575
if (pSession->getToken () != sToken)
7676
throw ELibMCInterfaceException(LIBMC_ERROR_INVALIDSESSIONTOKEN);
7777

78-
return std::make_shared<CAPIAuth>(pSession->getUUID(), pSession->getKey(), pSession->createUserInformation(), pSession->isAuthenticated(), pSession->getFrontendState (), pGlobalChrono);
78+
return std::make_shared<CAPIAuth>(pSession->getUUID(), pSession->getKey(), pSession->createUserInformation(), pSession->isAuthenticated(), pSession->getFrontendState ());
7979
}
8080
else {
8181
return nullptr;
@@ -84,25 +84,25 @@ PAPIAuth CAPISessionHandler::createAuthentication(const std::string& sAuthorizat
8484
}
8585

8686

87-
PAPIAuth CAPISessionHandler::createNewAuthenticationSession(AMCCommon::PChrono pGlobalChrono)
87+
PAPIAuth CAPISessionHandler::createNewAuthenticationSession(PUIFrontendDefinition pFrontendDefinition)
8888
{
89-
auto pSession = std::make_shared<CAPISession>(pGlobalChrono);
89+
auto pSession = std::make_shared<CAPISession>(pFrontendDefinition);
9090

9191
std::lock_guard<std::mutex> lockGuard(m_Mutex);
9292
m_SessionMap.insert (std::make_pair (pSession->getUUID(), pSession));
9393

94-
return std::make_shared<CAPIAuth>(pSession->getUUID(), pSession->getKey(), pSession->createUserInformation(), pSession->isAuthenticated(), pSession->getFrontendState(), pGlobalChrono);
94+
return std::make_shared<CAPIAuth>(pSession->getUUID(), pSession->getKey(), pSession->createUserInformation(), pSession->isAuthenticated(), pSession->getFrontendState());
9595

9696
}
9797

9898

99-
PAPIAuth CAPISessionHandler::createEmptyAuthenticationSession(AMCCommon::PChrono pGlobalChrono)
99+
PAPIAuth CAPISessionHandler::createEmptyAuthenticationSession()
100100
{
101101

102102
std::string sEmptyUUID = "00000000-0000-0000-0000-000000000000";
103103
std::string sEmptyKey = "0000000000000000000000000000000000000000000000000000000000000000";
104104

105-
return std::make_shared<CAPIAuth>(sEmptyUUID, sEmptyKey, CUserInformation::makeEmpty (), false, nullptr, pGlobalChrono);
105+
return std::make_shared<CAPIAuth>(sEmptyUUID, sEmptyKey, CUserInformation::makeEmpty (), false, nullptr);
106106
}
107107

108108

Implementation/API/amc_api_sessionhandler.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace AMC {
4747
amcDeclareDependingClass(CAPISession, PAPISession);
4848
amcDeclareDependingClass(CAPISessionHandler, PAPISessionHandler);
4949
amcDeclareDependingClass(CParameterHandler, PParameterHandler);
50+
amcDeclareDependingClass(CUIFrontendDefinition, PUIFrontendDefinition);
51+
5052

5153
class CAPISessionHandler {
5254
private:
@@ -64,9 +66,9 @@ namespace AMC {
6466

6567
PAPIAuth createAuthentication(const std::string& sAuthorizationJSON, AMCCommon::PChrono pGlobalChrono);
6668

67-
PAPIAuth createNewAuthenticationSession(AMCCommon::PChrono pGlobalChrono);
69+
PAPIAuth createNewAuthenticationSession(PUIFrontendDefinition pFrontendDefinition);
6870

69-
PAPIAuth createEmptyAuthenticationSession(AMCCommon::PChrono pGlobalChrono);
71+
PAPIAuth createEmptyAuthenticationSession();
7072

7173
void authorizeSession (const std::string & sSessionUUID, const std::string & sSaltedPassword, const std::string & sClientKey);
7274

Implementation/LibMC/libmc_mccontext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,15 +992,17 @@ IAPIRequestHandler* CMCContext::CreateAPIRequestHandler(const std::string& sURI,
992992
throw ELibMCNoContextException(LIBMC_ERROR_INVALIDAUTHORIZATION);
993993

994994
if (bCreateNewSession) {
995-
pAuth = pSessionHandler->createNewAuthenticationSession(m_pSystemState->getGlobalChronoInstance ());
995+
auto pFrontendDefinition = m_pSystemState->uiHandler()->getFrontendDefinition();
996+
997+
pAuth = pSessionHandler->createNewAuthenticationSession(pFrontendDefinition);
996998
LibMCAssertNotNull(pAuth);
997999

9981000
auto pLegacyParameterHandler = pAuth->getLegacyParameterHandler(true);
9991001
if (pLegacyParameterHandler != nullptr)
10001002
m_pSystemState->uiHandler()->populateClientVariables (pLegacyParameterHandler);
10011003
}
10021004
else
1003-
pAuth = pSessionHandler->createEmptyAuthenticationSession(m_pSystemState->getGlobalChronoInstance());
1005+
pAuth = pSessionHandler->createEmptyAuthenticationSession();
10041006

10051007
}
10061008
else {

Implementation/UI/amc_ui_frontenddefinition.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333

3434
using namespace AMC;
3535

36+
CUIFrontendDefinitionModuleStore::CUIFrontendDefinitionModuleStore(const std::string& sModuleUUID, const std::string& sModulePath)
37+
{
38+
39+
}
40+
41+
CUIFrontendDefinitionModuleStore::~CUIFrontendDefinitionModuleStore()
42+
{
43+
44+
}
45+
46+
CUIFrontendDefinition::CUIFrontendDefinition(AMCCommon::PChrono pGlobalChrono)
47+
: m_pGlobalChrono (pGlobalChrono)
48+
{
49+
if (pGlobalChrono.get() == nullptr)
50+
throw ELibMCInterfaceException(LIBMC_ERROR_INVALIDPARAM);
51+
}
52+
53+
CUIFrontendDefinition::~CUIFrontendDefinition()
54+
{
55+
56+
}
57+
58+
PUIFrontendDefinitionModuleStore CUIFrontendDefinition::registerModuleStore(const std::string& sModuleUUID, const std::string& sPath)
59+
{
60+
return std::make_shared<CUIFrontendDefinitionModuleStore>(sModuleUUID, sPath);
61+
62+
}
63+
64+
65+
AMCCommon::PChrono CUIFrontendDefinition::getGlobalChrono()
66+
{
67+
return m_pGlobalChrono;
68+
}

Implementation/UI/amc_ui_frontenddefinition.hpp

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,79 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

3535
#include "common_chrono.hpp"
3636

37+
#include "amc_ui_expression.hpp"
38+
39+
#include <memory>
40+
#include <map>
3741

3842
namespace AMC {
3943

44+
enum class eUIFrontendDefinitionAttributeType : uint32_t {
45+
atUnknown = 0,
46+
atString = 1,
47+
atNumber = 2,
48+
atInteger = 3,
49+
atBoolean = 4,
50+
atUUID = 5
51+
};
52+
53+
class CUIFrontendDefinitionAttribute {
54+
private:
55+
56+
std::string m_sName;
57+
eUIFrontendDefinitionAttributeType m_AttributeType;
58+
59+
public:
60+
61+
CUIFrontendDefinitionAttribute(const std::string& sName, eUIFrontendDefinitionAttributeType attributeType);
62+
63+
virtual ~CUIFrontendDefinitionAttribute();
64+
65+
std::string getName();
66+
67+
eUIFrontendDefinitionAttributeType getAttributeType();
68+
};
69+
70+
typedef std::shared_ptr<CUIFrontendDefinitionAttribute> PUIFrontendDefinitionAttribute;
71+
72+
73+
class CUIFrontendDefinitionModuleStore {
74+
private:
75+
76+
std::string m_sPath;
77+
std::string m_sUUID;
78+
79+
std::map<std::string, PUIFrontendDefinitionAttribute> m_Attributes;
80+
81+
public:
82+
CUIFrontendDefinitionModuleStore(const std::string& sModuleUUID, const std::string & sModulePath);
83+
84+
virtual ~CUIFrontendDefinitionModuleStore();
85+
86+
};
87+
88+
typedef std::shared_ptr<CUIFrontendDefinitionModuleStore> PUIFrontendDefinitionModuleStore;
89+
4090
class CUIFrontendDefinition {
4191
private:
4292

93+
std::map<std::string, PUIFrontendDefinitionModuleStore> m_ModuleStores;
94+
AMCCommon::PChrono m_pGlobalChrono;
95+
4396
public:
44-
CUIFrontendDefinition();
4597

46-
virtual ~CUIFrontendDefinition();
98+
CUIFrontendDefinition (AMCCommon::PChrono pGlobalChrono);
99+
100+
virtual ~CUIFrontendDefinition ();
101+
102+
PUIFrontendDefinitionModuleStore registerModuleStore (const std::string& sModuleUUID, const std::string& sPath);
103+
104+
AMCCommon::PChrono getGlobalChrono();
47105

48106
};
49107

108+
typedef std::shared_ptr<CUIFrontendDefinition> PUIFrontendDefinition;
109+
50110
}
51111

52112
#endif //__AMC_UI_FRONTENDDEFINITION

Implementation/UI/amc_ui_frontendstate.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535

3636
using namespace AMC;
3737

38-
CUIFrontendState::CUIFrontendState(AMCCommon::PChrono pGlobalChrono)
39-
: m_pGlobalChrono(pGlobalChrono)
38+
CUIFrontendState::CUIFrontendState(PUIFrontendDefinition pFrontendDefinition)
39+
: m_pFrontendDefinition(pFrontendDefinition)
4040
{
41-
m_pLegacyParameterHandler = std::make_shared<CParameterHandler>("", pGlobalChrono);
41+
if (pFrontendDefinition.get () == nullptr)
42+
throw ELibMCInterfaceException(LIBMC_ERROR_INVALIDPARAM);
43+
44+
m_pLegacyParameterHandler = std::make_shared<CParameterHandler>("", pFrontendDefinition->getGlobalChrono ());
4245

4346
}
4447

0 commit comments

Comments
 (0)