Skip to content

Commit

Permalink
修改回调方法的命名
Browse files Browse the repository at this point in the history
  • Loading branch information
ET-LINK committed Aug 29, 2019
1 parent b99601b commit e6c34ec
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 65 deletions.
54 changes: 27 additions & 27 deletions EnterAffectiveCloud/Cloud/AffectiveCloudServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AffectiveCloudServices: WebSocketServiceProcotol {
self.delegate?.error(client: self.client, request: nil, error: .unSocketConnected, message: "CSRequestError: Pleace check socket is connected!")
return
}
let requestModel = CSRequestJSONModel()
let requestModel = AffectiveCloudRequestJSONModel()
requestModel.services = CSServicesType.session.rawValue
requestModel.operation = CSSessionOperation.create.rawValue
requestModel.kwargs = CSKwargsJSONModel()
Expand All @@ -87,7 +87,7 @@ class AffectiveCloudServices: WebSocketServiceProcotol {
self.delegate?.error(client: self.client, request: nil, error: .noSession, message: "CSRequestError: The session id is empty, restore failed! Try restart cloud service.")
return
}
let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.session.rawValue
jsonModel.operation = CSSessionOperation.restore.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand All @@ -105,7 +105,7 @@ class AffectiveCloudServices: WebSocketServiceProcotol {
return
}

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.session.rawValue
jsonModel.operation = CSSessionOperation.close.rawValue
if let jsonString = jsonModel.toJSONString() {
Expand Down Expand Up @@ -210,7 +210,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol {
return
}

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.biodata.rawValue
jsonModel.operation = CSBiodataOperation.initial.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand Down Expand Up @@ -259,7 +259,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol {
return
}

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.biodata.rawValue
jsonModel.operation = CSBiodataOperation.subscribe.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand All @@ -285,7 +285,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol {
return
}

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.biodata.rawValue
jsonModel.operation = CSBiodataOperation.unsubscribe.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand All @@ -309,7 +309,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol {
return
}

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.biodata.rawValue
jsonModel.operation = CSBiodataOperation.upload.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand Down Expand Up @@ -362,7 +362,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol {
}

let biodataTypes = self.biodataTypeList(with: options)
let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.biodata.rawValue
jsonModel.operation = CSBiodataOperation.report.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand All @@ -389,7 +389,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol {
return
}

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.affective.rawValue
jsonModel.operation = CSEmotionOperation.start.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand All @@ -415,7 +415,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol {

self.checkEmotionAffectiveIsInitial(subscribeList: services)

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.affective.rawValue
jsonModel.operation = CSEmotionOperation.subscribe.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand Down Expand Up @@ -464,7 +464,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol {
}


let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.affective.rawValue
jsonModel.operation = CSEmotionOperation.unsubscribe.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand Down Expand Up @@ -514,7 +514,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol {

self.checkEmotionAffectiveIsInitial(affectiveList: services)

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.affective.rawValue
jsonModel.operation = CSEmotionOperation.report.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand All @@ -538,7 +538,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol {
return
}

let jsonModel = CSRequestJSONModel()
let jsonModel = AffectiveCloudRequestJSONModel()
jsonModel.services = CSServicesType.affective.rawValue
jsonModel.operation = CSEmotionOperation.finish.rawValue
jsonModel.kwargs = CSKwargsJSONModel()
Expand Down Expand Up @@ -750,7 +750,7 @@ extension AffectiveCloudServices: WebSocketDelegate {
if let unGzipData = try? data.gunzipped() {
let text = String(decoding: unGzipData, as: UTF8.self)
DLog("response data is \(text)")
if let responseModel = CSResponseJSONModel.deserialize(from: text) {
if let responseModel = AffectiveCloudResponseJSONModel.deserialize(from: text) {
if self.handleErrorWithResponse(model: responseModel) { return }
self.handleResponse(with: responseModel)
} else {
Expand All @@ -762,7 +762,7 @@ extension AffectiveCloudServices: WebSocketDelegate {
}

// check response status code, if error return `true`
private func handleErrorWithResponse(model: CSResponseJSONModel) -> Bool {
private func handleErrorWithResponse(model: AffectiveCloudResponseJSONModel) -> Bool {
switch model.code {
case 400:
self.delegate?.error(client: self.client, response: model, error: .requestException, message: "The Request error!!")
Expand All @@ -781,7 +781,7 @@ extension AffectiveCloudServices: WebSocketDelegate {

/// Handle response data
/// you can get data use `CSResponseDelegate` in your code
private func handleResponse(with model: CSResponseJSONModel) {
private func handleResponse(with model: AffectiveCloudResponseJSONModel) {
if let request = model.request {
switch (request.services, request.operation) {
case (CSServicesType.session.rawValue, CSSessionOperation.create.rawValue):
Expand All @@ -790,7 +790,7 @@ extension AffectiveCloudServices: WebSocketDelegate {
self.session_id = id
self.isSessionConnected = true
}
self.delegate?.sessionCreate(client: self.client, response: model)
self.delegate?.sessionCreateAndAuthenticate(client: self.client, response: model)
case (CSServicesType.session.rawValue, CSSessionOperation.restore.rawValue):
self.delegate?.sessionRestore(client: self.client, response: model)
case (CSServicesType.session.rawValue, CSSessionOperation.close.rawValue):
Expand All @@ -800,7 +800,7 @@ extension AffectiveCloudServices: WebSocketDelegate {
let list = biodata.biodataList {
self.appendBiodataInitialList(list: list)
}
self.delegate?.biodataInitial(client: self.client, response: model)
self.delegate?.biodataServicesInit(client: self.client, response: model)
case (CSServicesType.biodata.rawValue, CSBiodataOperation.subscribe.rawValue):
if let data = model.dataModel as? CSBiodataProcessJSONModel {
DLog("log biodata subscribe is \(data)")
Expand All @@ -816,30 +816,30 @@ extension AffectiveCloudServices: WebSocketDelegate {
// self.appendBiodataSubscribeList(list: list)
// }

self.delegate?.biodataSubscribe(client: self.client, response: model)
self.delegate?.biodataServicesSubscribe(client: self.client, response: model)
case (CSServicesType.biodata.rawValue, CSBiodataOperation.unsubscribe.rawValue):
self.delegate?.biodataUnsubscribe(client: self.client, response: model)
self.delegate?.biodataServicesUnsubscribe(client: self.client, response: model)
case (CSServicesType.biodata.rawValue, CSBiodataOperation.upload.rawValue):
self.delegate?.biodataUpload(client: self.client, response: model)
self.delegate?.biodataServicesUpload(client: self.client, response: model)
case (CSServicesType.biodata.rawValue, CSBiodataOperation.report.rawValue):
self.delegate?.biodataReport(client: self.client, response: model)
self.delegate?.biodataServicesReport(client: self.client, response: model)
case (CSServicesType.affective.rawValue, CSEmotionOperation.start.rawValue):
if let dataModel = model.dataModel as? CSResponseDataJSONModel,
let list = dataModel.affectiveList {
self.appendEmotionAffectiveInitialList(list: list)
}
self.delegate?.affectiveStart(client: self.client, response: model)
self.delegate?.affectiveDataStart(client: self.client, response: model)
case (CSServicesType.affective.rawValue, CSEmotionOperation.subscribe.rawValue):
if let dataModel = model.dataModel as? CSAffectiveSubscribeProcessJsonModel {
DLog("affective data is \(dataModel.isNil())")
}
self.delegate?.affectiveSubscribe(client: self.client, response: model)
self.delegate?.affectiveDataSubscribe(client: self.client, response: model)
case (CSServicesType.affective.rawValue, CSEmotionOperation.unsubscribe.rawValue):
self.delegate?.affectiveUnsubscribe(client: self.client, response: model)
self.delegate?.affectiveDataUnsubscribe(client: self.client, response: model)
case (CSServicesType.affective.rawValue, CSEmotionOperation.report.rawValue):
self.delegate?.affectiveReport(client: self.client, response: model)
self.delegate?.affectiveDataReport(client: self.client, response: model)
case (CSServicesType.affective.rawValue, CSEmotionOperation.finish.rawValue):
self.delegate?.affectiveFinish(client: self.client, response: model)
self.delegate?.affectiveDataFinish(client: self.client, response: model)
default:
break
}
Expand Down
6 changes: 3 additions & 3 deletions EnterAffectiveCloud/Cloud/CloudModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import HandyJSON
import SwiftyJSON

//MARK: Request Models
public class CSRequestJSONModel: HandyJSON {
public class AffectiveCloudRequestJSONModel: HandyJSON {
var services: String = ""
var operation: String = ""
var kwargs: CSKwargsJSONModel?
Expand Down Expand Up @@ -87,9 +87,9 @@ class CSKwargsJSONModel: HandyJSON {
}

//MARK: Response Models
public class CSResponseJSONModel: HandyJSON {
public class AffectiveCloudResponseJSONModel: HandyJSON {
public var code: Int = 0
public var request: CSRequestJSONModel?
public var request: AffectiveCloudRequestJSONModel?
private var data: [String: Any]?
var message: String?
public required init() { }
Expand Down
36 changes: 18 additions & 18 deletions EnterAffectiveCloud/Cloud/CloudServicesProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ public protocol AffectiveCloudResponseDelegate: class {
func websocketConnect(client: AffectiveCloudClient)
func websocketDisconnect(client: AffectiveCloudClient)

func sessionCreate(client: AffectiveCloudClient, response: CSResponseJSONModel)
func sessionRestore(client: AffectiveCloudClient, response: CSResponseJSONModel)
func sessionClose(client: AffectiveCloudClient, response: CSResponseJSONModel)

func biodataInitial(client: AffectiveCloudClient, response: CSResponseJSONModel)
func biodataSubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel)
func biodataUnsubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel)
func biodataUpload(client: AffectiveCloudClient, response: CSResponseJSONModel)
func biodataReport(client: AffectiveCloudClient, response: CSResponseJSONModel)

func affectiveStart(client: AffectiveCloudClient, response: CSResponseJSONModel)
func affectiveSubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel)
func affectiveUnsubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel)
func affectiveReport(client: AffectiveCloudClient, response: CSResponseJSONModel)
func affectiveFinish(client: AffectiveCloudClient, response: CSResponseJSONModel)

func error(client: AffectiveCloudClient, response: CSResponseJSONModel?, error: CSResponseError, message: String?)
func error(client: AffectiveCloudClient, request: CSRequestJSONModel?, error: CSRequestError, message: String?)
func sessionCreateAndAuthenticate(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func sessionRestore(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func sessionClose(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)

func biodataServicesInit(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesUpload(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)

func affectiveDataStart(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataFinish(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)

func error(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel?, error: AffectiveCloudResponseError, message: String?)
func error(client: AffectiveCloudClient, request: AffectiveCloudRequestJSONModel?, error: AffectiveCloudRequestError, message: String?)
}

//MARK: websocket services
Expand Down
4 changes: 2 additions & 2 deletions EnterAffectiveCloud/Cloud/CloudType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public enum CSEmotionOperation: String {
case finish
}

public enum CSRequestError: Error {
public enum AffectiveCloudRequestError: Error {
case unSocketConnected
case unStart
case noBiodataService
Expand All @@ -53,7 +53,7 @@ public enum CSRequestError: Error {
case unKnow
}

public enum CSResponseError: Error {
public enum AffectiveCloudResponseError: Error {
case requestException
case notFoundServer
case auth
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,25 @@ func finishAffectiveDataServices(services: AffectiveDataServiceOptions)

~~~swift
// session
func createAndAuthenticateSession(response: affectiveCloudResponseJSONModel)
func restoreSession(response: affectiveCloudResponseJSONModel)
func closeSession(response: affectiveCloudResponseJSONModel)
func sessionCreateAndAuthenticate(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func sessionRestore(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func sessionClose(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)

// bioData
func initBiodataServices(response: affectiveCloudResponseJSONModel)
func subscribeBiodataServices(response: affectiveCloudResponseJSONModel)
func unsubscribeBiodataServices(response: affectiveCloudResponseJSONModel)
func appendBiodata(response: affectiveCloudResponseJSONModel)
func getBiodataReport(response: affectiveCloudResponseJSONModel)
func biodataServicesInit(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesUpload(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func biodataServicesReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)

// affectiveData
func startAffectiveDataServices(response: affectiveCloudResponseJSONModel)
func subscribeAffectiveDataServices(response: affectiveCloudResponseJSONModel)
func unsubscribeAffectiveDataServices(response: affectiveCloudResponseJSONModel)
func getAffectiveDataReport(response: affectiveCloudResponseJSONModel)
func finishAffectiveDataServices(response: affectiveCloudResponseJSONModel)
func affectiveDataStart(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)
func affectiveDataFinish(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel)

// error
func error(response: affectiveCloudResponseJSONModel?, error: affectiveCloudResponseError, message: String?)
func error(request: affectiveCloudRequestJSONModel?, error: affectiveCloudRequestError, message: String?)
func error(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel?, error: AffectiveCloudResponseError, message: String?)
func error(client: AffectiveCloudClient, request: AffectiveCloudRequestJSONModel?, error: AffectiveCloudRequestError, message: String?)
~~~

0 comments on commit e6c34ec

Please sign in to comment.