Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notification Manager Callback How ?



Hi all,

Hi Matthias ;-)
At 10:05 +0100 10/11/05, Matthias Schmidt wrote:
Larry,

thanks a lot, but how do I do the miracle then.
Do I have to install an EventHandler in the Callback procedure?
The thing I'm working is a 4D Plugin (my fist one).
[snip]

You can have a look to (yes, again ;-)[note for other readers: Matthias and I used to talk on the 4D PluginTalk mailing list]) our ToolboxPack plugin. It has a routine called "tp_GetApplicationEvents". This routine installs a callback that executes a 4D method for some application events (see the demo database, execute the aGetAppliEvents_Install method, do some stuff (bring an app to front, bring 4D to front, launc an app, ...), and look at the log created by the 4D callback.


To do this, I InstallEventHandler for some events. Here is an abstract of the code.


static EventHandlerRef s_applicationEventHandlerRef = 0;

void TrapEvts_InstallRemoveCallback(PA_PluginParameters params)
{
. . . some code . . .
const EventTypeSpec applicationEvents[] =
{
{ kEventClassApplication, kEventAppActivated },
{ kEventClassApplication, kEventAppDeactivated },
// { kEventClassApplication, kEventAppLaunchNotification },
{ kEventClassApplication, kEventAppLaunched },
{ kEventClassApplication, kEventAppTerminated },
{ kEventClassApplication, kEventAppFrontSwitched },
{ kEventClassApplication, kEventAppHidden },
{ kEventClassApplication, kEventAppShown }
};


	if(s_applicationEventHandlerRef == 0)
	{
		err = InstallEventHandler(
			GetApplicationEventTarget(),
			NewEventHandlerUPP(TrapEvts_ApplicationEventHandler),
			GetEventTypeCount(applicationEvents),
			applicationEvents,
			0, // no userData
			&s_applicationEventHandlerRef);
	}
. . . some code . . .
}

TrapEvts_ApplicationEventHandler is a regular CarbonEvent handler:

static pascal OSStatus TrapEvts_ApplicationEventHandler(
				EventHandlerCallRef inCallRef,
				EventRef inEvent,
				void* inUserData)
{
	UInt32		eventClass	= GetEventClass(inEvent);
	UInt32		eventKind	= GetEventKind(inEvent);
	OSStatus	ignoreErr;

	if(eventClass != kEventClassApplication)
	{
#if (TBP_DEBUG_ON)
		TBP_DEBUG("(1) TrapEvts_InstallRemoveCallback modifié ?");
#endif
		return eventNotHandledErr;
	}

	switch(eventKind)
	{
	case kEventAppActivated:
	case kEventAppDeactivated:
	case kEventAppHidden:
	case kEventAppShown:
		ignoreErr = TrapEvts_ApplicationDoCallback(eventKind, 0);
		break;

//	case kEventAppLaunchNotification:
	case kEventAppLaunched:
	case kEventAppTerminated:
	case kEventAppFrontSwitched:
		{
			ProcessSerialNumber		psn;

ignoreErr = GetEventParameter(
inEvent,
kEventParamProcessID,
typeProcessSerialNumber,
NULL,
sizeof(ProcessSerialNumber),
NULL,
&psn);
if(! ignoreErr)
ignoreErr = TrapEvts_ApplicationDoCallback(eventKind, &psn);
}
break;


	default:
#if (TBP_DEBUG_ON)
		TBP_DEBUG("(2) TrapEvts_InstallRemoveCallback modifié ?");
#endif
		break

	} // switch(eventKind)

// We're a 4D plugin. Don't know what 4D does with this, and even if it
// has installed an handler. We always return "not handled", even if an error
// occured, to let 4D handle the stuff if needed.
return eventNotHandledErr;


} /* TrapEvts_EventHandler */

The TrapEvts_ApplicationDoCallback just execute the 4D callback method. Note that there is a trick with this when you're executed as a 4D's plug-in: when you're in a "system" callback/handler, you can't call PA_ExecuteMethod nor can you you execute any 4D code. Well, you can, but it crashes ;-) because the code is executed in a place where 4D has no context for the 4D code to be executed (say, the current 4D process number is 0). If you want to execute 4D code, you must use a sepcial 4D External Process that is freezed/Unfreezed when needed (PA_UnfreezeProcess works from a system callback/handler, it is not 4D code).

Thibaud Arguillere
Osmose Editeur
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.