Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
maross committed Nov 6, 2015
2 parents d3b3d76 + d0bf960 commit 06c4b27
Show file tree
Hide file tree
Showing 27 changed files with 879 additions and 636 deletions.
1 change: 0 additions & 1 deletion Classes/Kurento.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
#import "NBMMessage.h"
#import "NBMRequest.h"
#import "NBMResponse.h"
#import "NBMResponseError.h"
3 changes: 2 additions & 1 deletion Classes/NBMJSONRPCClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@protocol NBMJSONRPCClientDelegate <NSObject>

- (void)client:(NBMJSONRPCClient *)client didReceiveRequest:(NBMRequest *)request;
- (void)client:(NBMJSONRPCClient *)client didFailWithError:(NSError *)error;

@end

Expand Down Expand Up @@ -44,6 +45,6 @@
- (void)cancelAllRequest;

//Response (not implemented yet)
- (void)sendResponse:(NBMResponse *)response;
//- (void)sendResponse:(NBMResponse *)response;

@end
8 changes: 6 additions & 2 deletions Classes/NBMJSONRPCClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ - (void)sendRequestPack:(NBMRequestPack *)requestPack retried:(BOOL)retried

- (void)sendRequest:(NBMRequest *)request
{
NSDictionary *requestDictonary = [request toDictionary];
[_transport sendMessage:requestDictonary];
NSString *requestString = [request toJSONString];
[_transport send:requestString];
}

- (void)cancelRequestPack:(NBMRequestPack *)requestPack
Expand Down Expand Up @@ -484,6 +484,10 @@ - (void)channel:(NBMTransportChannel *)channel didReceiveMessage:(NSDictionary *
[self decodeMessage:messageDictionary];
}

- (void)channel:(NBMTransportChannel *)channel didEncounterError:(NSError *)error {
[self.delegate client:self didFailWithError:error];
}

#pragma mark TimeoutableDelegate

- (void)timeoutFired:(id)timeoutable
Expand Down
5 changes: 2 additions & 3 deletions Classes/NBMLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
// Created by Marco Rossi on 20/10/15.
// Copyright © 2015 Telecom Italia S.p.A. All rights reserved.
//

#import <CocoaLumberjack/DDLogMacros.h>
#import "DDLogMacros.h"

#ifdef DEBUG
static const int ddLogLevel = DDLogLevelVerbose;
//Simple log macro
#define DLog(s,...) NSLog((@"[%s] " s),__func__,## __VA_ARGS__);
#else
static const int ddLogLevel = DDLogLevelOff;
static const int ddLogLevel = 0;
//Log only in debug mode
#define DLog(...)
#endif
Expand Down
16 changes: 5 additions & 11 deletions Classes/NBMMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@

#import <Foundation/Foundation.h>

FOUNDATION_EXTERN NSString * const kNBMJSONRPCVersion;
@protocol NBMMessage <NSObject>

@interface NBMMessage : NSObject

@property (nonatomic, copy) NSString *sessionId;

+ (NSString *)version;
- (NSDictionary *)toDictionary;
- (NSString *)JSONString;

// Disallow init and don't add to documentation
//- (id)init __attribute__((unavailable("init is not a supported initializer for this class.")));
- (NSDictionary *)toJSONDictionary;
@optional
- (NSString *)toJSONString;

@end

38 changes: 0 additions & 38 deletions Classes/NBMMessage.m

This file was deleted.

2 changes: 1 addition & 1 deletion Classes/NBMRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import "NBMMessage.h"

@interface NBMRequest : NBMMessage
@interface NBMRequest : NSObject <NBMMessage>

@property (nonatomic, readonly) NSNumber *requestId;
@property (nonatomic, copy, readonly) NSString *method;
Expand Down
7 changes: 6 additions & 1 deletion Classes/NBMRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "NBMRequest+Private.h"

#import "NBMJSONRPCConstants.h"
#import "NBMUtilities.h"

@implementation NBMRequest

