[][src]Macro fm_plugin::register_plugin

macro_rules! register_plugin {
    ($x:ident) => { ... };
}

Sets up the entry point for every FileMaker call into the plug-in. The function then dispatches the calls to the various trait functions you can implement. Impl Plugin for your plugin struct, and then call the macro on it.

Example

use fm_plugin::prelude::*;

struct MyPlugin;

impl Plugin for MyPlugin {
           // ...
}

register_plugin!(MyPlugin);

Macro Contents

 #[no_mangle]
 pub static mut gfmx_ExternCallPtr: *mut fmx_ExternCallStruct = std::ptr::null_mut();

 #[no_mangle]
 unsafe extern "C" fn FMExternCallProc(pb: *mut fmx_ExternCallStruct) {
     // Setup global defined in fmxExtern.h (this will be obsoleted in a later header file)
     gfmx_ExternCallPtr = pb;
     use FMExternCallType::*;

     // Message dispatcher
     match (*pb).whichCall {
         Init => {
             (*pb).result = $x::initialize(
                 (*pb).extnVersion,
                 ApplicationVersion::from((*pb).parm1),
                 (*pb).parm2,
             ) as u64
         }
         Idle => {
             use IdleType::*;
             match IdleType::from((*pb).parm1) {
                 Idle => $x::idle((*pb).parm2),
                 NotIdle => $x::not_idle((*pb).parm2),
                 ScriptPaused => $x::script_paused((*pb).parm2),
                 ScriptRunning => $x::script_running((*pb).parm2),
                 Unsafe => $x::un_safe((*pb).parm2),
             }
         }
         Shutdown => $x::shutdown((*pb).extnVersion),
         AppPrefs => $x::preferences(),
         GetString => $x::get_string(
             (*pb).parm1.into(),
             (*pb).parm2 as u32,
             (*pb).parm3 as u32,
             (*pb).result as *mut u16,
         ),
         SessionShutdown => $x::session_shutdown((*pb).parm2),
         FileShutdown => $x::file_shutdown((*pb).parm2, (*pb).parm3),
     }
 }

 impl PluginInternal<$x> for $x {}

 pub fn execute_filemaker_script<F, S>(
     file_name: F,
     script_name: S,
     control: ScriptControl,
     parameter: Option<Data>,
 ) -> FMError
 where
     F: ToText,
     S: ToText,
 {
     unsafe {
         (*gfmx_ExternCallPtr).execute_filemaker_script(
             file_name,
             script_name,
             control,
             parameter,
         )
     }
 }

 lazy_static! {
     static ref GLOBAL_STATE: RwLock<HashMap<String, String>> = RwLock::new(HashMap::new());
 }

 pub fn store_state(key: &str, value: &str) {
     let mut hmap = GLOBAL_STATE.write().unwrap();
     (*hmap).insert(String::from(key), String::from(value));
 }

 pub fn get_state(key: &str) -> Option<String> {
     let hmap = GLOBAL_STATE.read().unwrap();
     (*hmap).get(key).cloned()
 }