Userspace Resource Manager
Loading...
Searching...
No Matches
ClientDataManager.h
1// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2// SPDX-License-Identifier: BSD-3-Clause-Clear
3
4#ifndef CLIENT_DATA_MANAGER_H
5#define CLIENT_DATA_MANAGER_H
6
7#include <vector>
8#include <unordered_map>
9#include <unordered_set>
10#include <shared_mutex>
11#include <memory>
12#include <mutex>
13#include "string.h"
14#include "unistd.h"
15#include "fstream"
16#include "sstream"
17
18#include "ErrCodes.h"
19#include "DLManager.h"
20#include "UrmSettings.h"
21#include "MemoryPool.h"
22#include "Logger.h"
23#include "Utils.h"
24
25#define PER_CLIENT_TID_CAP 32
26
27typedef struct _client_info {
28 uint8_t mClientType;
29 int32_t mCurClientThreads;
30 int32_t mClientTIDs[PER_CLIENT_TID_CAP];
31
32 _client_info(): mCurClientThreads(0) {}
33} ClientInfo;
34
35typedef struct {
36 std::unordered_set<int64_t>* mClientHandles;
37 int64_t mLastRequestTimestamp;
38 double mHealth;
39} ClientTidData;
40
52private:
53 static std::shared_ptr<ClientDataManager> mClientDataManagerInstance;
54 static std::mutex instanceProtectionLock;
55 std::unordered_map<int32_t, ClientInfo*> mClientRepo;
56 std::unordered_map<int32_t, ClientTidData*> mClientTidRepo;
57 std::shared_timed_mutex mGlobalTableMutex;
58
60
61public:
70 int8_t clientExists(int32_t clientPID, int32_t clientTID);
71
81 int8_t createNewClient(int32_t clientPID, int32_t clientTID);
82
89 std::unordered_set<int64_t>* getRequestsByClientID(int32_t clientTID);
90
97 void insertRequestByClientId(int32_t clientTID, int64_t requestHandle);
98
105 void deleteRequestByClientId(int32_t clientTID, int64_t requestHandle);
106
114 double getHealthByClientID(int32_t clientTID);
115
123 int64_t getLastRequestTimestampByClientID(int32_t clientTID);
124
131 void updateHealthByClientID(int32_t clientTID, double health);
132
139 void updateLastRequestTimestampByClientID(int32_t clientTID, int64_t currentMillis);
140
150 int8_t getClientLevelByClientID(int32_t clientPID);
151
152 void getThreadsByClientId(int32_t clientPID, std::vector<int32_t>& threadIDs);
153
158 void getActiveClientList(std::vector<int32_t>& clientList);
159
164 void deleteClientPID(int32_t clientPID);
165
170 void deleteClientTID(int32_t clientTID);
171
172 static std::shared_ptr<ClientDataManager> getInstance() {
173 if(mClientDataManagerInstance == nullptr) {
174 instanceProtectionLock.lock();
175 if(mClientDataManagerInstance == nullptr) {
176 try {
177 mClientDataManagerInstance = std::shared_ptr<ClientDataManager> (new ClientDataManager());
178 } catch(const std::bad_alloc& e) {
179 instanceProtectionLock.unlock();
180 return nullptr;
181 }
182 }
183 instanceProtectionLock.unlock();
184 }
185 return mClientDataManagerInstance;
186 }
187};
188
189#endif
void deleteClientPID(int32_t clientPID)
Delete a client PID Entry from the Client Table.
void getActiveClientList(std::vector< int32_t > &clientList)
This method is called by the PulseMonitor to fetch the list of all active clients.
void deleteClientTID(int32_t clientTID)
Delete a client TID Entry from the Client TID Data Table.
void updateHealthByClientID(int32_t clientTID, double health)
This method is called by the RateLimiter to update the current health for a given client in the Clien...
std::unordered_set< int64_t > * getRequestsByClientID(int32_t clientTID)
Returns a list of active requests for the client with the given PID.
double getHealthByClientID(int32_t clientTID)
This method is called by the RateLimiter to fetch the current health for a given client in the Client...
void updateLastRequestTimestampByClientID(int32_t clientTID, int64_t currentMillis)
This method is called by the RateLimiter to update the Last Request Timestamp for a given client in t...
void deleteRequestByClientId(int32_t clientTID, int64_t requestHandle)
This method is called by the RequestMap to delete a Request (represented by it's handle) for the clie...
int64_t getLastRequestTimestampByClientID(int32_t clientTID)
This method is called by the RateLimiter to fetch the Last Request Timestamp for a given client in th...
int8_t createNewClient(int32_t clientPID, int32_t clientTID)
Create a new entry for the client with the given PID in the ClientData Table.
std::unordered_map< int32_t, ClientTidData * > mClientTidRepo
Maintains Client Info indexed by TID.
int8_t clientExists(int32_t clientPID, int32_t clientTID)
Checks if the client with the given ID exists in the Client Data Table.
int8_t getClientLevelByClientID(int32_t clientPID)
This method is called by the Verifier to fetch the Permission Level for a given client in the Client ...
std::unordered_map< int32_t, ClientInfo * > mClientRepo
Maintains Client Info indexed by PID.
void insertRequestByClientId(int32_t clientTID, int64_t requestHandle)
This method is called by the RequestMap to insert a new Request (represented by it's handle) for the ...