Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Meder committed Nov 20, 2015
2 parents 58c0d4a + dd333b3 commit adb9f28
Show file tree
Hide file tree
Showing 46 changed files with 2,029 additions and 897 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

`DarkLightning` adheres to [Semantic Versioning](http://semver.org/).

## 0.3.0

### Additions

* Added the `deviceWithSerialNumber:` to JMUSBDeviceManager to obtain a `JMUSBDevice` for a given serial number if the device is attached to the system.
* Added more unit tests
* Added documentation for `JMUSBMuxDecoder` and `JMUSBMuxEncoder`
* Added a state property for `JMUSBDeviceManager`

### Changes

* All internal socket code has been refactored and separated in `JMSocket`, `JMHostSocket`, `JMPathSocket`, `JMNativeSocket`, and `JMSocketConnection` for reuse
* All `stop` and `disconnect` methods return the value `YES` from now on

## 0.2.3

### Bugfixes
Expand Down
9 changes: 5 additions & 4 deletions DarkLightning.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DarkLightning"
s.version = "0.2.3"
s.version = "0.3.0"
s.summary = "Simply the fastest way to transmit data between iOS and OSX"
s.description = <<-DESC
DarkLightning is a lightweight Objective-C library to allow data transmission between iOS devices (Lightning port or Dock connector) and OSX (USB) at 480MBit.
Expand All @@ -17,18 +17,19 @@ Pod::Spec.new do |s|

s.subspec "OSX" do |sp|

sp.source_files = 'Source/OSX/**/*{h,m,c}'
sp.source_files = 'Source/OSX/**/*{h,m,c}','Source/Internal/**/*{h,m,c}'
sp.platform = :osx, '10.9'
sp.private_header_files = "Source/OSX/Internal/**/*.h"
sp.private_header_files = "Source/Internal/**/*.h"

sp.dependency 'DarkLightning/PacketProtocol'

end

s.subspec "iOS" do |sp|

sp.source_files = 'Source/iOS/**/*{h,m,c}'
sp.source_files = 'Source/iOS/**/*{h,m,c}','Source/Internal/**/*{h,m,c}'
sp.platform = :ios, '8.0'
sp.private_header_files = "Source/Internal/**/*.h"

sp.dependency 'DarkLightning/PacketProtocol'

Expand Down
308 changes: 209 additions & 99 deletions DarkLightning.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions DarkLightning.xcworkspace/contents.xcworkspacedata

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions Example/OSX/Root/JMConcreteRootViewModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ -(BOOL)sendMessage:(NSString *)message

#pragma mark - Device Manager Delegate

-(void)deviceManager:(JMUSBDeviceManager *)manager deviceDidChangeState:(JMUSBDeviceManagerState)state
{

}

-(void)deviceManager:(JMUSBDeviceManager *)manager deviceDidAttach:(JMUSBDevice *)device
{
if (!_deviceConnection)
Expand Down
55 changes: 55 additions & 0 deletions Source/Internal/Sockets/JMHostSocket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Jens Meder
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import "JMSocket.h"

/**
* Represents a socket to a given host.
*/
@interface JMHostSocket : NSObject<JMSocket>

/**
* The port to which the socket is bound to.
*/
@property (readonly) uint32_t port;

/**
* The host to which the socket is bound to.
*/
@property (nonnull, nonatomic, strong, readonly) NSString* host;

///---------------------
/// @name Initialization
///---------------------

/**
* Initializes and returns a newly
*
* @param host The host to which the socket should be bound to.
* @param port The port to which the socket should be bound to.
*
* @return A newly initialized socket if the given host and port are valid, nil otherwise.
*/
-(nullable instancetype)initWithHost:(nonnull NSString*)host andPort:(uint32_t)port;

@end
102 changes: 102 additions & 0 deletions Source/Internal/Sockets/JMHostSocket.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Jens Meder
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import "JMHostSocket.h"

@implementation JMHostSocket

@synthesize inputStream = _inputStream;
@synthesize outputStream = _outputStream;
@synthesize state = _state;

-(instancetype)initWithHost:(NSString *)host andPort:(uint32_t)port
{
if (!host || !host.length)
{
return nil;
}

self = [super init];

if (self)
{
_host = host;
_port = port;
}

return self;
}

-(BOOL)connect
{
if (self.state != JMSocketStateDisconnected)
{
return NO;
}

self.state = JMSocketStateConnecting;

CFReadStreamRef readStream;
CFWriteStreamRef writeStream;

CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef) self.host, self.port, &readStream, &writeStream);

_inputStream = (__bridge NSInputStream *)(readStream);
_outputStream = (__bridge NSOutputStream *)(writeStream);

self.state = JMSocketStateConnected;

return YES;
}

-(BOOL)disconnect
{
if (self.state == JMSocketStateDisconnected)
{
return YES;
}

self.state = JMSocketStateDisconnected;

[_inputStream close];
[_outputStream close];

_inputStream = nil;
_outputStream = nil;

return YES;
}

#pragma mark - Properties

-(void) setState:(JMSocketState)state
{
if (state == _state)
{
return;
}

_state = state;
}

@end
52 changes: 52 additions & 0 deletions Source/Internal/Sockets/JMNativeSocket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Jens Meder
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import "JMSocket.h"


/**
* Represents a socket to a native socket.
*/
@interface JMNativeSocket : NSObject<JMSocket>

/**
* The native socket to which the socket is bound to.
*/
@property (readonly) CFSocketNativeHandle nativeSocket;

///---------------------
/// @name Initialization
///---------------------

/**
* Initializes a socket with the given native socket.
*
* @param nativeSocket The native socket to which the socket is bound to.
*
* @return A newly initialized socket if the given native socket is valid, nil otherwise.
*/
-(instancetype)initWithNativeSocket:(CFSocketNativeHandle)nativeSocket;

@end
105 changes: 105 additions & 0 deletions Source/Internal/Sockets/JMNativeSocket.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Jens Meder
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import "JMNativeSocket.h"

@implementation JMNativeSocket

@synthesize inputStream = _inputStream;
@synthesize outputStream = _outputStream;
@synthesize state = _state;

-(instancetype)initWithNativeSocket:(CFSocketNativeHandle)nativeSocket
{
if (nativeSocket < 0)
{
return nil;
}

self = [super init];

if (self)
{
_nativeSocket = nativeSocket;
}

return self;
}

-(BOOL)connect
{
if (self.state != JMSocketStateDisconnected)
{
return NO;
}

self.state = JMSocketStateConnecting;

CFReadStreamRef readStream;
CFWriteStreamRef writeStream;

CFStreamCreatePairWithSocket(kCFAllocatorDefault, _nativeSocket, &readStream, &writeStream);

CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

_inputStream = (__bridge NSInputStream *)(readStream);
_outputStream = (__bridge NSOutputStream *)(writeStream);

self.state = JMSocketStateConnected;

return YES;
}

-(BOOL)disconnect
{
if (self.state == JMSocketStateDisconnected)
{
return YES;
}

self.state = JMSocketStateDisconnected;

[_inputStream close];
[_outputStream close];

_inputStream = nil;
_outputStream = nil;

return YES;
}

#pragma mark - Properties

-(void) setState:(JMSocketState)state
{
if (state == _state)
{
return;
}

_state = state;
}


@end
Loading

0 comments on commit adb9f28

Please sign in to comment.