Creating the SUP101CallbackHandler File

Goal: Configure the SUP101CallBackHandler file.

There are two threads involved in the SUP101 application—the main thread, which is driven by the client application user interface controller, and the mobile object client access thread, which takes charge of message transportation with the server and synchronization with the application through the mobile object.

  1. In the SUP101 Xcode project, select File > New File.
  2. Select Objective-C Class and click Next.
  3. In File Name, enter SUP101CallbackHandler, select the Also create SUP101CallbackHandler.h option, and click Finish.
  4. In the new SUP101CallbackHandler.h file, enter the code for the callback handler. For example:
    #import "SUPDefaultCallbackHandler.h"
    
    @interface SUP101CallbackHandler:SUPDefaultCallbackHandler
    {
        SUPInt field_importCount;
        SUPInt field_replaySuccessCount;
        SUPInt field_replayFailureCount;
        SUPInt field_searchSuccessCount;
        SUPInt field_searchFailureCount;
        SUPInt field_loginSuccessCount;
        SUPInt field_importSuccessCount;
    }
    
    + (SUP101CallbackHandler*)newInstance;
    - (SUPInt)importCount;
    - (void)setImportCount:(SUPInt)_importCount;
    @property(assign) SUPInt importCount;
    - (SUPInt)replaySuccessCount;
    - (void)setReplaySuccessCount:(SUPInt)_replaySuccessCount;
    @property(assign) SUPInt replaySuccessCount;
    - (SUPInt)replayFailureCount;
    - (void)setReplayFailureCount:(SUPInt)_replayFailureCount;
    @property(assign) SUPInt replayFailureCount;
    - (SUPInt)searchSuccessCount;
    - (void)setSearchSuccessCount:(SUPInt)_searchSuccessCount;
    @property(assign) SUPInt searchSuccessCount;
    - (SUPInt)searchFailureCount;
    - (void)setSearchFailureCount:(SUPInt)_searchFailureCount;
    @property(assign) SUPInt searchFailureCount;
    - (SUPInt)loginSuccessCount;
    - (void)setLoginSuccessCount:(SUPInt)_loginSuccessCount;
    @property(assign) SUPInt loginSuccessCount;
    - (SUPInt)importSuccessCount;
    - (void)setImportSuccessCount:(SUPInt)_importSuccessCount;
    @property(assign) SUPInt importSuccessCount;
    - (void)onImport:(id)theObject;
    - (void)onReplayFailure:(id)theObject;
    - (void)onReplaySuccess:(id)theObject;
    - (void)onSearchFailure:(id)theObject;
    - (void)onSearchSuccess:(id)theObject;
    - (void)onLoginSuccess;
    - (void)onSubscribeSuccess;
    - (void)onUnsubscribeSuccess;
    - (void)onImportSuccess;
    - (void)dealloc;
    
    @end
    
  5. In the new SUP101CallbackHandler.m file, enter the code for the callback handler. For example:
    #import "SUP101CallbackHandler.h"
    
    @implementation SUP101CallbackHandler
    
    + (SUP101CallbackHandler*)newInstance
    {
        SUP101CallbackHandler* _me_1 = [[SUP101CallbackHandler alloc] init];
        [_me_1 autorelease];
        return _me_1;
    }
    
    - (SUPInt)importCount
    {
        return field_importCount;
    }
    
    - (void)setImportCount:(SUPInt)_importCount
    {
        field_importCount = _importCount;
    }
    
    - (SUPInt)replaySuccessCount
    {
        return field_replaySuccessCount;
    }
    
    - (void)setReplaySuccessCount:(SUPInt)_replaySuccessCount
    {
        field_replaySuccessCount = _replaySuccessCount;
    }
    
    - (SUPInt)replayFailureCount
    {
        return field_replayFailureCount;
    }
    
    - (void)setReplayFailureCount:(SUPInt)_replayFailureCount
    {
        field_replayFailureCount = _replayFailureCount;
    }
    
    - (SUPInt)searchSuccessCount
    {
        return field_searchSuccessCount;
    }
    
    - (void)setSearchSuccessCount:(SUPInt)_searchSuccessCount
    {
        field_searchSuccessCount = _searchSuccessCount;
    }
    
    - (SUPInt)searchFailureCount
    {
        return field_searchFailureCount;
    }
    
    - (void)setSearchFailureCount:(SUPInt)_searchFailureCount
    {
        field_searchFailureCount = _searchFailureCount;
    }
    
    - (SUPInt)loginSuccessCount
    {
        return field_loginSuccessCount;
    }
    
    - (void)setLoginSuccessCount:(SUPInt)_loginSuccessCount
    {
        field_loginSuccessCount = _loginSuccessCount;
    }
    - (SUPInt)importSuccessCount
    {
        return field_importSuccessCount;
    }
    
    - (void)setImportSuccessCount:(SUPInt)_importSuccessCount
    {
        field_importSuccessCount = _importSuccessCount;
    }
    - (void)onImport:(id)theObject
    {
        self.importCount = self.importCount + 1;
    }
    
    - (void)onReplayFailure:(id)theObject
    {
        self.replayFailureCount = self.replayFailureCount + 1;
    }
    
    - (void)onReplaySuccess:(id)theObject
    {
        self.replaySuccessCount = self.replaySuccessCount + 1;
        
        MBOLogInfo(@"================================================");
        MBOLogInfo(@"Replay Successful");
        MBOLogInfo(@"=================================================");
    
    }
    
    - (void)onSearchFailure:(id)theObject
    {
        self.searchFailureCount = self.searchFailureCount + 1;
    }
    
    - (void)onSearchSuccess:(id)theObject
    {
        self.searchSuccessCount = self.searchSuccessCount + 1;
    }
    
    - (void)onLoginSuccess
    {
        MBOLogInfo(@"================================================");
        MBOLogInfo(@"Login Successful");
        MBOLogInfo(@"=================================================");
        self.loginSuccessCount++;
    }
    - (void)onSubscribeSuccess
    {
        MBOLogInfo(@"================================================");
        MBOLogInfo(@"Subscribe Successful");
        MBOLogInfo(@"=================================================");
        
    }
    
    - (void)onUnsubscribeSuccess
    {
        MBOLogInfo(@"================================================");
        MBOLogInfo(@"Unsubscribe Successful");
        MBOLogInfo(@"=================================================");
        
    }
    - (void)onImportSuccess
    {
        MBOLogInfo(@"================================================");
        MBOLogInfo(@"import ends Successful");
        MBOLogInfo(@"=================================================");
        self.importSuccessCount++;
    }
    
    - (void)dealloc
    {
        [super dealloc];
    }
    
    @end
    
  6. Save the SUP101CallbackHandler.m and SUP101CallbackHandler.h files.