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
// 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_storage_manager.h"
#include "logger/log.h"
 
#ifdef USE_RKMEDIA
#include <nlohmann/json.hpp>
#include "flow_export.h"
#include "flow_sm_protocol.h"
#endif
 
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "dbus_storage_manager.cpp"
 
namespace rockchip {
namespace aiserver {
 
DBusStorageManager::DBusStorageManager(DBus::Connection &connection,
                                       const char *adaptor_path,
                                       const char *adaptor_name)
    : DBus::ObjectProxy(connection, adaptor_path, adaptor_name) {}
 
DBusStorageManager::~DBusStorageManager() {}
 
std::string DBusStorageManager::GetStorageStatus() {
  char tmp[128];
  sprintf(tmp, SM_GET_DISK_STATUS);
  return GetDisksStatus(tmp);
}
 
std::string DBusStorageManager::GetStoragePath() {
  char tmp[128];
  sprintf(tmp, SM_GET_DISK_STATUS);
  return GetMediaPath(tmp);
}
 
void DBusStorageManager::UpdateDisksStatus(const std::string &param) {
  // TODO
}
 
void DBusStorageManager::UpdateMediaPath(const std::string &param) {
  // TODO
}
 
void DBusStorageManager::FreeSizeNotice(const std::string &param) {
  // TODO
}
 
DBusStorageManagerListen::DBusStorageManagerListen(DBus::Connection &connection)
    : DBus::InterfaceProxy(STORAGE_MANAGER_DBCHANGE_INTERFACE),
      DBus::ObjectProxy(connection, STORAGE_MANAGER_PATH,
                        STORAGE_MANAGER_BUS_NAME) {
  connect_signal(DBusStorageManagerListen, UpdateDisksStatus,
                 UpdateDisksStatusChanged);
  connect_signal(DBusStorageManagerListen, UpdateMediaPath,
                 UpdateMediaPathChanged);
  connect_signal(DBusStorageManagerListen, FreeSizeNotice,
                 FreeSizeNoticeChanged);
}
 
DBusStorageManagerListen::~DBusStorageManagerListen() {}
 
void DBusStorageManagerListen::UpdateDisksStatusChanged(
    const DBus::SignalMessage &sig) {
  DBus::MessageIter it = sig.reader();
  std::string db_data;
  it >> db_data;
  LOG_INFO("DBusStorageListen UpdateDisksStatusChanged :\n[%s]\n",
           db_data.c_str());
  if (db_data.empty())
    return;
 
#ifdef USE_RKMEDIA
  std::unique_ptr<FlowSMProtocol> sm_protocol;
  sm_protocol.reset(new FlowSMProtocol);
  sm_protocol->DisksStatusChanged(db_data);
#endif
}
 
void DBusStorageManagerListen::UpdateMediaPathChanged(
    const DBus::SignalMessage &sig) {
  DBus::MessageIter it = sig.reader();
  std::string db_data;
  it >> db_data;
  LOG_INFO("DBusStorageListen UpdateMediaPathChanged :\n[%s]\n",
           db_data.c_str());
  if (db_data.empty())
    return;
 
#ifdef USE_RKMEDIA
  std::unique_ptr<FlowSMProtocol> sm_protocol;
  sm_protocol.reset(new FlowSMProtocol);
  sm_protocol->MediaPathChanged(db_data);
#endif
}
 
void DBusStorageManagerListen::FreeSizeNoticeChanged(
    const DBus::SignalMessage &sig) {
  DBus::MessageIter it = sig.reader();
  std::string db_data;
  it >> db_data;
  LOG_INFO("DBusStorageListen FreeSizeNoticeChanged :\n[%s]\n",
           db_data.c_str());
  if (db_data.empty())
    return;
 
#ifdef USE_RKMEDIA
  std::unique_ptr<FlowSMProtocol> sm_protocol;
  sm_protocol.reset(new FlowSMProtocol);
  sm_protocol->FreeSizeNotice(db_data);
#endif
}
 
} // namespace aiserver
} // namespace rockchip