Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/icuplug.h
38827 views
/*1******************************************************************************2*3* Copyright (C) 2009-2015, International Business Machines4* Corporation and others. All Rights Reserved.5*6******************************************************************************7*8* FILE NAME : icuplug.h9*10* Date Name Description11* 10/29/2009 sl New.12******************************************************************************13*/1415/**16* \file17* \brief C API: ICU Plugin API18*19* <h2>C API: ICU Plugin API</h2>20*21* <p>C API allowing run-time loadable modules that extend or modify ICU functionality.</p>22*23* <h3>Loading and Configuration</h3>24*25* <p>At ICU startup time, the environment variable "ICU_PLUGINS" will be26* queried for a directory name. If it is not set, the preprocessor symbol27* "DEFAULT_ICU_PLUGINS" will be checked for a default value.</p>28*29* <p>Within the above-named directory, the file "icuplugins##.txt" will be30* opened, if present, where ## is the major+minor number of the currently31* running ICU (such as, 44 for ICU 4.4, thus icuplugins44.txt)</p>32*33* <p>The configuration file has this format:</p>34*35* <ul>36* <li>Hash (#) begins a comment line</li>37*38* <li>Non-comment lines have two or three components:39* LIBRARYNAME ENTRYPOINT [ CONFIGURATION .. ]</li>40*41* <li>Tabs or spaces separate the three items.</li>42*43* <li>LIBRARYNAME is the name of a shared library, either a short name if44* it is on the loader path, or a full pathname.</li>45*46* <li>ENTRYPOINT is the short (undecorated) symbol name of the plugin's47* entrypoint, as above.</li>48*49* <li>CONFIGURATION is the entire rest of the line . It's passed as-is to50* the plugin.</li>51* </ul>52*53* <p>An example configuration file is, in its entirety:</p>54*55* \code56* # this is icuplugins44.txt57* testplug.dll myPlugin hello=world58* \endcode59* <p>Plugins are categorized as "high" or "low" level. Low level are those60* which must be run BEFORE high level plugins, and before any operations61* which cause ICU to be 'initialized'. If a plugin is low level but62* causes ICU to allocate memory or become initialized, that plugin is said63* to cause a 'level change'. </p>64*65* <p>At load time, ICU first queries all plugins to determine their level,66* then loads all 'low' plugins first, and then loads all 'high' plugins.67* Plugins are otherwise loaded in the order listed in the configuration file.</p>68*69* <h3>Implementing a Plugin</h3>70* \code71* U_CAPI UPlugTokenReturn U_EXPORT272* myPlugin (UPlugData *plug, UPlugReason reason, UErrorCode *status) {73* if(reason==UPLUG_REASON_QUERY) {74* uplug_setPlugName(plug, "Simple Plugin");75* uplug_setPlugLevel(plug, UPLUG_LEVEL_HIGH);76* } else if(reason==UPLUG_REASON_LOAD) {77* ... Set up some ICU things here....78* } else if(reason==UPLUG_REASON_UNLOAD) {79* ... unload, clean up ...80* }81* return UPLUG_TOKEN;82* }83* \endcode84*85* <p>The UPlugData* is an opaque pointer to the plugin-specific data, and is86* used in all other API calls.</p>87*88* <p>The API contract is:</p>89* <ol><li>The plugin MUST always return UPLUG_TOKEN as a return value- to90* indicate that it is a valid plugin.</li>91*92* <li>When the 'reason' parameter is set to UPLUG_REASON_QUERY, the93* plugin MUST call uplug_setPlugLevel() to indicate whether it is a high94* level or low level plugin.</li>95*96* <li>When the 'reason' parameter is UPLUG_REASON_QUERY, the plugin97* SHOULD call uplug_setPlugName to indicate a human readable plugin name.</li></ol>98*99*100* \internal ICU 4.4 Technology Preview101*/102103104#ifndef ICUPLUG_H105#define ICUPLUG_H106107#include "unicode/utypes.h"108109110#if UCONFIG_ENABLE_PLUGINS111112113114/* === Basic types === */115116#ifndef U_HIDE_INTERNAL_API117/**118* @{119* Opaque structure passed to/from a plugin.120* use the APIs to access it.121* @internal ICU 4.4 Technology Preview122*/123124struct UPlugData;125typedef struct UPlugData UPlugData;126127/** @} */128129/**130* Random Token to identify a valid ICU plugin. Plugins must return this131* from the entrypoint.132* @internal ICU 4.4 Technology Preview133*/134#define UPLUG_TOKEN 0x54762486135136/**137* Max width of names, symbols, and configuration strings138* @internal ICU 4.4 Technology Preview139*/140#define UPLUG_NAME_MAX 100141142143/**144* Return value from a plugin entrypoint.145* Must always be set to UPLUG_TOKEN146* @see UPLUG_TOKEN147* @internal ICU 4.4 Technology Preview148*/149typedef uint32_t UPlugTokenReturn;150151/**152* Reason code for the entrypoint's call153* @internal ICU 4.4 Technology Preview154*/155typedef enum {156UPLUG_REASON_QUERY = 0, /**< The plugin is being queried for info. **/157UPLUG_REASON_LOAD = 1, /**< The plugin is being loaded. **/158UPLUG_REASON_UNLOAD = 2, /**< The plugin is being unloaded. **/159UPLUG_REASON_COUNT /**< count of known reasons **/160} UPlugReason;161162163/**164* Level of plugin loading165* INITIAL: UNKNOWN166* QUERY: INVALID -> { LOW | HIGH }167* ERR -> INVALID168* @internal ICU 4.4 Technology Preview169*/170typedef enum {171UPLUG_LEVEL_INVALID = 0, /**< The plugin is invalid, hasn't called uplug_setLevel, or can't load. **/172UPLUG_LEVEL_UNKNOWN = 1, /**< The plugin is waiting to be installed. **/173UPLUG_LEVEL_LOW = 2, /**< The plugin must be called before u_init completes **/174UPLUG_LEVEL_HIGH = 3, /**< The plugin can run at any time. **/175UPLUG_LEVEL_COUNT /**< count of known reasons **/176} UPlugLevel;177178/**179* Entrypoint for an ICU plugin.180* @param plug the UPlugData handle.181* @param status the plugin's extended status code.182* @return A valid plugin must return UPLUG_TOKEN183* @internal ICU 4.4 Technology Preview184*/185typedef UPlugTokenReturn (U_EXPORT2 UPlugEntrypoint) (186UPlugData *plug,187UPlugReason reason,188UErrorCode *status);189190/* === Needed for Implementing === */191192/**193* Request that this plugin not be unloaded at cleanup time.194* This is appropriate for plugins which cannot be cleaned up.195* @see u_cleanup()196* @param plug plugin197* @param dontUnload set true if this plugin can't be unloaded198* @internal ICU 4.4 Technology Preview199*/200U_INTERNAL void U_EXPORT2201uplug_setPlugNoUnload(UPlugData *plug, UBool dontUnload);202203/**204* Set the level of this plugin.205* @param plug plugin data handle206* @param level the level of this plugin207* @internal ICU 4.4 Technology Preview208*/209U_INTERNAL void U_EXPORT2210uplug_setPlugLevel(UPlugData *plug, UPlugLevel level);211212/**213* Get the level of this plugin.214* @param plug plugin data handle215* @return the level of this plugin216* @internal ICU 4.4 Technology Preview217*/218U_INTERNAL UPlugLevel U_EXPORT2219uplug_getPlugLevel(UPlugData *plug);220221/**222* Get the lowest level of plug which can currently load.223* For example, if UPLUG_LEVEL_LOW is returned, then low level plugins may load224* if UPLUG_LEVEL_HIGH is returned, then only high level plugins may load.225* @return the lowest level of plug which can currently load226* @internal ICU 4.4 Technology Preview227*/228U_INTERNAL UPlugLevel U_EXPORT2229uplug_getCurrentLevel(void);230231232/**233* Get plug load status234* @return The error code of this plugin's load attempt.235* @internal ICU 4.4 Technology Preview236*/237U_INTERNAL UErrorCode U_EXPORT2238uplug_getPlugLoadStatus(UPlugData *plug);239240/**241* Set the human-readable name of this plugin.242* @param plug plugin data handle243* @param name the name of this plugin. The first UPLUG_NAME_MAX characters willi be copied into a new buffer.244* @internal ICU 4.4 Technology Preview245*/246U_INTERNAL void U_EXPORT2247uplug_setPlugName(UPlugData *plug, const char *name);248249/**250* Get the human-readable name of this plugin.251* @param plug plugin data handle252* @return the name of this plugin253* @internal ICU 4.4 Technology Preview254*/255U_INTERNAL const char * U_EXPORT2256uplug_getPlugName(UPlugData *plug);257258/**259* Return the symbol name for this plugin, if known.260* @param plug plugin data handle261* @return the symbol name, or NULL262* @internal ICU 4.4 Technology Preview263*/264U_INTERNAL const char * U_EXPORT2265uplug_getSymbolName(UPlugData *plug);266267/**268* Return the library name for this plugin, if known.269* @param plug plugin data handle270* @param status error code271* @return the library name, or NULL272* @internal ICU 4.4 Technology Preview273*/274U_INTERNAL const char * U_EXPORT2275uplug_getLibraryName(UPlugData *plug, UErrorCode *status);276277/**278* Return the library used for this plugin, if known.279* Plugins could use this to load data out of their280* @param plug plugin data handle281* @return the library, or NULL282* @internal ICU 4.4 Technology Preview283*/284U_INTERNAL void * U_EXPORT2285uplug_getLibrary(UPlugData *plug);286287/**288* Return the plugin-specific context data.289* @param plug plugin data handle290* @return the context, or NULL if not set291* @internal ICU 4.4 Technology Preview292*/293U_INTERNAL void * U_EXPORT2294uplug_getContext(UPlugData *plug);295296/**297* Set the plugin-specific context data.298* @param plug plugin data handle299* @param context new context to set300* @internal ICU 4.4 Technology Preview301*/302U_INTERNAL void U_EXPORT2303uplug_setContext(UPlugData *plug, void *context);304305306/**307* Get the configuration string, if available.308* The string is in the platform default codepage.309* @param plug plugin data handle310* @return configuration string, or else null.311* @internal ICU 4.4 Technology Preview312*/313U_INTERNAL const char * U_EXPORT2314uplug_getConfiguration(UPlugData *plug);315316/**317* Return all currently installed plugins, from newest to oldest318* Usage Example:319* \code320* UPlugData *plug = NULL;321* while(plug=uplug_nextPlug(plug)) {322* ... do something with 'plug' ...323* }324* \endcode325* Not thread safe- do not call while plugs are added or removed.326* @param prior pass in 'NULL' to get the first (most recent) plug,327* otherwise pass the value returned on a prior call to uplug_nextPlug328* @return the next oldest plugin, or NULL if no more.329* @internal ICU 4.4 Technology Preview330*/331U_INTERNAL UPlugData* U_EXPORT2332uplug_nextPlug(UPlugData *prior);333334/**335* Inject a plugin as if it were loaded from a library.336* This is useful for testing plugins.337* Note that it will have a 'NULL' library pointer associated338* with it, and therefore no llibrary will be closed at cleanup time.339* Low level plugins may not be able to load, as ordering can't be enforced.340* @param entrypoint entrypoint to install341* @param config user specified configuration string, if available, or NULL.342* @param status error result343* @return the new UPlugData associated with this plugin, or NULL if error.344* @internal ICU 4.4 Technology Preview345*/346U_INTERNAL UPlugData* U_EXPORT2347uplug_loadPlugFromEntrypoint(UPlugEntrypoint *entrypoint, const char *config, UErrorCode *status);348349350/**351* Inject a plugin from a library, as if the information came from a config file.352* Low level plugins may not be able to load, and ordering can't be enforced.353* @param libName DLL name to load354* @param sym symbol of plugin (UPlugEntrypoint function)355* @param config configuration string, or NULL356* @param status error result357* @return the new UPlugData associated with this plugin, or NULL if error.358* @internal ICU 4.4 Technology Preview359*/360U_INTERNAL UPlugData* U_EXPORT2361uplug_loadPlugFromLibrary(const char *libName, const char *sym, const char *config, UErrorCode *status);362363/**364* Remove a plugin.365* Will request the plugin to be unloaded, and close the library if needed366* @param plug plugin handle to close367* @param status error result368* @internal ICU 4.4 Technology Preview369*/370U_INTERNAL void U_EXPORT2371uplug_removePlug(UPlugData *plug, UErrorCode *status);372#endif /* U_HIDE_INTERNAL_API */373374#endif /* UCONFIG_ENABLE_PLUGINS */375376#endif /* _ICUPLUG */377378379380