//
//  ASControlTools.h
//  libAS-Control
//
//  Created by Alex Zhou on 15/12/2.
//  Copyright © 2015年 AirSmart. All rights reserved.
//
#import <UIKit/UIKit.h>
//#import "upnp.h"
#import <Foundation/Foundation.h>

//#define M3U_LOCATION "/web/playlist.m3u"
//#define M3U_LEN strlen(mGetM3UList())+1
//#define M3U_CONTENT_TYPE "audio/mpegurl"


@protocol ASControlDelegate

@optional

-(void)ReceivedStopCallBack:(NSString *)nUDN;

-(void)ReceivedPlayCallBack:(NSString *)nUDN;

-(void)ReceivedPauseCallBack:(NSString *)nUDN;

-(void)ReceivedSetVolumeCallBack:(NSString *)nUDN Volume:(NSInteger)Volume;

-(void)ReceivedSetMuteCallBack:(NSString *)nUDN Mute:(NSInteger)Mute;

-(void)ReceivedSetZoneMuteCallBack:(NSString *)nUDN Mute:(NSInteger)Mute;

-(void)ReceivedChangeChannelCallBack:(NSString *)nUDN Channel:(NSString *)channel;


-(void)ReceivedSetGroupIdCallBack:(NSString *)nUDN GrouId:(NSString *)GroupId;

-(void)ReceivedSetSleepStateCallBack:(NSString *)nUDN SleepState:(NSString *)SleepState;

-(void)ReceivedSetSoundSourceCallBack:(NSString *)nUDN SoundSource:(NSString *)SoundSource;

-(void)ReceivedSetVolumeChannelCallBack:(NSString *)nUDN Channel:(NSString *)Channel;

-(void)ReceivedSetZoneVolumeCallBack:(NSString *)nUDN Volume:(NSInteger)Volume;

-(void)CallBackRemoveZoneMedia:(NSString *)nByeUDN BaseURL:(NSString *)BaseURL;

-(void)CallBackRemoveRenderer:(NSString *)nByeUDN BaseURL:(NSString *)BaseURL;

-(void)CallBackRemoveDMS:(NSString *)nByeUDN BaseURL:(NSString *)BaseURL;

-(void)CallBackAddZoneMedia:(NSArray *)nStr Size:(NSInteger)size;

-(void)CallBackAddMediaServer:(NSArray *)nStr Size:(NSInteger)size;

-(void)CallBackAddMediaRenderer:(NSArray *)nStr Size:(NSInteger)size;

-(void)getLocalIp:(NSString *)Ip;


-(void)AddLocalResource:(NSArray *)oneSongID3Info;

-(void) UpdateLocalResourceFinish;


@end
//
//extern UpnpClient_Handle nctrlpt_handle;
//extern UpnpDevice_Handle ndevice_handle;

@interface ASControlTools : NSObject

@property (nonatomic, assign) id<ASControlDelegate> delegate;
@property int ImportLibRc;

@property (strong, nonatomic) NSMutableDictionary *allIpodLibrarySongList;


@property BOOL isTransformingIpodURL;

+ (ASControlTools *)sharedInstanceUPNP;


- (NSString *) localWiFiIPAddress;

- (NSString *)getIPAddress;
@property (strong, nonatomic) NSString *myIp;


//int libupnp_UpnpStart(NSString * name,NSString * server,NSString * renderer,int Type,int SearchTime,NSString *Devinfo, int VersionCode);

int libupnp_RELoadUpnp();//检测到断网的时候，用于释放upnp内存用的，使用完这个以后，才能再次重新start upnp


int libupnp_UpnpQuickExit();//退出应用程序的时候用这个释放upnp

int libupnp_UpnpSetWebServerRootDir(NSString *dir);

int libupnp_SearchByUUID(int sleeptime,NSString *UUID, NSString *BaseURL);//按照UUID搜索设备


int libupnp_FirstCheckByBaseURL(int ListCount,NSMutableArray *BaseURList);

