| 1 | #include "machdefs.h"
 | 
|---|
| 2 | #include <stdio.h>
 | 
|---|
| 3 | #include <stdlib.h>
 | 
|---|
| 4 | #include <iostream.h>
 | 
|---|
| 5 | #include <math.h>
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #include <typeinfo>
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include <vector>
 | 
|---|
| 10 | #include <string>
 | 
|---|
| 11 | 
 | 
|---|
| 12 | #include "piacmd.h"
 | 
|---|
| 13 | #include "nobjmgr.h"
 | 
|---|
| 14 | #include "pistdimgapp.h"
 | 
|---|
| 15 | 
 | 
|---|
| 16 | 
 | 
|---|
| 17 | //  Exemple de module chargeable ds piapp 
 | 
|---|
| 18 | 
 | 
|---|
| 19 | //  Declaration de la fonction d'activation et de desactivation du module
 | 
|---|
| 20 | extern "C" {
 | 
|---|
| 21 | void exmodule_init();
 | 
|---|
| 22 | void exmodule_end();
 | 
|---|
| 23 | }
 | 
|---|
| 24 | 
 | 
|---|
| 25 | 
 | 
|---|
| 26 | //  Une classe commande-executor, permettant d'enregistrer de 
 | 
|---|
| 27 | //  nouvelles commandes a piapp
 | 
|---|
| 28 | class exmoduleExecutor : public CmdExecutor {
 | 
|---|
| 29 | public:
 | 
|---|
| 30 |                 exmoduleExecutor();
 | 
|---|
| 31 |   virtual       ~exmoduleExecutor();
 | 
|---|
| 32 |   // Execute s'occupe de l'execution effective des commandes
 | 
|---|
| 33 |   virtual int   Execute(string& keyw, vector<string>& args, string& toks);
 | 
|---|
| 34 | };
 | 
|---|
| 35 | 
 | 
|---|
| 36 | /* --Methode-- */
 | 
|---|
| 37 | exmoduleExecutor::exmoduleExecutor()
 | 
|---|
| 38 | {
 | 
|---|
| 39 | 
 | 
|---|
| 40 | PIACmd * mpiac;
 | 
|---|
| 41 | NamedObjMgr omg;
 | 
|---|
| 42 | mpiac = omg.GetImgApp()->CmdInterpreter();
 | 
|---|
| 43 | 
 | 
|---|
| 44 | // On enregistre deux nouvelles commandes 
 | 
|---|
| 45 | string hgrp = "ExModuleCmd";
 | 
|---|
| 46 | // commande excmd1
 | 
|---|
| 47 | string kw = "excmd1";
 | 
|---|
| 48 | string usage = "exmd1: Appel Print pour obj1 \n" ;
 | 
|---|
| 49 | usage += "Usage: excmd1 obj1 ";
 | 
|---|
| 50 | mpiac->RegisterCommand(kw, usage, this, hgrp);
 | 
|---|
| 51 | // commande excmd2
 | 
|---|
| 52 | kw = "excmd2";
 | 
|---|
| 53 | usage = "exmd2: Appel Print pour obj1 et obj2 \n" ;
 | 
|---|
| 54 | usage += "Usage: excmd2 obj1 obj2";
 | 
|---|
| 55 | mpiac->RegisterCommand(kw, usage, this, hgrp);
 | 
|---|
| 56 | 
 | 
|---|
| 57 | }
 | 
|---|
| 58 | 
 | 
|---|
| 59 | /* --Methode-- */
 | 
|---|
| 60 | exmoduleExecutor::~exmoduleExecutor()
 | 
|---|
| 61 | {
 | 
|---|
| 62 | }
 | 
|---|
| 63 | 
 | 
|---|
| 64 | /* --Methode-- */
 | 
|---|
| 65 | int exmoduleExecutor::Execute(string& kw, vector<string>& tokens, string&)
 | 
|---|
| 66 | {
 | 
|---|
| 67 | 
 | 
|---|
| 68 | NamedObjMgr omg;
 | 
|---|
| 69 | if (kw == "excmd1") {
 | 
|---|
| 70 |   if (tokens.size() < 1) {
 | 
|---|
| 71 |     cout << "Usage: excmd1 obj1" << endl;
 | 
|---|
| 72 |     return(0);
 | 
|---|
| 73 |     }
 | 
|---|
| 74 |   omg.PrintObj(tokens[0]);
 | 
|---|
| 75 |   }
 | 
|---|
| 76 | else if (kw == "excmd2") {
 | 
|---|
| 77 |   if (tokens.size() < 2) {
 | 
|---|
| 78 |     cout << "Usage: excmd2 obj1 obj2" << endl;
 | 
|---|
| 79 |     return(0);
 | 
|---|
| 80 |     }
 | 
|---|
| 81 |   omg.PrintObj(tokens[0]);
 | 
|---|
| 82 |   omg.PrintObj(tokens[1]);
 | 
|---|
| 83 |   }
 | 
|---|
| 84 | 
 | 
|---|
| 85 | return(0);
 | 
|---|
| 86 | 
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | static exmoduleExecutor * piaerex = NULL;
 | 
|---|
| 90 | /* Nouvelle-Fonction */
 | 
|---|
| 91 | void exmodule_init()
 | 
|---|
| 92 | {
 | 
|---|
| 93 | // Fonction d'initialisation du module
 | 
|---|
| 94 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
 | 
|---|
| 95 | if (piaerex) delete piaerex;
 | 
|---|
| 96 | piaerex = new exmoduleExecutor;
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | /* Nouvelle-Fonction */
 | 
|---|
| 100 | void exmodule_end()
 | 
|---|
| 101 | {
 | 
|---|
| 102 | // Desactivation du module
 | 
|---|
| 103 | if (piaerex) delete piaerex;
 | 
|---|
| 104 | piaerex = NULL;
 | 
|---|
| 105 | }
 | 
|---|
| 106 | 
 | 
|---|