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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// 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 <assert.h>
#include <fcntl.h>
 
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unistd.h>
 
#include "dbus_dbserver.h"
#include "logger/log.h"
 
#ifdef USE_RKMEDIA
#include <nlohmann/json.hpp>
#include "flow_db_protocol.h"
#endif
 
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "dbus_dbserver"
 
namespace rockchip {
namespace aiserver {
 
DBusDbServer::DBusDbServer(DBus::Connection &connection,
                           const char *adaptor_path, const char *adaptor_name)
    : DBus::ObjectProxy(connection, adaptor_path, adaptor_name) {}
 
DBusDbServer::~DBusDbServer() {}
 
void DBusDbServer::DataChanged(const std::string &param) {
    // NO NEED TODO
}
 
std::string DBusDbServer::SelectVideoDb(int id) {
  char tmp[128];
  sprintf(tmp, DB_SELECT_VIDEO_CMD, id);
  return Cmd(tmp);
}
 
std::string DBusDbServer::SelectAudioDb(int id) {
  char tmp[128];
  sprintf(tmp, DB_SELECT_AUDIO_CMD, id);
  return Cmd(tmp);
}
 
std::string DBusDbServer::SelectOsdDb(int region_id) {
  char tmp[128];
  sprintf(tmp, DB_SELECT_OSD_REGION_CMD, region_id);
  return Cmd(tmp);
}
 
std::string DBusDbServer::SelectRoiDb(int region_id) {
  char tmp[128];
  sprintf(tmp, DB_SELECT_ROI_REGION_CMD, region_id);
  return Cmd(tmp);
}
 
DBusDbListener::DBusDbListener(DBus::Connection &connection)
    : DBus::InterfaceProxy(DBSERVER_DBCHANGE_INTERFACE),
      DBus::ObjectProxy(connection, DBSERVER_PATH, DBSERVER_BUS_NAME) {
  connect_signal(DBusDbListener, DataChanged, DataChangedCb);
}
 
DBusDbListener::~DBusDbListener() {}
 
void DBusDbListener::DataChangedCb(const DBus::SignalMessage &sig) {
  DBus::MessageIter it = sig.reader();
  std::string db_data;
  it >> db_data;
  printf("DBus data changed [%s]\n", db_data.c_str());
 
#ifdef USE_RKMEDIA
  std::unique_ptr<FlowDbProtocol> db_protocol;
  db_protocol.reset(new FlowDbProtocol);
  db_protocol->DbDataDispatch(db_data);
#endif
}
 
DBusDbEvent::DBusDbEvent(DBus::Connection &connection, const char *adaptor_path,
                         const char *adaptor_name)
    : DBus::ObjectProxy(connection, adaptor_path, adaptor_name) {}
 
DBusDbEvent::~DBusDbEvent() {}
 
void DBusDbEvent::DataChanged(const std::string &param) {
  // NO NEED TODO
}
 
std::string DBusDbEvent::SelectRegionInvade(int id) {
  char tmp[128];
  sprintf(tmp, DB_SELECT_REGION_INVADE_CMD, id);
  return Cmd(tmp);
}
 
std::string DBusDbEvent::SelectMoveDetectDb(int id) {
  char tmp[128];
  sprintf(tmp, DB_SELECT_MOVE_DETECTION_CMD, id);
  return Cmd(tmp);
}
 
DBusDbEventListener::DBusDbEventListener(DBus::Connection &connection)
    : DBus::InterfaceProxy(DBSERVER_DBEVENT_CHANGE_INTERFACE),
      DBus::ObjectProxy(connection, DBSERVER_PATH, DBSERVER_BUS_NAME) {
  connect_signal(DBusDbEventListener, DataChanged, DataChangedCb);
}
 
DBusDbEventListener::~DBusDbEventListener() {}
 
void DBusDbEventListener::DataChangedCb(const DBus::SignalMessage &sig) {
  DBus::MessageIter it = sig.reader();
  std::string db_data;
  it >> db_data;
  printf("DBus envent: [%s]\n", db_data.c_str());
 
#ifdef USE_RKMEDIA
  std::unique_ptr<FlowDbProtocol> db_protocol;
  db_protocol.reset(new FlowDbProtocol);
  db_protocol->DbDataDispatch(db_data);
#endif
}
 
} // namespace aiserver
} // namespace rockchip