4 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <external_sensor_record.h>
23 external_sensor_record::external_sensor_record()
29 external_sensor_record::~external_sensor_record()
31 close_command_socket();
34 bool external_sensor_record::add_usage(sensor_id_t sensor)
36 if (!m_usages.insert(sensor).second) {
37 _E("Sensor[%#x] is already registered", sensor);
44 bool external_sensor_record::remove_usage(sensor_id_t sensor)
46 if (!m_usages.erase(sensor)) {
47 _E("Sensor[%#x] is not found", sensor);
54 bool external_sensor_record::has_usage(void)
56 return !m_usages.empty();
59 bool external_sensor_record::has_usage(sensor_id_t sensor)
61 auto it_usage = m_usages.find(sensor);
63 return (it_usage != m_usages.end());
66 void external_sensor_record::set_client_id(int client_id)
68 m_client_id = client_id;
71 void external_sensor_record::set_client_info(pid_t pid, const string &name)
73 char client_info[NAME_MAX + 32];
76 snprintf(client_info, sizeof(client_info), "%s[pid=%d, id=%d]", name.c_str(), m_pid, m_client_id);
77 m_client_info.assign(client_info);
80 const char* external_sensor_record::get_client_info(void)
82 return m_client_info.c_str();
85 void external_sensor_record::set_command_socket(const csocket &socket)
87 m_command_socket = socket;
90 void external_sensor_record::get_command_socket(csocket &socket)
92 socket = m_command_socket;
95 bool external_sensor_record::close_command_socket(void)
97 return m_command_socket.close();