Skip to content

Commit 68ad41c

Browse files
cm: add storage interface
Signed-off-by: Mykola Kobets <[email protected]> Reviewed-by: Mykhailo Lohvynenko <[email protected]> Reviewed-by: Oleksandr Grytsov <[email protected]> Reviewed-by: Mykola Solianko <[email protected]>
1 parent 2314dac commit 68ad41c

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

include/aos/cm/storage.hpp

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (C) 2025 EPAM Systems, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef AOS_CM_STORAGE_HPP_
8+
#define AOS_CM_STORAGE_HPP_
9+
10+
#include <aos/common/types.hpp>
11+
12+
namespace aos::cm::storage {
13+
14+
/** @addtogroup CM Storage
15+
* @{
16+
*/
17+
18+
/**
19+
* Instance state type.
20+
*/
21+
class InstanceStateType {
22+
public:
23+
enum class Enum {
24+
eActive,
25+
eCached,
26+
ePending,
27+
};
28+
29+
static const Array<const char* const> GetStrings()
30+
{
31+
static const char* const sStateStrings[] = {
32+
"active",
33+
"cached",
34+
};
35+
36+
return Array<const char* const>(sStateStrings, ArraySize(sStateStrings));
37+
};
38+
};
39+
40+
using InstanceStateEnum = InstanceStateType::Enum;
41+
using InstanceState = EnumStringer<InstanceStateType>;
42+
43+
/**
44+
* Represents information about a service instance.
45+
*/
46+
struct InstanceInfo {
47+
/**
48+
* Instance identifier.
49+
*/
50+
InstanceIdent mInstanceID;
51+
52+
/**
53+
* Node identifier.
54+
*/
55+
StaticString<cNodeIDLen> mNodeID;
56+
57+
/**
58+
* Previous node identifier, it's used for node balancing.
59+
*/
60+
StaticString<cNodeIDLen> mPrevNodeID;
61+
62+
/**
63+
* User ID.
64+
*/
65+
uint32_t mUID = 0;
66+
67+
/**
68+
* Timestamp.
69+
*/
70+
Time mTimestamp;
71+
72+
/**
73+
* Instance state.
74+
*/
75+
InstanceStateType state;
76+
};
77+
78+
/**
79+
* Interface for service instance storage.
80+
*/
81+
class StorageItf {
82+
public:
83+
/**
84+
* Destructor.
85+
*/
86+
virtual ~StorageItf() = default;
87+
88+
/**
89+
* Adds a new instance to the storage.
90+
*
91+
* @param info instance information.
92+
* @return Error.
93+
*/
94+
virtual Error AddInstance(const InstanceInfo& info) = 0;
95+
96+
/**
97+
* Updates an existing instance in the storage.
98+
*
99+
* @param info updated instance information.
100+
* @return Error.
101+
*/
102+
virtual Error UpdateInstance(const InstanceInfo& info) = 0;
103+
104+
/**
105+
* Removes an instance from the storage.
106+
*
107+
* @param instanceID instance identifier.
108+
* @return Error.
109+
*/
110+
virtual Error RemoveInstance(const InstanceIdent& instanceID) = 0;
111+
112+
/**
113+
* Get information about a stored instance.
114+
*
115+
* @param instanceID instance identifier.
116+
* @param[out] info instance info.
117+
* @return Error.
118+
*/
119+
virtual Error GetInstance(const InstanceIdent& instanceID, InstanceInfo& info) const = 0;
120+
121+
/**
122+
* Get all stored instances.
123+
*
124+
* @param[out] instances all stored instances.
125+
* @return Error.
126+
*/
127+
virtual Error GetInstances(Array<InstanceInfo>& instances) const = 0;
128+
};
129+
130+
/** @}*/
131+
132+
} // namespace aos::cm::storage
133+
134+
#endif

0 commit comments

Comments
 (0)