1 // Copyright 2016 The Weave Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef LIBWEAVE_SRC_ACCESS_API_HANDLER_H_ 6 #define LIBWEAVE_SRC_ACCESS_API_HANDLER_H_ 7 8 #include <memory> 9 10 #include <base/memory/weak_ptr.h> 11 #include <weave/error.h> 12 13 namespace weave { 14 15 class AccessBlackListManager; 16 class Command; 17 class Device; 18 19 // Handles commands for 'accessControlBlackList' trait. 20 // Objects of the class subscribe for notification from CommandManager and 21 // execute incoming commands. 22 // Handled commands: 23 // accessControlBlackList.block 24 // accessControlBlackList.unblock 25 // accessControlBlackList.list 26 class AccessApiHandler final { 27 public: 28 AccessApiHandler(Device* device, AccessBlackListManager* manager); 29 30 private: 31 void Block(const std::weak_ptr<Command>& command); 32 void Unblock(const std::weak_ptr<Command>& command); 33 void List(const std::weak_ptr<Command>& command); 34 void UpdateState(); 35 36 void OnCommandDone(const std::weak_ptr<Command>& command, ErrorPtr error); 37 38 Device* device_{nullptr}; 39 AccessBlackListManager* manager_{nullptr}; 40 41 base::WeakPtrFactory<AccessApiHandler> weak_ptr_factory_{this}; 42 DISALLOW_COPY_AND_ASSIGN(AccessApiHandler); 43 }; 44 45 } // namespace weave 46 47 #endif // LIBWEAVE_SRC_ACCESS_API_HANDLER_H_ 48