/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#import "TBaseClient.h"
#import "TApplicationException.h"
#import "TObjective-C.h"

@implementation TBaseClient

- (void) dealloc
{
    [inProtocol release_stub];
    [outProtocol release_stub];
    [super dealloc_stub];
}

- (TApplicationException *)checkIncomingMessageException
{
    int msgType = 0;
    [inProtocol readMessageBeginReturningName: nil type: &msgType sequenceID: NULL];
    if (msgType == TMessageType_EXCEPTION) {
        TApplicationException * x = [TApplicationException read: inProtocol];
        [inProtocol readMessageEnd];
        return x;
    }
    
    return nil;
}

@end
