Difference between revisions of "Idle Call"

From FM Plugin Wikipedia
Jump to: navigation, search
Line 20: Line 20:
  
  
===Step Two - Do_PluginIdle function===
+
===Step Two - FMExternCallProc===
 +
This is the key function that FileMaker calls to initialise, shutdown, get name or perform during idle time.
 +
 
 +
It shouldn't be necessary to edit this function.
 +
 
 +
void FMX_ENTRYPT FMExternCallProc(FMX_ExternCallPtr pb)
 +
{
 +
// Setup global defined in FMxExtern.h
 +
gFMX_ExternCallPtr = pb;
 +
 +
// Message dispatcher
 +
switch (gFMX_ExternCallPtr->whichCall)
 +
{
 +
case kFMXT_Init:
 +
{
 +
// Msg = Parm1 Parm2 Parm3
 +
// kFMXT_Init FMX_Application value App vers unicode c str* [unused]
 +
gFMX_ExternCallPtr->result = Do_PluginInit(gFMX_ExternCallPtr->extnVersion, gFMX_ExternCallPtr->parm1 );
 +
}
 +
break;
 +
 +
case kFMXT_Idle:
 +
{
 +
Do_PluginIdle(gFMX_ExternCallPtr->parm1);
 +
}
 +
break;
 +
 +
case kFMXT_Shutdown:
 +
{
 +
Do_PluginShutdown();
 +
}
 +
break;
 +
 +
case kFMXT_DoAppPreferences:
 +
{
 +
Do_PluginPrefs();
 +
}
 +
break;
 +
 +
case kFMXT_GetString:
 +
{
 +
Do_GetString(gFMX_ExternCallPtr->parm1, gFMX_ExternCallPtr->parm2,
 +
gFMX_ExternCallPtr->parm3, reinterpret_cast<FMX_Unichar*>(gFMX_ExternCallPtr->result));
 +
}
 +
break;
 +
 +
}// switch whichCall
 +
 +
} // FMExternCallProc
 +
 
 +
 
 +
 
 +
 
 +
===Step Three - Do_PluginIdle function===
 
In your main file, you will find the 'Do_PluginIdle' function.
 
In your main file, you will find the 'Do_PluginIdle' function.
  
Line 64: Line 117:
 
  }
 
  }
 
  } // Do_PluginIdle
 
  } // Do_PluginIdle
 +
 +
 +
 +
 +
===Example 1 : Execute queued SQL===
 +
The following example shows how to execute a callback to FileMaker of a queued ExecuteSQL

Revision as of 21:11, 3 April 2012

You can have FileMaker call your plugin during the standard system idle call. During this time, you can execute call backs to FileMaker, including Script and/or SQL callbacks.

NOTE : Be careful that your idle code doesn't take too much time - it's called frequently and any time it takes reduces the overall performance of FileMaker.


Step One - Enable Idle Time Flag

Set the 'Want idle time' flag in the plugin Option String to be 'Y' (the third to last flag)


#define IDMA_Plugin_OptionString		"IDMA1nnYYnn"
//						 ^--^ || | |---- // No Win32s support
//						 |    || |------ // Want idle time 
//						 |    ||-------- // No old external functions
//						 |    |--------- // Has preferences dialog
//						 |-------------- // 'IDMA' plug-in ID



Step Two - FMExternCallProc

This is the key function that FileMaker calls to initialise, shutdown, get name or perform during idle time.

It shouldn't be necessary to edit this function.

void FMX_ENTRYPT FMExternCallProc(FMX_ExternCallPtr pb)
{
	// Setup global defined in FMxExtern.h
	gFMX_ExternCallPtr = pb;

	// Message dispatcher
	switch (gFMX_ExternCallPtr->whichCall) 
	{
		case kFMXT_Init:
		{
			//	Msg	=					Parm1						Parm2							Parm3
			//	kFMXT_Init				FMX_Application value		App vers unicode c str* 		[unused]
			gFMX_ExternCallPtr->result = Do_PluginInit(gFMX_ExternCallPtr->extnVersion, gFMX_ExternCallPtr->parm1 );
		}
		break;
			
		case kFMXT_Idle:
		{
			Do_PluginIdle(gFMX_ExternCallPtr->parm1);
		}
		break;
			
		case kFMXT_Shutdown:
		{
			Do_PluginShutdown();
		}
		break;
			
		case kFMXT_DoAppPreferences:
		{
			Do_PluginPrefs();
		}
		break;

		case kFMXT_GetString:
		{
			Do_GetString(gFMX_ExternCallPtr->parm1, gFMX_ExternCallPtr->parm2,
						 gFMX_ExternCallPtr->parm3, reinterpret_cast<FMX_Unichar*>(gFMX_ExternCallPtr->result));
		}
		break;

	}// switch whichCall

} // FMExternCallProc



Step Three - Do_PluginIdle function

In your main file, you will find the 'Do_PluginIdle' function.


static void Do_PluginIdle(FMX_IdleLevel idleLevel) 
{
	if (pluginIsRunningOnFMPro)          // Only execute if running on client or runtime  (ie. don't call when on server)
	{                                                    // BOOL pluginIsRunningOnFMPro  set during plugin init
		// Check idle state
		switch (idleLevel)
		{
			case kFMXT_UserIdle:
			{
				// The user hasn't done anything for 30 seconds or more.  (mouse movement don't reset this)
			}
			break;
				
 			case kFMXT_UserNotIdle:
			{
				// The user has done something within the last 30 seconds
			}
			break;

			case kFMXT_ScriptPaused:
			{
				// The user is running a script that is paused
			}
			break;

			case kFMXT_ScriptRunning:
			{
				// The user is running a script
			}
			break;
				
			case kFMXT_Unsafe:
			{
				// The plug-in should wait and do nothing at this time.
			}
			break;
		}// switch idleLevel

	}
} // Do_PluginIdle



Example 1 : Execute queued SQL

The following example shows how to execute a callback to FileMaker of a queued ExecuteSQL