I have a chunk of code written in C that is pulling data from a device, that code can be viewed Here
I want this code which contains a function called getData to be run as method (called getData) of an Objective-C class rather than just having it run from inside the main() C function as it does now while I test it out. My goal is for this method to populate a public global variable variable or even just an class property with a base64 encoded string and return a status.
Here Is how I'm currently setting this up, but this is also my first time writing both C and Objective-C so to be honest I'm not sure if my approach is correct. First I create an interface(protocol) called GDDriver.h
//GDDriver.h
typedef enum Status : NSInteger {
Success,
Cancelled,
DeviceNotFound,
DeviceError,
UnkownModel,
} Status;
@protocol GWDriver <NSObject>
-(enum Status)getData;
-(void)cancel;
@end
I then have a class which lets call it DriverOne which I'm setting up like this
DriverOne.h
// DriverOne.h
#import <Foundation/Foundation.h>
#import "GWDriver.h"
@interface DriverOne : NSObject <GWDriver>
@end
DriverOne.m
// DriverOne.m
#import "DriverOne.h"
@implementation DriverOne
enum Status getData(char* encodedBuffer, int user)
{
// Copy C code which I showed in the link earlier
// into this method. I will want it to return a status
// and populate a global variable with the data.
}
void cancel()
{
// Cancels and closes driver
// is called from with in getData()
}
@end
I'm aware that the methods are currently written in C syntax here, I'm not sure if that is bad practice or not though at this point. Here is how I intend to call the method.
DriverOne *driver = [[DriverOne alloc] init];
driver.getData();
Am I completely off base here or is this approach correct in what I'm trying to achieve? Thanks for any advice or suggestions.