[missing-sync-ppc-dev-talk] re: Notification of connection

Eric Shapiro eshapiro at markspace.com
Wed Aug 17 06:44:18 PDT 2005


If you register yourself as a plugin with The Missing Sync, you should 
get device connected notifications. If this is not the case, let me 
know.

Specifically, call the routine "connectToMissingSync" as shown below 
from your application. You will then get calls to deviceConnected and 
deviceDisconnected which get passed an NSString with the device name.

You should implement all of the routines in the protocol 
"MSCeAppToPluginProtocol" (in our framework's MSPPCPluginAPIProtocol.h 
file).

There's a non-Cocoa way to do this too using callbacks in 
MSPPCPluginAPI.h.

  -Eric Shapiro

#import <MissingSyncWM/MissingSyncPPC.h>
#import <MissingSyncWM/MSPPCPluginAPIProtocol.h>

@interface MyController : NSObject<MSCeAppToPluginProtocol>
	id<MSCePluginToAppProtocol, NSObject>		mMissingSync;
	NSString *mBundlePath;
@end

@implementation MyController

-(id) init
{
     if ( (self = [super init]) != nil )
     {
		mBundlePath =  [[[NSBundle mainBundle] bundlePath] retain];
     }

     return self;
}

-(void) awakeFromNib
{
   if ( [self connectToMissingSync] )
     NSLog( @"Connected to Missing Sync" );
   else
     NSLog( @"Can not connect to Missing Sync" );
}

/*===============================
	connectToMissingSync	
	
	Initiates a connection with The Missing Sync for Pocket PC application.
===============================*/
-(BOOL) connectToMissingSync
{
	BOOL ok = NO;
	
	if ( mMissingSync )
	{
		[mMissingSync release];
		mMissingSync = nil;
	}
	
	id remoteObject = [NSConnection  
rootProxyForConnectionWithRegisteredName: @kMSCePluginConnectionName 
host: nil];
	if ( remoteObject )
	{
		[remoteObject setProtocolForProxy: 
@protocol(MSCePluginToAppProtocol)];
		mMissingSync = [remoteObject retain];
		
		NS_DURING
			[mMissingSync initialize:mBundlePath target:self];
			ok = YES;
		NS_HANDLER
		NS_ENDHANDLER
	}

	return ok;
}

/*===============================
	disconnectFromMissingSync	
===============================*/
-(void) disconnectFromMissingSync
{
	if ( mMissingSync )
	{
		NS_DURING
			[mMissingSync cleanup:mBundlePath];
			[mMissingSync release];
		NS_HANDLER
		NS_ENDHANDLER
		
		mMissingSync = nil;
	}
}

/*============================================
	deviceConnected
	
	Description:
	Called when a new device is connected. Typically ignored by plugins.
==============================================*/
-(oneway void) deviceConnected:(MSCeDeviceID)deviceID
{
}

/*============================================
	deviceDisconnected
	
	Description:
	Called when a new device is disconnected.
	We'll cancel any in-progress activity.
==============================================*/
-(oneway void) deviceDisconnected:(MSCeDeviceID)deviceID
{
	[self stopSync];
}


/*=============================================
	enableForDevice
	
	Called when the user turns on our plugin.
==============================================*/
-(oneway void) enableForDevice:(MSCeDeviceID)deviceID
{
}

/*=============================================
	disableForDevice
	
	Called when the user turns off our plugin
==============================================*/
-(oneway void) disableForDevice:(MSCeDeviceID)deviceID
{
	[self stopSync];
}

/*=============================================
	missingSyncQuitting
	
	The Missing Sync application is quitting.
==============================================*/
-(oneway void) missingSyncQuitting
{
	[NSApp terminate:self];							// no need to stick around
}

/*=============================================
	lockAvailable
==============================================*/
-(oneway void) lockAvailable:(NSString*)key
{
}

/*=============================================
	showSettingsForDevice
	
	Show our settings dialog.
==============================================*/
-(oneway void) showSettingsForDevice:(MSCeDeviceID)deviceID
{
}

@end

  -Eric

-----------------------------------------------
Eric Shapiro             Mark/Space Engineering
-----------------------------------------------



More information about the missing-sync-ppc-dev-talk mailing list