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 "gatt_server.h"
31 // This implements a single threaded event loop which dispatches
32 // reads from a set of FDs (pfds_) to a set of handlers.
33 // Reads from the GATT pipe read end will result in a write to
34 // to the IPC socket, and vise versa.
37 // Host owns the passed sockfd.
38 Host(int sockfd, CoreStack* bt);
41 // Synchronously handle all events on input FDs.
45 // Handler for IPC message receives.
46 // Decodes protocol and dispatches to another handler.
49 // Handler for GATT characteristic writes.
50 // Encodes to protocol and transmits IPC.
53 // Applies adapter name changes to stack.
54 bool OnSetAdapterName(const std::string& name);
56 // Handles service creation.
57 bool OnCreateService(const std::string& service_uuid);
59 // Handles service destruction.
60 bool OnDestroyService(const std::string& service_uuid);
62 // Creates a characteristic for a service.
63 bool OnAddCharacteristic(const std::string& service_uuid,
64 const std::string& characteristic_uuid,
65 const std::string& control_uuid,
66 const std::string& options);
68 // Sets the value of a characetistic.
69 bool OnSetCharacteristicValue(const std::string& service_uuid,
70 const std::string& characteristic_uuid,
71 const std::string& value);
73 // Applies settings to service advertisement.
74 bool OnSetAdvertisement(const std::string& service_uuid,
75 const std::string& advertise_uuids,
76 const std::string& advertise_data,
77 const std::string& transmit_name);
79 // Applies settings to scan response.
80 bool OnSetScanResponse(const std::string& service_uuid,
81 const std::string& advertise_uuids,
82 const std::string& advertise_data,
83 const std::string& transmit_name);
85 // Starts service (advertisement and connections)
86 bool OnStartService(const std::string& service_uuid);
89 bool OnStopService(const std::string& service_uuid);
94 // File descripters that we will block against.
95 std::vector<struct pollfd> pfds_;
97 // Container for multiple GATT servers. Currently only one is supported.
98 // TODO(icoolidge): support many to one for real.
99 std::unordered_map<std::string, std::unique_ptr<gatt::Server>> gatt_servers_;
102 } // namespace bluetooth