Skip to content

Commit

Permalink
fix: rename Component to Identity in order to make CoatySwift macOS c…
Browse files Browse the repository at this point in the history
…ompatible
  • Loading branch information
melloskitten committed Oct 29, 2019
1 parent 9d02133 commit fac20c1
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 61 deletions.
8 changes: 4 additions & 4 deletions CoatySwift/Classes/Common/CoatyObjectFamily.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum CoatyObjectFamily: String, ObjectFamily {
case log = "coaty.Log"
case location = "coaty.Location"
case snapshot = "coaty.Snapshot"
case component = "coaty.Component"
case identity = "coaty.Component"

// Core type matching for dynamic coaty applications.
case core_CoatyObject = "CoatyObject"
Expand All @@ -34,16 +34,16 @@ public enum CoatyObjectFamily: String, ObjectFamily {
case core_IoSource = "IoSource"
case core_IoActor = "IoActor"
case core_Config = "Config"
case core_Component = "Component"
case core_Identity = "Component"
case core_Log = "Log"
case core_Location = "Location"

public func getType() -> AnyObject.Type {
switch self {
case .coatyObject:
return CoatyObject.self
case .component:
return Component.self
case .identity:
return Identity.self
case .snapshot:
// This does _not always_ work properly. Snapshot objects need to be parametrized with the
// object family of the snapshotted objects. The base implementation only allows core objects.
Expand Down
4 changes: 2 additions & 2 deletions CoatySwift/Classes/Communication/Events/AdvertiseEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public class AdvertiseEventFactory<Family: ObjectFamily>: EventFactoryInit {
/// Note that this class should preferably be initialized via its withObject() method.
public class AdvertiseEvent<Family: ObjectFamily>: CommunicationEvent<AdvertiseEventData<Family>> {

override init(eventSource: Component, eventData: AdvertiseEventData<Family>) {
override init(eventSource: Identity, eventData: AdvertiseEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

/// Convenience factory method that configures an instance of an AdvertiseEvent with
/// an object and privateData. Note that the event source should be the controller that
/// creates the AdvertiseEvent.
internal static func withObject(eventSource: Component,
internal static func withObject(eventSource: Identity,
object: CoatyObject,
privateData: [String: Any]? = nil) -> AdvertiseEvent {

Expand Down
4 changes: 2 additions & 2 deletions CoatySwift/Classes/Communication/Events/CallEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public class CallEvent<Family: ObjectFamily>: CommunicationEvent<CallEventData<F
}
}

fileprivate override init(eventSource: Component, eventData: CallEventData<Family>) {
fileprivate override init(eventSource: Identity, eventData: CallEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

fileprivate init(eventSource: Component, eventData: CallEventData<Family>, operation: String) {
fileprivate init(eventSource: Identity, eventData: CallEventData<Family>, operation: String) {

if !CommunicationTopic.isValidEventTypeFilter(filter: operation) {
LogManager.log.warning("\(operation) is not a valid operation name.")
Expand Down
4 changes: 2 additions & 2 deletions CoatySwift/Classes/Communication/Events/ChannelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public class ChannelEvent<Family: ObjectFamily>: CommunicationEvent<ChannelEvent

// MARK: - Initializers.

fileprivate override init(eventSource: Component, eventData: ChannelEventData<Family>) {
fileprivate override init(eventSource: Identity, eventData: ChannelEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

internal init(eventSource: Component, eventData: ChannelEventData<Family>, channelId: String) {
internal init(eventSource: Identity, eventData: ChannelEventData<Family>, channelId: String) {

if !CommunicationTopic.isValidEventTypeFilter(filter: channelId) {
LogManager.log.warning("\(channelId) is not a valid channel identifier.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CommunicationEvent<T: CommunicationEventData>: Codable {
/// Event data that conforms to event type specific CommunicationEventData
public var data: T

public var source: Component?
public var source: Identity?
public var sourceId: CoatyUUID?

/// The associated user id of an inbound event. The value is always nil for
Expand All @@ -27,7 +27,7 @@ public class CommunicationEvent<T: CommunicationEventData>: Codable {

// MARK: - Initializer.

init(eventSource: Component, eventData: T) {
init(eventSource: Identity, eventData: T) {
self.source = eventSource
self.sourceId = eventSource.objectId
self.userId = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CompleteEventFactory<Family: ObjectFamily>: EventFactoryInit {
/// Note that this class should preferably be initialized via its withObject() method.
public class CompleteEvent<Family: ObjectFamily>: CommunicationEvent<CompleteEventData<Family>> {

override init(eventSource: Component, eventData: CompleteEventData<Family>) {
override init(eventSource: Identity, eventData: CompleteEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class DeadvertiseEventFactory<Family: ObjectFamily>: EventFactoryInit {
/// Note that this class should preferably be initialized via its withObjectIds() method.
public class DeadvertiseEvent<Family: ObjectFamily>: CommunicationEvent<DeadvertiseEventData<Family>> {

override init(eventSource: Component, eventData: DeadvertiseEventData<Family>) {
override init(eventSource: Identity, eventData: DeadvertiseEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

/// Convenience factory method that configures an instance of a DeadvertiseEvent with
/// object ids to be deadvertised. Note that the event source should be the controller that
/// creates the DeadvertiseEvent.
internal static func withObjectIds(eventSource: Component,
internal static func withObjectIds(eventSource: Identity,
objectIds: [CoatyUUID]) throws -> DeadvertiseEvent {

let deadvertiseEventData = DeadvertiseEventData<Family>(objectIds: objectIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class DiscoverEvent<Family: ObjectFamily>: CommunicationEvent<DiscoverEve
}
}

override init(eventSource: Component, eventData: DiscoverEventData) {
override init(eventSource: Identity, eventData: DiscoverEventData) {
super.init(eventSource: eventSource, eventData: eventData)
type = .Discover
}
Expand Down
6 changes: 3 additions & 3 deletions CoatySwift/Classes/Communication/Events/EventFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import Foundation

public class EventFactoryInit {
var identity: Component
var identity: Identity

init(_ identity: Component) {
init(_ identity: Identity) {
self.identity = identity
}
}
Expand All @@ -28,7 +28,7 @@ public class EventFactory<Family: ObjectFamily>: EventFactoryInit {
public var CallEvent: CallEventFactory<Family>
public var ReturnEvent: ReturnEventFactory<Family>

override init(_ identity: Component) {
override init(_ identity: Identity) {
self.AdvertiseEvent = AdvertiseEventFactory(identity)
self.DeadvertiseEvent = DeadvertiseEventFactory(identity)
self.ChannelEvent = ChannelEventFactory(identity)
Expand Down
2 changes: 1 addition & 1 deletion CoatySwift/Classes/Communication/Events/QueryEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class QueryEvent<Family: ObjectFamily>: CommunicationEvent<QueryEventData

// MARK: - Initializers.

fileprivate override init(eventSource: Component, eventData: QueryEventData<Family>) {
fileprivate override init(eventSource: Identity, eventData: QueryEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

Expand Down
2 changes: 1 addition & 1 deletion CoatySwift/Classes/Communication/Events/ResolveEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ResolveEvent<Family: ObjectFamily>: CommunicationEvent<ResolveEvent

// MARK: - Initializers.

override init(eventSource: Component, eventData: ResolveEventData<Family>) {
override init(eventSource: Identity, eventData: ResolveEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class RetrieveEvent<Family: ObjectFamily>: CommunicationEvent<RetrieveEve

// MARK: - Initializers.

fileprivate override init(eventSource: Component, eventData: RetrieveEventData<Family>) {
fileprivate override init(eventSource: Identity, eventData: RetrieveEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

Expand Down
2 changes: 1 addition & 1 deletion CoatySwift/Classes/Communication/Events/ReturnEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ReturnEvent<Family: ObjectFamily>: CommunicationEvent<ReturnEventDa

// MARK: - Initializers.

fileprivate override init(eventSource: Component, eventData: ReturnEventData<Family>) {
fileprivate override init(eventSource: Identity, eventData: ReturnEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

Expand Down
2 changes: 1 addition & 1 deletion CoatySwift/Classes/Communication/Events/UpdateEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class UpdateEvent<Family: ObjectFamily>: CommunicationEvent<UpdateEventDa

// MARK: - Initializers.

fileprivate override init(eventSource: Component, eventData: UpdateEventData<Family>) {
fileprivate override init(eventSource: Identity, eventData: UpdateEventData<Family>) {
super.init(eventSource: eventSource, eventData: eventData)
}

Expand Down
16 changes: 8 additions & 8 deletions CoatySwift/Classes/Communication/Manager/CM+Observe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension CommunicationManager {
/// - coreType: observed coreType.
/// - objectType: observed objectType.
private func observeAdvertise<Family: ObjectFamily, T: AdvertiseEvent<Family>>(topic: String,
eventTarget: Component,
eventTarget: Identity,
coreType: CoreType?,
objectType: String?) throws -> Observable<T> {

Expand Down Expand Up @@ -92,7 +92,7 @@ extension CommunicationManager {
/// - eventTarget: eventTarget target for which Advertise events should be emitted.
/// - coreType: coreType core type of objects to be observed.
/// - Returns: An observable emitting the advertise events, that have the given coreType.
public func observeAdvertiseWithCoreType<T: AdvertiseEvent<Family>>(eventTarget: Component,
public func observeAdvertiseWithCoreType<T: AdvertiseEvent<Family>>(eventTarget: Identity,
coreType: CoreType) throws -> Observable<T> {
let topic = try CommunicationTopic.createTopicStringByLevelsForSubscribe(eventType: .Advertise,
eventTypeFilter: coreType.rawValue)
Expand All @@ -107,7 +107,7 @@ extension CommunicationManager {
/// - eventTarget: eventTarget target for which Advertise events should be emitted.
/// - objectType: objectType object type of objects to be observed.
/// - Returns: An observable emitting the advertise events, that have the given objectType.
public func observeAdvertiseWithObjectType<T: AdvertiseEvent<Family>>(eventTarget: Component,
public func observeAdvertiseWithObjectType<T: AdvertiseEvent<Family>>(eventTarget: Identity,
objectType: String) throws -> Observable<T> {
let topic = try CommunicationTopic.createTopicStringByLevelsForSubscribe(eventType: .Advertise,
eventTypeFilter: objectType)
Expand All @@ -129,7 +129,7 @@ extension CommunicationManager {
/// - eventTarget: target for which Channel events should be emitted
/// - channelId: a channel identifier
/// - Returns: a hot observable emitting incoming Channel events.
public func observeChannel<T: ChannelEvent<Family>>(eventTarget: Component,
public func observeChannel<T: ChannelEvent<Family>>(eventTarget: Identity,
channelId: String) throws -> Observable<T> {

if !CommunicationTopic.isValidEventTypeFilter(filter: channelId) {
Expand Down Expand Up @@ -180,7 +180,7 @@ extension CommunicationManager {
/// - Parameters:
/// - eventTarget: target for which Deadvertise events should be emitted
/// - Returns: a hot observable emitting incoming Deadvertise events
public func observeDeadvertise(eventTarget: Component) throws -> Observable<DeadvertiseEvent<Family>> {
public func observeDeadvertise(eventTarget: Identity) throws -> Observable<DeadvertiseEvent<Family>> {
let deadvertiseTopic = try CommunicationTopic.createTopicStringByLevelsForSubscribe(eventType: .Deadvertise)

var observable = client.messages.map(convertToTupleFormat)
Expand Down Expand Up @@ -219,7 +219,7 @@ extension CommunicationManager {
/// - Parameters:
/// - eventTarget: target for which Update events should be emitted.
/// - Returns: a hot observable emitting incoming Update events.
public func observeUpdate<T: UpdateEvent<Family>>(eventTarget: Component) throws -> Observable<T> {
public func observeUpdate<T: UpdateEvent<Family>>(eventTarget: Identity) throws -> Observable<T> {

let updateTopic = try CommunicationTopic.createTopicStringByLevelsForSubscribe(eventType: .Update)

Expand Down Expand Up @@ -265,7 +265,7 @@ extension CommunicationManager {
/// - Parameters:
/// - eventTarget: target for which Discover events should be emitted.
/// - Returns: a hot observable emitting incoming Discover events.
public func observeDiscover<T: DiscoverEvent<Family>>(eventTarget: Component) throws -> Observable<T> {
public func observeDiscover<T: DiscoverEvent<Family>>(eventTarget: Identity) throws -> Observable<T> {
let discoverTopic = try CommunicationTopic.createTopicStringByLevelsForSubscribe(eventType: .Discover)

var observable = client.messages.map(convertToTupleFormat)
Expand Down Expand Up @@ -323,7 +323,7 @@ extension CommunicationManager {
/// - operationId: the name of the operation to be invoked
/// - Returns: a hot observable emitting incoming Call events
/// whose context filter matches the given context
public func observeCall<T: CallEvent<Family>>(eventTarget: Component, operationId: String) throws -> Observable<T> {
public func observeCall<T: CallEvent<Family>>(eventTarget: Identity, operationId: String) throws -> Observable<T> {
if !CommunicationTopic.isValidEventTypeFilter(filter: operationId) {
throw CoatySwiftError.InvalidArgument("\(operationId) is not a valid parameter name.")
}
Expand Down
8 changes: 4 additions & 4 deletions CoatySwift/Classes/Communication/Manager/CM+Publish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension CommunicationManager {
messageToken: CoatyUUID().string)

// Save advertises for Components or Devices.
if advertiseEvent.data.object.coreType == .Component ||
if advertiseEvent.data.object.coreType == .Identity ||
advertiseEvent.data.object.coreType == .Device {

// Add if not existing already in deadvertiseIds.
Expand Down Expand Up @@ -280,7 +280,7 @@ extension CommunicationManager {
/// - event: the complete event that should be sent out.
/// - messageToken: the message token associated with the update-complete
/// request.
internal func publishComplete(identity: Component,
internal func publishComplete(identity: Identity,
event: CompleteEvent<Family>,
messageToken: String) throws {

Expand All @@ -300,7 +300,7 @@ extension CommunicationManager {
/// - event: the resolve event that should be sent out.
/// - messageToken: the message token associated with the discover-resolve
/// request.
internal func publishResolve(identity: Component,
internal func publishResolve(identity: Identity,
event: ResolveEvent<Family>,
messageToken: String) throws {

Expand Down Expand Up @@ -378,7 +378,7 @@ extension CommunicationManager {
/// - event: the return event that should be sent out.
/// - messageToken: the message token associated with the call-return
/// request.
internal func publishReturn(identity: Component,
internal func publishReturn(identity: Identity,
event: ReturnEvent<Family>,
messageToken: String) throws {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CommunicationManager<Family: ObjectFamily> {
private var subscriptions = [String: Int]()

/// Coaty identity object of the communication manager. Initialized through initializeIdentity().
var identity: Component!
var identity: Identity!

/// The operating state of the communication manager.
var operatingState: BehaviorSubject<OperatingState> = BehaviorSubject(value: .initial)
Expand Down Expand Up @@ -81,7 +81,7 @@ public class CommunicationManager<Family: ObjectFamily> {
// MARK: - Setup methods.

func initializeIdentity() {
identity = Component(name: "CommunicationManager")
identity = Identity(name: "CommunicationManager")

// Merge property values from CommunicationOptions.identity option.
if self.communicationOptions.identity != nil {
Expand Down Expand Up @@ -312,7 +312,7 @@ public class CommunicationManager<Family: ObjectFamily> {

try? observeDiscover(eventTarget: identity)
.filter({ (event) -> Bool in
(event.data.isDiscoveringTypes() && event.data.isCoreTypeCompatible(.Component)) ||
(event.data.isDiscoveringTypes() && event.data.isCoreTypeCompatible(.Identity)) ||
(event.data.isDiscoveringObjectId() && event.data.objectId == self.identity.objectId)
})
.subscribe(onNext: { event in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import RxSwift

public class ControllerCommunicationManager<Family: ObjectFamily> {

private var controllerIdentity: Component
private var controllerIdentity: Identity
private var cm: CommunicationManager<Family>
public var identity: Component {
public var identity: Identity {
return self.cm.identity
}

init(identity: Component, communicationManager: CommunicationManager<Family>) {
init(identity: Identity, communicationManager: CommunicationManager<Family>) {
self.controllerIdentity = identity
self.cm = communicationManager
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class CommunicationTopic {
/// See [Communication Protocol - Topic Structure](https://coatyio.github.io/coaty-js/man/communication-protocol/#topic-structure)
/// - Parameters:
/// - eventType: CommunicationEventType (e.g. Advertise)
/// - eventTypeFilter: may either be a core type (e.g. Component) or an object type
/// - eventTypeFilter: may either be a core type (e.g. Identity) or an object type
/// (e.g. org.example.object)
/// - associatedUserId: an optional UUID String, if the parameter is omitted it is replaced
/// with a wildcard.
Expand Down Expand Up @@ -190,7 +190,7 @@ class CommunicationTopic {
/// See [Communication Protocol](https://coatyio.github.io/coaty-js/man/communication-protocol/#topic-structure)
/// - Parameters:
/// - eventType: CommunicationEventType (e.g. Advertise)
/// - eventTypeFilter: may either be a core type (e.g. Component) or an object type
/// - eventTypeFilter: may either be a core type (e.g. Identity) or an object type
/// (e.g. org.example.object)
/// - associatedUserId: an optional UUID String, if the parameter is omitted it is replaced
/// with "-".
Expand All @@ -214,7 +214,7 @@ class CommunicationTopic {
/// See [Communication Protocol](https://coatyio.github.io/coaty-js/man/communication-protocol/#topic-filters)
/// - Parameters:
/// - eventType: CommunicationEventType (e.g. Advertise)
/// - eventTypeFilter: may either be a core type (e.g. Component) or an object type
/// - eventTypeFilter: may either be a core type (e.g. Identity) or an object type
/// (e.g. org.example.object)
/// - associatedUserId: an optional UUID String, if the parameter is omitted it is replaced
/// with a wildcard.
Expand Down
Loading

0 comments on commit fac20c1

Please sign in to comment.