Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_FlyWebDiscoveryManager_h
8 : #define mozilla_dom_FlyWebDiscoveryManager_h
9 :
10 : #include "nsISupportsImpl.h"
11 : #include "mozilla/ErrorResult.h"
12 : #include "nsRefPtrHashtable.h"
13 : #include "nsWrapperCache.h"
14 : #include "FlyWebDiscoveryManagerBinding.h"
15 : #include "FlyWebService.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : class FlyWebDiscoveryManager final : public nsISupports
21 : , public nsWrapperCache
22 : {
23 : public:
24 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FlyWebDiscoveryManager)
26 :
27 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
28 : nsISupports* GetParentObject() const;
29 :
30 : static already_AddRefed<FlyWebDiscoveryManager> Constructor(const GlobalObject& aGlobal,
31 : ErrorResult& rv);
32 :
33 : void ListServices(nsTArray<FlyWebDiscoveredService>& aServices);
34 : uint32_t StartDiscovery(FlyWebDiscoveryCallback& aCallback);
35 : void StopDiscovery(uint32_t aId);
36 :
37 : void PairWithService(const nsAString& aServiceId,
38 : FlyWebPairingCallback& callback);
39 :
40 : void NotifyDiscoveredServicesChanged();
41 :
42 : private:
43 : FlyWebDiscoveryManager(nsISupports* mParent, FlyWebService* aService);
44 : ~FlyWebDiscoveryManager();
45 :
46 0 : uint32_t GenerateId() {
47 0 : return ++mNextId;
48 : }
49 :
50 : nsCOMPtr<nsISupports> mParent;
51 : RefPtr<FlyWebService> mService;
52 :
53 : uint32_t mNextId;
54 :
55 : nsRefPtrHashtable<nsUint32HashKey, FlyWebDiscoveryCallback> mCallbackMap;
56 : };
57 :
58 : } // namespace dom
59 : } // namespace mozilla
60 :
61 : #endif // mozilla_dom_FlyWebDiscoveryManager_h
|