hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2019 Fuzhou Rockchip Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
#include "shm_control_nn.h"
#include "logger/log.h"
 
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "shm_control_nn"
 
namespace rockchip {
namespace aiserver {
 
ShmNNController::ShmNNController() {
    shmWriteInited = 0;
    initialize();
}
 
ShmNNController::~ShmNNController() {
 
}
 
void ShmNNController::initialize() {
    if (shmWriteInited) {
        return;
    }
 
#ifdef ENABLE_SHM_SERVER
    shmc::SetLogHandler(shmc::kDebug, [](shmc::LogLevel lv, const char *s) {
        LOG_INFO("[%d] %s\n", lv, s);
    });
    shmWriteInited = shmNNQueue.InitForWrite(kShmNNKey, kNNQueueBufSize);
#endif
}
 
void ShmNNController::send(std::string &buf) {
    if (!shmWriteInited) {
        initialize();
    }
 
    if (shmWriteInited) {
        shmNNQueue.Push(buf);
    } else {
        LOG_ERROR("shm nn init for write failed");
    }
}
 
}
}
// namespace ShmControl