Repository URL to install this package:
/********* DEMotifConnector.m Cordova Plugin Implementation *******/
#import <Cordova/CDV.h>
#import "DEMotifConnectorPluginConfiguration.h"
#import <DEMotifConnector/DEServerManagerFactory.h>
#import <DEMotifConnector/IDEServerManagerDelegate.h>
#import <DEMotifConnector/IDEServerResultSuccess.h>
#import <DEMotifConnector/IDEServerResultFailure.h>
#import <DEMotifConnector/IDEServerRequest.h>
#import <DEMotifConnector/IDEServerManager.h>
#pragma mark - DESERVER DELEGATE
@interface DEServerManagerPluginRequestDelegate : NSObject<IDEServerManagerDelegate> {
CDVInvokedUrlCommand* _command;
id<CDVCommandDelegate> _commandDelegate;
}
@end
#pragma mark - DESERVER DELEGATE IMPLEMENTATION
@implementation DEServerManagerPluginRequestDelegate
- (DEServerManagerPluginRequestDelegate*) initWithCommand:(CDVInvokedUrlCommand*)command andCommandDelegate:(id<CDVCommandDelegate>)commandDelegate
{
_command = command;
_commandDelegate = commandDelegate;
return self;
}
- (void)successResult:(id<IDEServerResultSuccess>)serverResult forRequest:(id<IDEServerRequest>)serverRequest
{
CDVPluginResult* pluginResult = nil;
NSDictionary* jsonResponse = [serverResult resultDataAsDictionary];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonResponse];
[_commandDelegate sendPluginResult:pluginResult callbackId:_command.callbackId];
}
- (void)failureResult:(id<IDEServerResultFailure>)serverResult forRequest:(id<IDEServerRequest>)serverRequest
{
CDVPluginResult* pluginResult = nil;
NSError* error = [serverResult serverError];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: error.localizedDescription];
[_commandDelegate sendPluginResult:pluginResult callbackId:_command.callbackId];
}
@end
#pragma mark - PLUGIN IMPLEMENTATION
@interface MotifConnector : CDVPlugin {
// Member variables go here.
}
- (void)serverRequest:(CDVInvokedUrlCommand*)command;
@end
@implementation MotifConnector
- (void)pluginInitialize
{
/* Make a Wrapper around the configuration files */
DEMotifConnectorPluginConfiguration *config = [[DEMotifConnectorPluginConfiguration alloc]initWithCordovaSettings:self.commandDelegate.settings];
[DEServerManagerFactory initWithSharedConfiguration:config];
NSLog(@"MOTIF server address: %@", [config serverAddress]);
}
- (void)serverRequest:(CDVInvokedUrlCommand*)command
{
// Retrieve the json request
NSDictionary* jsonRequest = command.arguments[0];
// Create a request delegate
DEServerManagerPluginRequestDelegate* requestDelegate = [[DEServerManagerPluginRequestDelegate alloc] initWithCommand:command andCommandDelegate:self.commandDelegate];
//Get shared instance
id<IDEServerManager> serverManager = [[DEServerManagerFactory defaultInstance]shared];
// Create a request
id<IDEServerRequest> request = [serverManager buildServerRequestWithDictionary:jsonRequest];
// Send the request
[serverManager executeRequestWithRequest:request delegate:requestDelegate];
}
@end