int libupnp_SearchBybaseURL( NSString *BaseURL);

int libupnp_SearchDevice( int sleeptime);//搜索设备


int libupnp_SearchServer( int sleeptime);//搜索设备


int libupnp_SearchDeviceAndServer( int sleeptime);//全搜索


int libupnp_RemoveZoneMedia( NSString *UDN, NSString *BaseURL);//上层检测到设备丢失的时候，主动调用底层删除设备

//上层检测到设备丢失的时候，主动调用底层删除设备

int libupnp_RemoveRenderer(NSString *UDN , NSString *BaseURL);//上层检测到设备丢失的时候，主动调用底层删除设备


int libupnp_RemoveDMS(NSString *UDN, NSString *BaseURL);//上层检测到设备丢失的时候，主动调用底层删除设备

-(NSMutableArray *)libupnp_SearchDeviceRes:(NSArray *)oneDMSProperty;

-(NSArray *)libupnp_GetTransportInfo:(NSString *) controlurl;

-(NSArray *)libupnp_GetPositionInfo:(NSString *)controlurl;

int libupnp_SetAVTransportURI(NSString *controlurl,
                              NSString *encodedURL,
                              NSString *title,//歌曲名
                              NSString *artist,//艺人
                              NSString *album,//专辑名
                              NSString *albumArtUri,//专辑封面
                              NSString *duration,//歌曲时长
                              NSString *protocolInfo,//文件类型
                              NSString *upnpclass,
                              NSString *Timestamp,
                              NSString *channelNum,
                              NSString *songOrder,
                              NSString *controlpoint,
                              NSString *songID,
                              NSString *songFrom,//来源类别
                              NSString *songAlbumID);//专辑ID

int libupnp_SetAVTransportURI_DLNA(NSString *controlurl,
                                   NSString *encodedURL,
                                   NSString *title,//歌曲名
                                   NSString *artist,//艺人
                                   NSString *album,//专辑名
                                   NSString *albumArtUri,//专辑封面
                                   NSString *duration,//歌曲时长
                                   NSString *protocolInfo,//文件类型
                                   NSString *upnpclass);//来源类别


//下一首播放连接
int libupnp_SetNextAVTransportURI(NSString *controlurl,
                                  NSString *encodedURL,
                                  NSString *title,//歌曲名
                                  NSString *artist,//艺人
                                  NSString *album,//专辑名
                                  NSString *albumArtUri,//专辑封面
                                  NSString *duration,//歌曲时长
                                  NSString *protocolInfo,//文件类型
                                  NSString *upnpclass,
                                  NSString *Timestamp,
                                  NSString *channelNum,
                                  NSString *songOrder,
                                  NSString *controlpoint);//来源类别

int libupnp_Play(NSString *Controlurl);

int libupnp_Next(NSString *ControlURL) ;
int libupnp_Previous(NSString *ControlURL);



int libupnp_Pause(NSString *ControlURL);


int libupnp_ZonePause(NSString *ControlURL,NSString *ServiceType);


int libupnp_Stop(NSString *Controlurl);

int libupnp_ZoneStop(NSString *Controlurl,NSString *ServiceType);

int libupnp_SetMediaSeek(NSString *ControlURL , NSString *Time);


int libupnp_GetVolume(NSString * ControlURL ,NSString * Channel);
int libupnp_SetVolume( NSString *ControlURL , NSString *Channel,int Volume);

int libupnp_SetZoneVolume(NSString  *ControlURL,NSString * ServiceTYPE, NSString *Sign ,int Volume);



int libupnp_ZoneMediaSetChannel( NSString *Controlurl ,NSString * ServiceTYPE,NSString *Channel);

int libupnp_GetMute(NSString *ControlURL ,NSString *Channel);

int libupnp_SetMute(NSString *ControlURL ,NSString *Channel , int Mute);



int libupnp_SetZoneMute(NSString *ControlURL, NSString *ServiceTYPE, NSString *Channel , int Mute);


