2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include "internal/bus_names_array.hpp"
23 #include <boost/utility/string_ref.hpp>
25 class KdbusConnectionInfo;
27 class KdbusConnection {
31 int open_bus(const char *path);
32 int hello(uint64_t hello_flags,
33 uint64_t attach_flags_send,
34 uint64_t attach_flags_recv);
36 typedef enum { POLICY_CONN_INFO_ALL, POLICY_CONN_INFO_NAME } conn_info_type;
38 void shared_init_fd(int fd_to_set) { fd = fd_to_set; }
39 void shared_init_pool(void *pool_to_set) { pool = static_cast<decltype(pool)>(pool_to_set); }
40 int connect(const char *path,
42 uint64_t attach_flags_send,
43 uint64_t attach_flags_recv);
44 int get_conn_info(const char *bus_name,
45 conn_info_type conn_info_type,
46 KdbusConnectionInfo *info);
47 int free_by_offset(uint64_t offset);
50 class KdbusConnectionInfo {
51 static const uid_t UID_INVALID = -1;
52 static const gid_t GID_INVALID = -1;
54 char const *_label{nullptr};
56 KdbusBusNames k_names;
57 uint64_t free_offset{0};
58 uid_t uid_n{UID_INVALID};
59 gid_t gid_n{GID_INVALID};
62 KdbusConnection &my_connection;
65 KdbusConnectionInfo(KdbusConnection &c) : my_connection{c} {}
66 ~KdbusConnectionInfo() { release_info(); }
69 void setNewData(uint64_t offset);
71 void addName(const char *name) { k_names.push_back(name); }
73 void setCreds(uid_t uid, gid_t gid) { uid_n = uid; gid_n = gid; }
75 void setLabel(const char *label) { _label = label; }
77 int get(const char *destination, KdbusConnection::conn_info_type conn_info_type) {
78 return my_connection.get_conn_info(destination, conn_info_type, this);
80 const KdbusBusNames &names() const { return k_names; }
81 KdbusBusNames &names() { return k_names; }
82 uid_t uid() const { return uid_n; }
83 gid_t gid() const { return gid_n; }
84 const char *label() const { return _label; }