Expand Down Expand Up @@ -96,7 +97,7 @@ - (NSString *)debugDescription {

#pragma mark - Message

- (NSDictionary *)toDictionary
- (NSDictionary *)toJSONDictionary
{
NSMutableDictionary *json = [NSMutableDictionary dictionary];
[json setObject:kJsonRpcVersion forKey:kJsonRpcKey];
Expand All @@ -109,4 +110,8 @@ - (NSDictionary *)toDictionary
return [json copy];
}

- (NSString *)toJSONString {
return [NSString nbm_stringFromJSONDictionary:[self toJSONDictionary]];
}

@end
23 changes: 22 additions & 1 deletion Classes/NBMResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "NBMMessage.h"

@class NBMResponseError;
@interface NBMResponse : NBMMessage
@interface NBMResponse : NSObject <NBMMessage>

@property (nonatomic, readonly) id result;
@property (nonatomic, readonly) NBMResponseError *error;
Expand All @@ -22,3 +22,24 @@
responseId:(NSNumber *)responseId;

@end

typedef NS_ENUM(NSInteger, NBMResponseErrorCode) {
NBMResponseErrorInvalidParamCode = -32602,
NBMResponseErrorMethodNotFoundCode = -32601,
NBMResponseErrorInvalidRequestCode = -32600,
NBMResponseErrorParseErrorCode = -32700,
NBMResponseErrorInternalErrorCode = -32603,
NBMResponseErrorServerErrorCode = -32000
};

@interface NBMResponseError : NSObject

@property (nonatomic) NSInteger code;
@property (nonatomic, copy) NSString *message;
@property (nonatomic) id data;

+ (instancetype)responseErrorWithCode:(NBMResponseErrorCode)code
message:(NSString *)message
data:(id)data;

@end
56 changes: 54 additions & 2 deletions Classes/NBMResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,56 @@
//

#import "NBMResponse+Private.h"
#import "NBMResponseError.h"

#import "NBMJSONRPCConstants.h"
#import "NBMUtilities.h"

static NSString* JSONRPCLocalizedErrorMessageForCode(NSInteger code) {
switch(code) {
case NBMResponseErrorParseErrorCode:
return @"Parse Error";
case NBMResponseErrorInvalidRequestCode:
return @"Invalid Request";
case NBMResponseErrorMethodNotFoundCode:
return @"Method Not Found";
case NBMResponseErrorInvalidParamCode:
return @"Invalid Params";
case NBMResponseErrorInternalErrorCode:
return @"Internal Error";
default:
return @"Server Error";
}
}

@implementation NBMResponseError

+ (instancetype)responseErrorWithCode:(NBMResponseErrorCode)code
message:(NSString *)message
data:(id)data
{
NBMResponseError *responseError = [[NBMResponseError alloc] init];
responseError.code = code;
if (!message || message.length == 0) {
message = JSONRPCLocalizedErrorMessageForCode(code);
}
responseError.message = message;
responseError.data = data;

return responseError;
}

- (NSDictionary *)errorDictionary
{
NSMutableDictionary *errorDict = [NSMutableDictionary dictionaryWithCapacity:3];
[errorDict setObject:@(self.code) forKey:kCodeKey];
[errorDict setObject:self.message forKey:kMessageKey];
if (self.data) {
[errorDict setObject:self.data forKey:kDataKey];
}
return errorDict;
}

@end

@implementation NBMResponse

Expand Down Expand Up @@ -77,7 +125,7 @@ - (NSString *)debugDescription {

#pragma mark - Message

- (NSDictionary *)toDictionary
- (NSDictionary *)toJSONDictionary
{
NSMutableDictionary *json = [NSMutableDictionary dictionary];
[json setObject:kJsonRpcVersion forKey:kJsonRpcKey];
Expand All @@ -91,4 +139,8 @@ - (NSDictionary *)toDictionary
return [json copy];
}

- (NSString *)toJSONString {
return [NSString nbm_stringFromJSONDictionary:[self toJSONDictionary]];
}

@end
31 changes: 0 additions & 31 deletions Classes/NBMResponseError.h

This file was deleted.

61 changes: 0 additions & 61 deletions Classes/NBMResponseError.m

This file was deleted.

5 changes: 4 additions & 1 deletion Classes/NBMTransportChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ typedef NS_ENUM(NSInteger, NBMTransportChannelState) {
- (void)channel:(NBMTransportChannel *)channel
didChangeState:(NBMTransportChannelState)channelState;

- (void)channel:(NBMTransportChannel *)channel
didEncounterError:(NSError *)error;

- (void)channel:(NBMTransportChannel *)channel
didReceiveMessage:(NSDictionary *)messageDictionary;

Expand All @@ -38,7 +41,7 @@ didReceiveMessage:(NSDictionary *)messageDictionary;

- (void)open;
- (void)close;
//- (void)send:(NSString *)message;
- (void)send:(NSString *)message;
- (void)sendMessage:(NSDictionary *)messageDictionary;

@end
Loading

0 comments on commit 06c4b27

Please sign in to comment.