Skip to content

Commit beb0a3b

Browse files
mykola-kobets-epamal1img
authored andcommitted
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 22411af commit beb0a3b

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (C) 2025 EPAM Systems, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef AOS_CM_LAUNCHER_STORAGE_HPP_
8+
#define AOS_CM_LAUNCHER_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+
* Represents information about a service instance.
20+
*/
21+
struct InstanceInfo {
22+
/**
23+
* Instance identifier.
24+
*/
25+
InstanceIdent mInstanceID;
26+
27+
/**
28+
* Node identifier.
29+
*/
30+
StaticString<cNodeIDLen> mNodeID;
31+
32+
/**
33+
* Previous node identifier, it's used for node balancing.
34+
*/
35+
StaticString<cNodeIDLen> mPrevNodeID;
36+
37+
/**
38+
* User ID.
39+
*/
40+
uint32_t mUID = 0;
41+
42+
/**
43+
* Timestamp.
44+
*/
45+
Time mTimestamp;
46+
47+
/**
48+
* Instance state.
49+
*/
50+
InstanceState mState;
51+
};
52+
53+
/**
54+
* Interface for service instance storage.
55+
*/
56+
class StorageItf {
57+
public:
58+
/**
59+
* Destructor.
60+
*/
61+
virtual ~StorageItf() = default;
62+
63+
/**
64+
* Adds a new instance to the storage.
65+
*
66+
* @param info instance information.
67+
* @return Error.
68+
*/
69+
virtual Error AddInstance(const InstanceInfo& info) = 0;
70+
71+
/**
72+
* Updates an existing instance in the storage.
73+
*
74+
* @param info updated instance information.
75+
* @return Error.
76+
*/
77+
virtual Error UpdateInstance(const InstanceInfo& info) = 0;
78+
79+
/**
80+
* Removes an instance from the storage.
81+
*
82+
* @param instanceID instance identifier.
83+
* @return Error.
84+
*/
85+
virtual Error RemoveInstance(const InstanceIdent& instanceID) = 0;
86+
87+
/**
88+
* Get information about a stored instance.
89+
*
90+
* @param instanceID instance identifier.
91+
* @param[out] info instance info.
92+
* @return Error.
93+
*/
94+
virtual Error GetInstance(const InstanceIdent& instanceID, InstanceInfo& info) const = 0;
95+
96+
/**
97+
* Get all stored instances.
98+
*
99+
* @param[out] instances all stored instances.
100+
* @return Error.
101+
*/
102+
virtual Error GetInstances(Array<InstanceInfo>& instances) const = 0;
103+
};
104+
105+
/** @}*/
106+
107+
} // namespace aos::cm::storage
108+
109+
#endif

include/aos/common/types.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,31 @@ class ServiceStateType {
15291529
using ServiceStateEnum = ServiceStateType::Enum;
15301530
using ServiceState = EnumStringer<ServiceStateType>;
15311531

1532+
/**
1533+
* Instance state type.
1534+
*/
1535+
class InstanceStateType {
1536+
public:
1537+
enum class Enum {
1538+
eActive,
1539+
eCached,
1540+
ePending,
1541+
};
1542+
1543+
static const Array<const char* const> GetStrings()
1544+
{
1545+
static const char* const sStateStrings[] = {
1546+
"active",
1547+
"cached",
1548+
};
1549+
1550+
return Array<const char* const>(sStateStrings, ArraySize(sStateStrings));
1551+
};
1552+
};
1553+
1554+
using InstanceStateEnum = InstanceStateType::Enum;
1555+
using InstanceState = EnumStringer<InstanceStateType>;
1556+
15321557
} // namespace aos
15331558

15341559
#endif

0 commit comments

Comments
 (0)