File indexing completed on 2024-05-12 16:25:01

0001 /*
0002  * SPDX-FileCopyrightText: 2014 YANG Qiao <yangqiao0505@me.com>
0003  *                         2020 Weixuan Xiao <veyx.shaw@gmail.com>
0004  *                         2021 Lucas Wang <lucas.wang@tuta.io>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007  */
0008 
0009 // Original header below:
0010 //Copyright 29/4/14  YANG Qiao yangqiao0505@me.com
0011 //kdeconnect is distributed under two licenses.
0012 //
0013 //* The Mozilla Public License (MPL) v2.0
0014 //
0015 //or
0016 //
0017 //* The General Public License (GPL) v2.1
0018 //
0019 //----------------------------------------------------------------------
0020 //
0021 //Software distributed under these licenses is distributed on an "AS
0022 //IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
0023 //implied. See the License for the specific language governing rights
0024 //and limitations under the License.
0025 //kdeconnect is distributed under both the GPL and the MPL. The MPL
0026 //notice, reproduced below, covers the use of either of the licenses.
0027 //
0028 //---------------------------------------------------------------------
0029 
0030 #import <Foundation/Foundation.h>
0031 #import "BaseLink.h"
0032 #import "NetworkPackage.h"
0033 #import "UIKit/UIKit.h"
0034 //#import "deviceDelegate.h"
0035 //#import "BackgroundService.h"
0036 @class BaseLink;
0037 @class NetworkPackage;
0038 @protocol Plugin;
0039 //@class Ping;
0040 //@class Share;
0041 //@class FindMyPhone;
0042 //@class Battery;
0043 //@interface PluginInterface;
0044 
0045 typedef NS_ENUM(NSUInteger, PairStatus)
0046 {
0047     NotPaired=0,
0048     Requested=1,
0049     RequestedByPeer=2,
0050     Paired=3
0051 };
0052 
0053 typedef NS_ENUM(NSUInteger, DeviceType)
0054 {
0055     DeviceTypeUnknown=0,
0056     DeviceTypeDesktop=1,
0057     DeviceTypeLaptop=2,
0058     DeviceTypePhone=3,
0059     DeviceTypeTablet=4,
0060     DeviceTypeTv=5,
0061 };
0062 
0063 @protocol DeviceDelegate;
0064 
0065 @interface Device : NSObject <LinkDelegate, NSSecureCoding>
0066 
0067 @property(readonly, nonatomic) NSString *_id;
0068 @property(readonly, nonatomic) NSString *_name;
0069 @property(readonly, nonatomic) DeviceType _type;
0070 @property(readonly, nonatomic) NSInteger _protocolVersion;
0071 @property(readonly, nonatomic) PairStatus _pairStatus;
0072 @property(readonly, nonatomic) NSArray<NSString *> *_incomingCapabilities;
0073 @property(readonly, nonatomic) NSArray<NSString *> *_outgoingCapabilities;
0074 
0075 @property(nonatomic) NSMutableArray* _links;
0076 @property(nonatomic, setter=setPlugins:) NSDictionary<NetworkPackageType, id<Plugin>> *plugins;
0077 @property(nonatomic) NSMutableArray* _failedPlugins;
0078 
0079 @property(nonatomic, copy) NSString* _SHA256HashFormatted;
0080 
0081 @property(nonatomic) id<DeviceDelegate> deviceDelegate;
0082 
0083 //@property(readonly,nonatomic) BOOL _testDevice;
0084 
0085 // Plugin enable status
0086 @property(nonatomic, setter=setPluginsEnableStatus:) NSDictionary<NetworkPackageType, NSNumber *> *pluginsEnableStatus;
0087 
0088 // Plugin-specific persistent data are stored in the Device object. Plugin objects contain runtime
0089 // data only and are therefore NOT stored persistently
0090 // Remote Input
0091 @property(nonatomic) float _cursorSensitivity;
0092 @property(nonatomic) UIImpactFeedbackStyle hapticStyle;
0093 // Presenter
0094 @property(nonatomic) float _pointerSensitivity;
0095 
0096 // For NSCoding
0097 @property (class, readonly) BOOL supportsSecureCoding;
0098 
0099 - (instancetype)init NS_UNAVAILABLE;
0100 - (instancetype)initWithID:(NSString *)deviceID
0101                       type:(DeviceType)deviceType
0102                       name:(NSString *)deviceName
0103       incomingCapabilities:(NSArray<NSString *> *)incomingCapabilities
0104       outgoingCapabilities:(NSArray<NSString *> *)outgoingCapabilities
0105            protocolVersion:(NSInteger)protocolVersion
0106             deviceDelegate:(id<DeviceDelegate>)deviceDelegate;
0107 - (instancetype)initWithNetworkPackage:(NetworkPackage *)np
0108                                   link:(BaseLink*)link
0109                               delegate:(id<DeviceDelegate>)deviceDelegate;
0110 - (NSInteger) compareProtocolVersion;
0111 
0112 #pragma mark Link-related Functions
0113 - (void)updateInfoWithNetworkPackage:(NetworkPackage *)np;
0114 - (void)addLink:(BaseLink *)link;
0115 - (void)onPackageReceived:(NetworkPackage *)np;
0116 - (void)onLinkDestroyed:(BaseLink *)link;
0117 - (BOOL)sendPackage:(NetworkPackage *)np tag:(long)tag;
0118 - (BOOL)isReachable;
0119 
0120 #pragma mark Pairing-related Functions
0121 - (BOOL)isPaired;
0122 - (BOOL)isPaireRequested;
0123 //- (void)setAsPaired; // Is this needed to be public?
0124 - (void)requestPairing;
0125 - (void)setAsUnpaired;
0126 - (void)unpair;
0127 - (void)acceptPairing;
0128 
0129 #pragma mark Plugin-related Functions
0130 - (void) reloadPlugins;
0131 // - (NSArray*) getPluginViews:(UIViewController*)vc;
0132 
0133 #pragma mark enum tools
0134 + (NSString*)DeviceType2Str:(DeviceType)type;
0135 + (DeviceType)Str2DeviceType:(NSString*)str;
0136 @end
0137 
0138 @protocol DeviceDelegate <NSObject>
0139 @optional
0140 - (void)onDeviceReachableStatusChanged:(Device *)device;
0141 - (void)onDevicePairRequest:(Device *)device;
0142 - (void)onDevicePairTimeout:(Device *)device;
0143 - (void)onDevicePairSuccess:(Device *)device;
0144 - (void)onDevicePairRejected:(Device *)device;
0145 - (void)onDeviceUnpaired:(Device *)device;
0146 - (void)onDevicePluginChanged:(Device *)device;
0147 - (void)onLinkDestroyed:(BaseLink *)link;
0148 @end