int libupnp_SetSKYDevName(NSString  *ControlURL ,NSString *ServiceTYPE, NSString *Name);

int libupnp_SetWifi(NSString *ControlURL,NSString *ServiceTYPE,NSString *Ssid, NSString *Psk, NSString *Mode);
int libupnp_SetAP(NSString  *ControlURL ,NSString *ServiceTYPE);

int libupnp_RebootUpnp(NSString  *ControlURL ,NSString *ServiceTYPE);


int libupnp_SetSoundSource(NSString  *ControlURL ,NSString *ServiceTYPE,NSString *SoundSource);


int libupnp_SetSleepState(NSString  *ControlURL ,NSString *ServiceTYPE,NSString *SleepState);

int libupnp_SetNewM3UList(NSMutableArray *Seconds, NSMutableArray *Artist, NSMutableArray *Title, NSMutableArray *Url, NSMutableArray *CUE, NSMutableArray *StartTimeList, NSMutableArray *EndTimeList,NSMutableArray *VIPCanPlayList, NSMutableArray *Album,NSMutableArray *AlbumArtURI,NSMutableArray *Duration,NSMutableArray *ProtocolInfo,NSMutableArray *UpnpClass, NSMutableArray *ChannelNumList, NSMutableArray *SongOrderList, NSString *ControlPoint, NSMutableArray *SongIDList, NSMutableArray *SongFromList, NSMutableArray *SongAlbumIDList,NSString *CurrentChannel ,NSString *CurrentPlayMode,NSString *Timestamp,NSString *ChannelPure,NSString *AlbumID,NSString *ChannelInfo,NSString *UserID,int StartIndex,int EndIndex,int TotalNum,NSString *DevUUId);

int libupnp_SetNewM3UListV2(NSMutableArray *Seconds,
                            NSMutableArray *Artist,
                            NSMutableArray *Title,
                            NSMutableArray *Url,
                            NSMutableArray *SongFromList,
                            NSString *CurrentChannel ,
                            NSString *CurrentPlayMode,
                            NSString *Timestamp,
                            int StartIndex,
                            int EndIndex,
                            int TotalNum,
                            NSString *ChannelID,
                            NSString *ChannelInfo);

int libupnp_GetTransportSettings(NSString  *ControlURL);

int libupnp_SetPlayMode(NSString *ControlURL, NSString *CurrentPlayMode);  //设置CurrentPlayMode: NORMAL/REPEAT_ALL/REPEAT_ONE/SHUFFLE

int libupnp_SetGroupId(NSString  *ControlURL  ,NSString *ServiceTYPE, NSString *GroupId , NSMutableArray *UDN, NSMutableArray *BaseURL, NSMutableArray *GMlist, NSMutableArray *NEWorOLDlist,NSString *Action,NSString *Timestamp);

-(NSArray *)libupnp_GetGroupId:(NSString *)ControlURL ServiceTYPE:(NSString *)ServiceTYPE;

-(NSArray *)libupnp_GetDeviceInfo:(NSString *)ControlURL ServiceTYPE:(NSString *)ServiceTYPE;

-(NSArray *)libupnp_RegistrationDEV:(NSString *)Devinfo VersionCode:(int)VersionCode ClientTypeValue:(NSString *)ClientTypeValue;


int libupnp_SetUpdatePar(NSString *ControlURL,NSString *ServiceTYPE,NSString *Product_Model, NSString *Software_Version, NSString *Md5_Key, NSString *Update_Url);

int libupnp_SetWifiScan(NSString *ControlURL,NSString *ServiceTYPE);

-(NSMutableArray *)libupnp_GetWifiList:(NSString *)ControlURL ServiceTYPE:(NSString *)ServiceTYPE;

int libupnp_SetTransportInfo(NSString *State,NSString *Status,NSString *Speed);

