123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef RKNNMANAGER_H
- #define RKNNMANAGER_H
- #include <thread>
- #include <vector>
- #include <iostream>
- #include <string>
- #include "../GrpcTransfer/GrpcTransfer.h"
- class RKNNManager
- {
- public:
- static RKNNManager &getInstance()
- {
- static RKNNManager instance;
- return instance;
- }
- RKNNManager(const RKNNManager &) = delete;
- RKNNManager &operator=(const RKNNManager &) = delete;
- void setGrpcServerAddress(const std::string &address)
- {
- m_grpcServerAddress = address;
- std::cout << "GRPC Server Address: " << m_grpcServerAddress << std::endl;
- }
- void addRknnTask(std::string modelData);
-
- // 用于重启特定线程
- void restartRknnThread(int threadIndex);
-
- // 检查线程状态并更新线程心跳
- void updateThreadStatus(int threadIndex);
- void StopProcessData()
- {
- for(int i = 0; i < m_threads.size(); i++)
- {
- m_vThreadSwitch[i] = false;
- }
- for (auto &thread : m_threads)
- {
- if (thread.joinable())
- {
- thread.join();
- }
- }
- }
- private:
- RKNNManager() = default;
- ~RKNNManager() = default;
- void taskThread(int index, std::string modelData);
- // 建立gRPC通道
- bool setupGrpcChannel(
- const std::string &target_str,
- std::unique_ptr<MessageService::Stub> &stub,
- std::unique_ptr<grpc::ClientWriter<DataList>> &writer,
- grpc::ClientContext &context,
- R360::Empty &response);
- private:
- std::vector<std::thread> m_threads;
- std::vector<std::thread::id> m_threadIds;
- std::string m_modelData;
- std::string m_grpcServerAddress;
- // thread switch
- std::vector<bool> m_vThreadSwitch;
- bool m_bThreadSwitch;
- };
- #endif // RKNNMANAGER_H
|