/** * Doesn't return the proper token. */ U_CAPI UPlugTokenReturn U_EXPORT2 myPluginFailToken ( UPlugData *data, UPlugReason reason, UErrorCode *status) { fprintf(stderr,"MyPluginFailToken: data=%p, reason=%s, status=%s\n", (void*)data, udbg_enumName(UDBG_UPlugReason,(int32_t)reason), u_errorName(*status)); if(reason==UPLUG_REASON_QUERY) { uplug_setPlugName(data, "myPluginFailToken Plugin"); uplug_setPlugLevel(data, UPLUG_LEVEL_LOW); } return 0; /* Wrong. */ }
U_CAPI UPlugTokenReturn U_EXPORT2 myPluginHigh ( UPlugData *data, UPlugReason reason, UErrorCode *status) { fprintf(stderr,"MyPluginHigh: data=%p, reason=%s, status=%s\n", (void*)data, udbg_enumName(UDBG_UPlugReason,(int32_t)reason), u_errorName(*status)); if(reason==UPLUG_REASON_QUERY) { uplug_setPlugName(data, "High Plugin"); uplug_setPlugLevel(data, UPLUG_LEVEL_HIGH); } return UPLUG_TOKEN; }
U_CAPI UPlugTokenReturn U_EXPORT2 myPlugin ( UPlugData *data, UPlugReason reason, UErrorCode *status) { /* Just print this for debugging */ fprintf(stderr,"MyPlugin: data=%p, reason=%s, status=%s\n", (void*)data, udbg_enumName(UDBG_UPlugReason,(int32_t)reason), u_errorName(*status)); if(reason==UPLUG_REASON_QUERY) { uplug_setPlugName(data, "Just a Test High-Level Plugin"); /* This call is optional in response to UPLUG_REASON_QUERY, but is a good idea. */ uplug_setPlugLevel(data, UPLUG_LEVEL_HIGH); /* This call is Mandatory in response to UPLUG_REASON_QUERY */ } return UPLUG_TOKEN; /* This must always be returned, to indicate that the entrypoint was actually a plugin. */ }
U_CAPI UPlugTokenReturn U_EXPORT2 coll_provider_plugin (UPlugData *data, UPlugReason reason, UErrorCode *status) { switch(reason) { case UPLUG_REASON_QUERY: uplug_setPlugName(data, "Collation Provider Plugin"); uplug_setPlugLevel(data, UPLUG_LEVEL_HIGH); break; case UPLUG_REASON_LOAD: coll_provider_register(*status); break; case UPLUG_REASON_UNLOAD: coll_provider_unregister(*status); break; default: break; /* not handled */ } return UPLUG_TOKEN; }
U_CAPI UPlugTokenReturn U_EXPORT2 debugMemoryPlugin ( UPlugData *data, UPlugReason reason, UErrorCode *status) { fprintf(stderr,"debugMemoryPlugin: data=%p, reason=%s, status=%s\n", (void*)data, udbg_enumName(UDBG_UPlugReason,(int32_t)reason), u_errorName(*status)); if(reason==UPLUG_REASON_QUERY) { uplug_setPlugLevel(data, UPLUG_LEVEL_LOW); uplug_setPlugName(data, "Memory Plugin"); } else if(reason==UPLUG_REASON_LOAD) { u_setMemoryFunctions(uplug_getContext(data), &myMemAlloc, &myMemRealloc, &myMemFree, status); fprintf(stderr, "MEM: status now %s\n", u_errorName(*status)); } else if(reason==UPLUG_REASON_UNLOAD) { fprintf(stderr, "MEM: not possible to unload this plugin (no way to reset memory functions)...\n"); uplug_setPlugNoUnload(data, TRUE); } return UPLUG_TOKEN; }
/** * Says it's low, but isn't. */ U_CAPI UPlugTokenReturn U_EXPORT2 myPluginBad ( UPlugData *data, UPlugReason reason, UErrorCode *status) { fprintf(stderr,"MyPluginLow: data=%p, reason=%s, status=%s\n", (void*)data, udbg_enumName(UDBG_UPlugReason,(int32_t)reason), u_errorName(*status)); if(reason==UPLUG_REASON_QUERY) { uplug_setPlugName(data, "Bad Plugin"); uplug_setPlugLevel(data, UPLUG_LEVEL_LOW); } else if(reason == UPLUG_REASON_LOAD) { void *ctx = uprv_malloc(12345); uplug_setContext(data, ctx); fprintf(stderr,"I'm %p and I did a bad thing and malloced %p\n", (void*)data, (void*)ctx); } else if(reason == UPLUG_REASON_UNLOAD) { void * ctx = uplug_getContext(data); uprv_free(ctx); } return UPLUG_TOKEN; }