int libupnp_UpnpStart( NSString *MAC_bak,NSString *FriendlyName,int Argc,NSArray *Argv,NSString *Devinfo, int VersionCode);
int libupnp_UpnpStartTest( NSString *MAC_bak,NSString *FriendlyName,int Argc,NSArray *Argv,NSString *Devinfo, int VersionCode);

void libupnp_BuildFilesList();
void libupnp_StopBuildFilesList();


-(void)ipodLibraryURLPlay:(NSString *)exportFileStr;

-(int)getFileSize:(NSString *)filePath;

int AddLocalResource(NSArray *oneSongID3Info);


/*20161208添加得到所有频道的时间戳**/
-(NSMutableDictionary *)libupnp_GetAllChannelTimestamp:(NSString *)ControlURL ServiceTYPE:(NSString *)ServiceTYPE;


/**PlayNumFlag=======x-y代表第几频道第几首歌*/
int libupnp_PlayNumFlag(NSString *ControlURL,
                        NSString *PlayNumFlag,
                        NSString *Timestamp,
                        NSString *UserID,
                        NSString *LocalPlaylistUrl,
                        NSString *IsVIP) ;

/*20170215添加得到所有频道的时间戳**/
-(NSMutableDictionary *)libupnp_GetAllChannelPlayMode:(NSString *)ControlURL ServiceTYPE:(NSString *)ServiceTYPE;



/*20170217添加修改频道顺序**/
int libupnp_ChangeChannelOrder(NSString *ControlURL,NSMutableDictionary *orderList);

int libupnp_SetChannelPlayMode(NSString  *ControlURL, NSString *ChannelFlag, NSString *CurrentPlayMode);


/*20170303添加清空频道**/
int libupnp_SetChannelClear(NSString  *ControlURL, NSString *ChannelFlag,NSString *TimeStamp);
/*20170306添加设置设备闹钟**/
int libupnp_SetAlarm(NSString  *ControlURL,NSMutableDictionary *alarmInfo);

/*20171016添加获得设备某频道M3u列表**/
int libupnp_GetM3uList(NSString *ControlURL,NSString *ChannelNum);

/*20180312修改频道信息通知**/
int libupnp_SetChannelUpdate(NSString  *ControlURL, NSString *UserID,NSString *TimeStamp,NSString *ChannelOrder,NSString *LocalPlaylistUrl);

/*20180928添加设置设备低电量通知命令**/
int libupnp_SetLowBatteryNotification(NSString  *ControlURL,BOOL isNotification);

/*20181023添加设置暂停后多久自动休眠命令**/
int libupnp_SetPauseShutDownTime(NSString  *ControlURL,NSString *ShutDownTime);

/*20181127发送度秘token**/
int libupnp_SetDuerAuthToken(NSString  *ControlURL,NSString *DuerAccessToken,NSString *DuerRefreshToken);

#pragma mark - 2.0


/// 获取播放信息
- (NSDictionary *)libupnp_getPlayInfo:(NSString *)controlUrl;

int libupnp_SetChannelUpdateV2(NSString  *ControlURL,
                               NSString *UserID,
                               NSString *TimeStamp,
                               NSString *ChannelOrder,
                               NSString *LocalPlaylistUrl);

int libupnp_PlayNumFlagV2(NSString *ControlURL,
                          NSString *PlayNumFlag,
                          NSString *Timestamp,
                          NSString *UserID,
                          NSString *LocalPlaylistUrl,
                          NSString *IsVIP) ;

int libupnp_SetAVTransportURIV2(NSString *controlurl,
                              NSString *encodedURL,
                              NSString *title,//歌曲名
                              NSString *artist,//艺人
                              NSString *album,//专辑名
                              NSString *albumArtUri,//专辑封面
                              NSString *duration,//歌曲时长
                              NSString *protocolInfo,//文件类型
                              NSString *upnpclass,
                              NSString *Timestamp,
                              NSString *channelNum,
                              NSString *songOrder,
                              NSString *controlpoint,
                              NSString *songID,
                              NSString *songFrom,//来源类别
                              NSString *songAlbumID);//专辑ID

@end
