2 // Copyright (C) 2015 Google, Inc.
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 <unordered_map>
24 #include "service/common/bluetooth/uuid.h"
25 #include "service/gatt_server_old.h"
29 } // namespace bluetooth
33 // This implements a single threaded event loop which dispatches
34 // reads from a set of FDs (pfds_) to a set of handlers.
35 // Reads from the GATT pipe read end will result in a write to
36 // to the IPC socket, and vise versa.
39 // LinuxIPCHost owns the passed sockfd.
40 LinuxIPCHost(int sockfd, bluetooth::Adapter* adapter);
43 // Synchronously handle all events on input FDs.
47 // Handler for IPC message receives.
48 // Decodes protocol and dispatches to another handler.
51 // Handler for GATT characteristic writes.
52 // Encodes to protocol and transmits IPC.
55 // Applies adapter name changes to stack.
56 bool OnSetAdapterName(const std::string& name);
58 // Handles service creation.
59 bool OnCreateService(const std::string& service_uuid);
61 // Handles service destruction.
62 bool OnDestroyService(const std::string& service_uuid);
64 // Creates a characteristic for a service.
65 bool OnAddCharacteristic(const std::string& service_uuid,
66 const std::string& characteristic_uuid,
67 const std::string& control_uuid,
68 const std::string& options);
70 // Sets the value of a characetistic.
71 bool OnSetCharacteristicValue(const std::string& service_uuid,
72 const std::string& characteristic_uuid,
73 const std::string& value);
75 // Applies settings to service advertisement.
76 bool OnSetAdvertisement(const std::string& service_uuid,
77 const std::string& advertise_uuids,
78 const std::string& advertise_data,
79 const std::string& manufacturer_data,
80 const std::string& transmit_name);
82 // Applies settings to scan response.
83 bool OnSetScanResponse(const std::string& service_uuid,
84 const std::string& advertise_uuids,
85 const std::string& advertise_data,
86 const std::string& manufacturer_data,
87 const std::string& transmit_name);
89 // Starts service (advertisement and connections)
90 bool OnStartService(const std::string& service_uuid);
93 bool OnStopService(const std::string& service_uuid);
96 bluetooth::Adapter *adapter_;
98 // File descripters that we will block against.
99 std::vector<struct pollfd> pfds_;
101 // Container for multiple GATT servers. Currently only one is supported.
102 // TODO(icoolidge): support many to one for real.
103 std::unordered_map<std::string, std::unique_ptr<bluetooth::gatt::Server>>