L'implementation de plugin est la suite d'un projet d'eleve realise en Juin 2000 par GEORGE Lise, HOURS Simon, FERLICOT Frédérici et DEURVEILHER Gilles.
A partir de la version 3.6.9, mMosaic est capable de charger dynamiquement du code executable. Le developpement de plugin est relativement facile, il faut cependant une bonne connaissance de Motif. La methode est assez similaire a celle des plugins netscape en plus simple... mMosaic se base sur le marqueur <OBJECT> du w3c
<OBJECT classid=helloworld width=80 height=20> </OBJECT>classid.so est le nom de l'executable qui sera charge dynamiquement par mMosaic. L'executable sera copie dans /usr/local/mMosaic/plugins/helloworld.so. Creer le fichier helloworld.c. Compiler-le de la maniere suivante:
cc -KPIC -G -I/usr/local/mMosaic/include -o helloworld.so helloworld.c (pour Solaris)ou
cc -fpic -shared -I/usr/local/mMosaic/include -o helloworld.so helloworld.c (pour Linux)Copier ce fichier dans le repertoire de plugin de mMosaic:
cp helloworld.so /usr/local/mMosaic/helloworld.so chmod 755 /usr/local/mMosaic/helloworld.so
int MPP_Initialize(HtmlObjectStruct * obs)
{
if (obs->mp_class->release < MP_PLUGIN_RELEASE )
/* ou afficher un message de chargement */
return 0;
if( obs->width == 0 || obs->height == 0) {
/* en positionnant width et height, il y aura creation
* de fenetre ; sinon le plugin est 'externe' */
obs->width=100; /* en pixel */
obs->height = 20;
}
/* dans le cas ou le tag DATA est present, ne rien faire*/
obs->load_data_method = MPP_URI_TO_AS_IS;
return 1;
}
void MPP_New(HtmlObjectStruct *obs)
{
Widget mosaic_rowcol;
Arg args[10];
Widget label_frame;
int i;
/* la widget mMosaic est de type RowColumn */
mosaic_rowcol=(Widget)(obs->frame); /* XmRowColumn */
/* On cree une widget label pour y mettre hello world */
i=0;
XtSetArg(args[i], XmNwidth, obs->width); i++;
XtSetArg(args[i], XmNheight, obs->height); i++;
XtSetArg(args[i], XmNborderWidth, 0); i++;
XtSetArg(args[i], XmNrecomputeSize, 0); i++;
XtSetArg(args[i], XmNalignment, XmALIGNMENT_CENTER); i++;
label_frame=XmCreateLabel(mosaic_rowcol,"Hello World", args, i);
/* mMosaic laisse la fenetre non-mapper.
* c'est au plugin de le faire
*/
XtSetMappedWhenManaged(label_frame,True);
XtSetMappedWhenManaged(mosaic_rowcol,True);
XtManageChild(mosaic_rowcol);
XtRealizeWidget(mosaic_rowcol); /* au cas ou... */
/* memoriser les donnees du plugin pour cet objet */
obs->plugin_data=(void*)label_frame;
}
void MPP_Destroy(HtmlObjectStruct *)
void MPP_Destroy(HtmlObjectStruct *p)
{
Widget label_frame;
label_frame=(Widget) p->plugin_data;
XtDestroyWidget(label_frame);
}
dans le cas present la fonction peut etre vide. mMosaic detruitra sa fenetre et
par consequent toutes les filles.
La structure ObjectParamStruct est envoyee a chaque appel de fonction du plugin. Il y a une structure par instance d'OBJECT. La structure MosaicPlugjectClassRec decrit une classe d'objet. Il 'y a qu'UNE SEULE COPIE pour toutes les instances de la meme 'classid'.
typedef struct _MosaicPlugjectClassRec
{
int release; /* release of mmosaic plugin */
int i_cid; /* internal id , internal use*/
char * class_id; /* name of plugin */
char * bin_path; /* abs path to binary */
char * codebase; /* url to codebase */
void * dl_handle; /* return by dlsym, internal use*/
MPPInitializeProc MPP_Initialize; /* pointer to Initialize func */
MPPNewProc MPP_New; /* pointer to MPP_New */
MPPDestroyProc MPP_Destroy; /* pointer to MPP_Destroy */
void *plugin_ext; /* if needed by plugin */
void *ext; /* futur use */
} MosaicPlugjectClassRec, * MosaicPlugjectClass;
typedef struct _HtmlObjectStruct {
int x; /* read only */
int y; /* read only */
int width; /* read/write */
int height; /* read/write */
int border_width; /* read only */
int valignment; /* read only */
char * class_id; /* name of ... */
char * bin_path; /* classidPtr donne le bin_path */
char *content_type;
char *codebase;
char *data_url;
MPPLoadDataMethod load_data_method; /*read/write */
char * fname_for_data; /* in case of MPP_URI_TO_FILE */
int param_count; /* number of params */
ObjectParamPtr *param_t; /* table of params */
int cw_only; /* Boolean */
void * frame; /* XtWidget frame, xmRowColumn */
MosaicPlugjectClass mp_class; /* point to an uniq class rec */
int i_oid; /* internal id */
struct _HtmlObjectStruct *mp_rec;
void *plugin_data;
} HtmlObjectStruct;
typedef enum {
MPP_URI_TO_FILE=1,
MPP_URI_TO_FD,
MPP_URI_TO_AURI,
MPP_URI_TO_AS_IS
} MPPLoadDataMethod ;
typedef struct _ObjectParamStruct {
char *name;
char *value;
char *valuetype;
} ObjectParamStruct, *ObjectParamPtr;
Dans le repertoire plugins/examples, vous trouverez d'autre exemples de plugin.