Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | #import "TMultiplexedProtocol.h" |
| 21 | |
| 22 | #import "TProtocol.h" |
Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 23 | |
Jens Geyer | 56e5b9b | 2015-10-09 22:01:55 +0200 | [diff] [blame] | 24 | NSString *TMultiplexedProtocolSeperator = @":"; |
| 25 | |
| 26 | |
| 27 | @interface TMultiplexedProtocol () |
| 28 | |
| 29 | @property(strong, nonatomic) NSString *serviceName; |
| 30 | |
| 31 | @end |
| 32 | |
Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 33 | |
| 34 | @implementation TMultiplexedProtocol |
| 35 | |
Jens Geyer | 56e5b9b | 2015-10-09 22:01:55 +0200 | [diff] [blame] | 36 | -(id) initWithProtocol:(id <TProtocol>)protocol |
| 37 | serviceName:(NSString *)name |
Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 38 | { |
Jens Geyer | 56e5b9b | 2015-10-09 22:01:55 +0200 | [diff] [blame] | 39 | self = [super initWithProtocol:protocol]; |
| 40 | if (self) { |
| 41 | _serviceName = name; |
| 42 | } |
| 43 | return self; |
Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 44 | } |
| 45 | |
Jens Geyer | 56e5b9b | 2015-10-09 22:01:55 +0200 | [diff] [blame] | 46 | -(BOOL) writeMessageBeginWithName:(NSString *)name |
| 47 | type:(SInt32)messageType |
| 48 | sequenceID:(SInt32)sequenceID |
| 49 | error:(NSError *__autoreleasing *)error |
Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 50 | { |
Jens Geyer | 56e5b9b | 2015-10-09 22:01:55 +0200 | [diff] [blame] | 51 | switch (messageType) { |
| 52 | case TMessageTypeCALL: |
| 53 | case TMessageTypeONEWAY: { |
| 54 | NSMutableString *serviceFunction = [[NSMutableString alloc] initWithString:_serviceName]; |
| 55 | [serviceFunction appendString:TMultiplexedProtocolSeperator]; |
| 56 | [serviceFunction appendString:name]; |
| 57 | return [super writeMessageBeginWithName:serviceFunction type:messageType sequenceID:sequenceID error:error]; |
| 58 | } |
| 59 | break; |
Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 60 | |
Jens Geyer | 56e5b9b | 2015-10-09 22:01:55 +0200 | [diff] [blame] | 61 | default: |
| 62 | return [super writeMessageBeginWithName:name type:messageType sequenceID:sequenceID error:error]; |
| 63 | } |
Jens Geyer | aa99e0e | 2014-09-29 22:09:15 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @end |