Salome HOME
Merge branch 'omu/SalomeLauncher'
[modules/kernel.git] / idl / SALOME_Component.idl
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SALOME_Component.idl
23 //  Author : Paul RASCLE, EDF
24
25 #ifndef _SALOME_COMPONENT_IDL_
26 #define _SALOME_COMPONENT_IDL_
27
28 #include "SALOME_GenericObj.idl"
29 #include "SALOMEDS.idl"
30 #include "SALOME_Exception.idl"
31 #include "SALOME_PyNode.idl"
32
33 /*! \file SALOME_Component.idl \brief interfaces for EngineComponent and Container
34 */
35
36 /*! \brief
37 This is a package of interfaces used for connecting new components to %SALOME
38 application. It also contains a set of interfaces used for management of %MED
39 component in %SALOME application.
40 */
41 module Engines
42 {
43   /*! 
44     A byte stream which is used for binary data transfer between different
45     components
46   */
47   typedef sequence<octet> TMPFile;  
48   
49   //!  General Key Value Structure to set or get properties, for component
50   struct KeyValuePair
51   {
52     string key;
53     any value;
54   };
55
56   //!  Structure data type to hold reference on data 
57   struct dataref
58   {
59     string ref;
60   };
61
62   typedef sequence<KeyValuePair> FieldsDict;
63   typedef sequence<string> ListOfOptions;
64   typedef sequence<string> ListOfIdentifiers;
65
66   interface EngineComponent ;
67   interface fileRef ;
68   interface fileTransfer ;
69   interface Salome_file;
70   interface DataContainer;
71
72   typedef sequence<DataContainer> ListOfData;
73   
74   /*! \brief Interface of the %Container.
75   This interface defines the process of loading and registration
76   of new components in %SALOME application
77   */
78
79   interface Container
80   {
81
82     /*! \brief Loads a new component class (dynamic library).
83
84       \param componentName like COMPONENT, (Python or C++ implementation)
85                            try to make a Python import of COMPONENT,
86                            then a lib open of libCOMPONENTEngine.so
87       \param reason      in case of error (return false) a string explaining the error
88       \return true if load successfull or already done, false otherwise
89     */
90     boolean load_component_Library(in string componentName, out string reason);
91
92     //! Create a new servant instance of a component.
93     /*!
94       Component library must be loaded.
95       \param componentName Name of the component which will be registered
96                            in Registry and Name Service,
97                          (instance number suffix added to the registered name)
98       \param studyId        0 if instance is not associated to a study, 
99                             >0 otherwise (== study id)
100       \return a loaded component
101     */
102     Engines::EngineComponent create_component_instance(in string componentName,
103                                                        in long studyId);
104
105     //! Create a new servant instance of a component with environment variables specified.
106     /*!
107       Component library must be loaded.
108       \param componentName Name of the component which will be registered
109                            in Registry and Name Service,
110                          (instance number suffix added to the registered name)
111       \param studyId        0 if instance is not associated to a study, 
112                             >0 otherwise (== study id)
113       \param env         a dict of env variables
114       \param reason      in case of error (return nil) a string explaining the error
115       \return a loaded component
116     */
117     Engines::EngineComponent create_component_instance_env(in string componentName,
118                                                            in long studyId, in FieldsDict env,
119                                                            out string reason);
120     //! Find a servant instance of a component
121     /*!
122       \param registeredName  Name of the component in Registry or Name Service,
123                              without instance suffix number
124       \param studyId        0 if instance is not associated to a study, 
125                             >0 otherwise (== study id)
126       \return the first instance found with same studyId
127     */
128     EngineComponent find_component_instance(in string registeredName,
129                                             in long studyId);
130
131     //! Find a servant instance of a component, or create a new one.
132     /*!
133       Loads the component library if needed.
134       Only applicable to multiStudy components.
135       \param nameToRegister Name of the component which will be registered
136                             in Registry (or Name Service)
137       \param componentName  Name of the constructed library of the %component
138                             (not used any more, give empty string)
139       \return a loaded component
140     */
141     EngineComponent load_impl(in string nameToRegister,
142                               in string componentName);
143
144     //! Remove the component servant, and deletes all related objects
145     /*!
146       \param component_i     Component to be removed
147     */
148     void remove_impl(in EngineComponent component_i);
149
150     //!  Unload component libraries from the container. 
151     void finalize_removal() ;
152
153     //!  Determines whether the server has been loaded or not.
154     void ping();
155
156     //!  Name of the %container
157     readonly attribute string name ;
158
159     //!  working directory of the %container
160     readonly attribute string workingdir ;
161
162     //!  name of the %container log file (this has been set by the launcher)
163     attribute string logfilename ;
164
165     //!  Shutdown the Container process.
166     void Shutdown();
167
168     //!  Returns the hostname of the container
169     string getHostName();
170
171     //!  Returns the PID of the container
172     long getPID();
173
174     //! Kill the container 
175     /*!
176       Returns True if the %container has been killed.
177       Kept for Superv compilation but can't work, unless oneway...
178       TO REMOVE !
179     */
180     boolean Kill_impl() ;
181
182     //! Create a fileRef
183     /*!
184       returns a fileRef object if origFileName exists and is readable
185       else returns null object. Only one fileRef is created for a given
186       file name, so, several calls with the same file name returns the 
187       same object.
188     */
189     fileRef createFileRef(in string origFileName);
190
191     //! Create a Salome_file
192     /*!
193       returns a Salome_file object if origFileName exists and is readable
194       else returns null object. 
195
196       \param origFileName name of the file to be managed (can contain the path).
197
198       \return Salome_file CORBA reference.
199     */
200     Salome_file createSalome_file(in string origFileName);
201
202     //! Create a fileTransfer
203     /*!
204       returns a fileTransfer object used to copy files from the container
205       machine to the clients machines. Only one fileTransfer instance is
206       created in a container.
207     */
208     fileTransfer getFileTransfer();
209
210     //! Copy a file from a remote host (container) to a local file
211     /*!
212       \param contai the remote container
213       \param remoteFile the file on the remote host to copy
214       \param localFile the local file to create by copy
215      */
216     void copyFile(in Container contai, in string remoteFile, in string localFile);
217
218     //! Create a PyNode in the container
219     /*!
220       \param nodeName the name of the PyNode
221       \param code python code as text to load in the node
222      */
223     PyNode createPyNode(in string nodeName, in string code)  raises(SALOME::SALOME_Exception);
224
225     //! Retrieves the last created PyNode instance with createPyNode.
226     PyNode getDefaultPyNode();
227
228     //! Create a PyScriptNode in the container
229     /*!
230       \param nodeName the name of the PyScriptNode
231       \param code python code as text to load in the node
232      */
233     PyScriptNode createPyScriptNode(in string nodeName, in string code)  raises(SALOME::SALOME_Exception);
234
235     //! Retrieves the last created PyScriptNode instance with createPyScriptNode.
236     PyScriptNode getDefaultPyScriptNode();
237   };
238
239   /*! \brief Interface to pass data files from the client side to the SALOME Container.
240     Passes data from client side to the SALOME container (where component engine is running)
241     size via the CORBA bus as a stream of bytes.
242   */
243
244   interface DataContainer
245   {
246     //! This operation returns the stream with the data file content.
247     TMPFile get();
248     
249     //! Returns the name of the document corresponding to this data container.                                                                                  
250     string name();
251     
252     //! Returns the identifier of the document corresponding to this data container.
253     string identifier();
254
255     //! Returns the extension (type) of the document corresponding to this data container.
256     //! It is taked from the SIMAN URL.
257     string extension();
258
259     //! Defines the extension. It is required is extension of the file is not
260     //! matched with a read extension: archived file, for example.
261     void setExtension(in string extension);
262   };
263                                       
264
265   /*! \brief Interface of the %component.
266   This interface is used for interaction between the %container and the
267   %component and between the components inside the container.
268   */
269   interface EngineComponent
270   {
271     //!  The name of the instance of the %Component
272     readonly attribute string instanceName ;
273
274     //!  The name of the interface of the %Component
275     readonly attribute string interfaceName ;
276
277     //!  Determines whether the server has already been loaded or not.
278     void ping();
279
280     //!  Get study associated to component instance
281     /*!
282       get study associated to component instance
283       \return -1: not initialised (Internal Error)
284                0: multistudy component instance
285               >0: study id associated to this instance
286     */
287     long getStudyId();
288
289     //! Remove component instance from container
290     /*!
291       Deactivates the %Component.
292       -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
293       use remove_impl from Container instead !
294     */
295     void destroy() ;
296
297     //!  Returns the container that the %Component refers to.
298     Container GetContainerRef() ;
299
300     //! Set component instance properties
301     /*!
302       Gives a sequence of (key=string,value=any) to the component. 
303       Base class component stores the sequence in a map.
304       The map is cleared before.
305       This map is for use by derived classes. 
306     */
307     void setProperties(in FieldsDict dico);
308
309     //! Get component instance properties
310     /*!
311       returns a previously stored map (key=string,value=any) as a sequence.
312       See setProperties(in FieldsDict dico).
313     */
314     FieldsDict getProperties();
315
316     //! Set an option value
317     /*!
318       This method is to set an option specific to a certain EngineComponent.
319     */
320     void SetOption(in string optionName, in string value);
321
322     //! Return an option value
323     /*!
324       This method is to get value of an option specific to a certain EngineComponent.
325     */
326     string GetOption(in string optionName);
327
328     //! Set name of a node in a graph (for %SUPERVISOR use)
329     /*!
330       This method is used by the %SUPERVISOR component. It sets the names of
331       the graph and of the node.
332       \param aGraphName Name of graph
333       \param aNodeName  Name of node
334     */
335     void Names( in string aGraphName , in string aNodeName ) ;
336
337     //! Kill the component (if you can)
338     /*!
339       Returns True if the %Component has been killed.
340     */
341     boolean Kill_impl() ;
342
343     //! Stop the component (if you can)
344     /*!
345       Returns True if the activity of the %Component has been stopped.
346       (It's action can't be resumed)
347     */
348     boolean Stop_impl() ;
349
350     //! Suspend the component
351     /*!
352       Returns True if the activity of the %Component has been suspended.
353       (It's action can be resumed)
354     */
355     boolean Suspend_impl() ;
356
357     //! Resume the component
358     /*!
359       Returns True if the activity of the %Component has been resumed.
360     */
361     boolean Resume_impl() ;
362
363     //! Get the cpu used
364     /*!
365       Returns the Cpu used 
366     */
367     long CpuUsed_impl() ;
368     
369     //! Get a python dump
370     /*!
371       Returns a python script, which is being played back reproduces
372       the data model of component
373     */    
374     TMPFile DumpPython(in Object theStudy,
375                        in boolean isPublished,
376                        in boolean isMultiFile,
377                        out boolean isValidScript);
378
379     
380     //! Returns a CORBA Ref of a input Salome_file managed by a service.
381     /*!
382
383       \param service_name service's name.
384       \param file_name name of the requested file.
385
386       \return CORBA Ref of the requested file.
387
388       \exception contains informations of what if the component cannot 
389       sends the file's reference.
390     */
391     Engines::Salome_file getInputFileToService(in string service_name, 
392                                                in string Salome_file_name) raises(SALOME::SALOME_Exception);
393
394     //! Check service input files (transfer them if needed) 
395     /*!
396       This method is used before the activation of the service. It calls
397       recvFiles() on all the input Salome_file files of the service. 
398       
399       Before each recvFiles(), it uses the callback method named configureSalome_file.
400       This method allows the user to configure the files managed by the Salome_file.
401
402       By default, there is no files managed when a Salome_file is created, 
403       but the supervisor set some files managed by the Salome_file from the information contained
404       into the schema file.
405
406       \param service_name service's name.
407
408       \exception contains informations about files that are not in a good state.
409     */
410     void checkInputFilesToService(in string service_name)           raises(SALOME::SALOME_Exception);
411
412     //!  This method adds a input Salome_file to a service of the component.
413     /*!
414
415       \param service_name service's name.
416       \param Salome_file_name name of the Salome_file
417
418       \return a reference of the Salome_file
419
420       \exception raises an exception if there is already
421       a Salome_file with this name for the service.
422     */
423     Engines::Salome_file setInputFileToService(in string service_name,
424                                                in string Salome_file_name)   raises(SALOME::SALOME_Exception);
425
426     //!  Returns a CORBA Ref of a output Salome_file managed by a service.
427     /*!
428
429       \param service_name service's name.
430       \param file_name name of the requested file.
431
432       \return CORBA Ref of the requested file.
433
434       \exception contains informations of what if the component cannot 
435       sends the file's reference.
436     */
437     Engines::Salome_file getOutputFileToService(in string service_name, 
438                                                 in string Salome_file_name) raises(SALOME::SALOME_Exception);
439
440     //! Check service output files (transfer them if needed) 
441     /*!
442       This method is used at the end of the service. It calls
443       recvFiles() on all the output Salome_file files of the service. 
444       
445       Before each recvFiles(), it uses the callback method named configureSalome_file.
446       This method allows the user to configure the files managed by the Salome_file.
447
448       By default, there is no files managed when a Salome_file is created, 
449       but the supervisor set some files managed by the Salome_file from the information contained
450       into the schema file.
451
452       \param service_name service's name.
453
454       \exception contains informations about files that are not in a good state.
455     */
456     void checkOutputFilesToService(in string service_name)        raises(SALOME::SALOME_Exception);
457
458     //!  This method adds an output Salome_file to a service of the component.
459     /*!
460
461       \param service_name service's name.
462       \param Salome_file_name name of the Salome_file
463
464       \return a reference of the Salome_file
465
466       \exception raises an exception if there is already
467       a Salome_file with this name for the service.
468     */
469     Engines::Salome_file setOutputFileToService(in string service_name,
470                                                 in string Salome_file_name)  raises(SALOME::SALOME_Exception);
471
472     //! Indicate if the component instance provides custom information about its objects.
473     /*!
474       Returns true if the component provides custom information about its objects, false otherwise.
475       Should be redefined in the certain component to return true in case of this
476       component provides such information.
477     */
478     boolean hasObjectInfo();
479     
480     //! Get custom information about the given object.
481     /*!
482       This method is used to get the custom information about the given object.
483       Should be redefined in the certain component in case of this
484       component provides such information.
485       It is worth using this method only if hasObjectInfo() method returns true.
486       
487       \param entry object's entry.
488       \param studyId study id
489
490       \return an information about the given object.
491     */
492     string getObjectInfo(in long studyId, in string entry);
493
494     //! Get version of the component
495     /*!
496       This method is supposed to be implemented in all derived classes; default implementation
497       returns "unknown" string that means that no version information about the component is available.
498       \note The version of the component is stored to the study, as a part of general persistence
499       mechanism; once stored, version information in the study cannot be changed.
500
501       \return string containing component's version, e.g. "1.0"
502     */
503     string getVersion();
504
505     //! Generic Import operation to let the component to import data, corresponding to it.
506     /*!
507       \param studyId indentifier of the study where the data must be placed
508       \param data data for import: usually this is just imported file content
509       \param options additional options for Importat operation
510       \return the sequence of identifiers of the importedData in the component (to use later in the export function)
511     */
512     ListOfIdentifiers importData(in long studyId, in DataContainer data, in ListOfOptions options);
513     
514     //! Generic Export operation to ket the component export all modified data corresponding to it.
515     /*!
516       \param studyId identifier of the study that contains the exported data
517      */
518     ListOfData getModifiedData(in long studyId);
519   };
520
521   /*!
522     \brief Base interface of the %component that supports exporting data.
523   */
524   interface ImportableComponent
525   {
526     /*! \brief Get a list of supported formats */
527     SALOME::StringSeq GetImportableFormats();
528     boolean           ImportDataAs(in string format, in SALOME::GenericObj exporter);
529   };
530
531   //!  A block of binary data used for file transfer. The maximum size of the block is defined on server side.
532   typedef sequence<octet> fileBlock;
533
534   /*! \brief Interface of fileTransfer.
535      The fileTransfer and fileRef interfaces provide a file transfer service
536      between different computers.
537   */
538   interface fileTransfer : SALOME::GenericObj
539   {
540     //! Open the file transfer
541     /*!
542       open method returns a key (fileId) that identifies the structure
543       (ex: C FILE), associated to the original file on the server.
544       The structure is created by a container for transfer of files availables
545       on the computer which runs the container.
546       Each open gives a unique fileId, to allow concurrent reads of the same
547       File.
548     */
549     long open(in string fileName);
550     //! Open the file transfer in write mode for file fileName
551     /*!
552       \param fileName the file to copy into with putBlock
553       \return the id to use with putBlock
554     */
555     long openW(in string fileName);
556
557     //! Close the file transfer
558     /*!
559     when the file transfer is finished, close method releases structures 
560     created by open method, identified by fileId.
561     */
562     void close(in long fileId);
563
564     //! Get a file data block
565     /*!
566       Get successive blocks of octets from the original file.
567       The last block is empty, and identifies the end of file.
568     */
569     fileBlock getBlock(in long fileId);
570
571     //! Put a file data block
572     /*!
573        \param fileId identification of the file obtained by openW
574        \param block a data block to copy into the file identified by fileId
575     */
576     void putBlock(in long fileId, in fileBlock block);
577
578   };
579
580   //!  A file managed by a Salome_file. 
581   struct file {
582     //! file name
583     string file_name;
584     //! path name
585     string path; 
586     string type;
587     string source_file_name;
588     //! status ("present" or "notpresent")
589     string status; 
590     long   node;
591     Engines::Container container;
592   };
593
594   //!  A sequence of Engines::file.
595   typedef sequence<Engines::file> files;
596
597
598   //!  The state of a Salome_file. 
599   struct SfState {
600     //! file name
601     string  name; 
602     //! hdf5 file where the file can be saved
603     string  hdf5_file_name; 
604     //! number of files managed
605     long    number_of_files; 
606     //! information if all the files are received
607     boolean files_ok; 
608
609   };
610
611   /*! \brief Interface of a Salome_file managed
612     This file is independent of a Salome module. It can managed one or more
613     real files. It's useful for parallel files. Currently Salome_file cannot manage
614     two files that have the same name but not the same path.
615   */
616   interface Salome_file : Engines::fileTransfer
617   {
618     //!  Load a Salome_file from a hdf5 file.
619     /*!
620
621       \param hdf5_file name (with path) of the hdf5_file.
622
623       \exception contains informations of errors if the loading doesn't succeed.
624      */
625     void load(in string hdf5_file)                            raises (SALOME::SALOME_Exception);
626
627     //!  Save a Salome_file into a hdf5_file.
628     /*!
629
630       \param  hdf5_file name (with path) of the hdf5_file.
631
632       \exception contains informations of errors if the save doesn't succeed.
633
634     */
635     void save(in string hdf5_file)                            raises (SALOME::SALOME_Exception);
636
637     //!  Save a Salome_file into a hdf5_file. 
638     /*!
639       All files that are managed are saved into the hdf5_file
640
641       \param  hdf5_file name (with path) of the hdf5_file.
642
643       \exception contains informations of errors if the save doesn't succeed.
644
645     */
646     void save_all(in string hdf5_file)                            raises (SALOME::SALOME_Exception);
647
648 /**************/
649
650     //!  Add a Local file to the Salome_file.
651     /*!
652
653       \param file_name name of the file with the path.
654
655       \exception raised if the file is already added into the Salome_file.
656     */
657     void setLocalFile(in string comp_file_name) raises (SALOME::SALOME_Exception);
658
659     //!  Add a Distributed file to the Salome_file.
660     /*!
661
662       \param comp_file_name name of the file with the path.
663
664       \exception raised if the file is already added into the Salome_file.
665     */
666     void setDistributedFile(in string comp_file_name) raises (SALOME::SALOME_Exception);
667
668     //!  Connect a Salome_file with another Salome_file.
669     /*!
670       It works only if the Salome_file managed only one file
671
672       \param source_Salome_file Salome_file that managed the distributed version of the file.
673
674       \exception raised if there is more or less than one file.
675     */
676     void connect(in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception);
677
678     //!  Connect the managed file file_name to a Salome_file.
679     /*!
680
681       \param file_name name of the file without the path.
682       \param source_Salome_file Salome_file that managed the distributed version of the file.
683
684       \exception raised if the file doesn't exist.
685     */
686     void connectDistributedFile(in string file_name,
687                                 in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception);
688     
689     //!  Connect the file_name with a Distributed file_name.
690     /*!
691
692       \param file_name name of the file without the path.
693       \param source_file_name It's the name of the file managed by the distributed source Salome_file.
694
695       \exception raised if the file doesn't exist.
696     */
697     void setDistributedSourceFile(in string file_name,
698                                   in string source_file_name) raises (SALOME::SALOME_Exception);
699
700 /**************/
701
702     //! Get all the distributed files managed by the Salome_file and check all the local files.
703     /*!
704
705       \exception raised if some of the files are not ok.
706     */
707     void recvFiles()                                            raises (SALOME::SALOME_Exception) ;
708
709 /**************/
710
711     //!  Remove a file of the Salome_file.
712     /*!
713
714       \param file_name name of the file.
715
716       \exception raised if the file doesn't exist.
717     */
718     void removeFile(in string file_name)                    raises (SALOME::SALOME_Exception);
719
720     //!  Remove all the files of the Salome_file.
721     void removeFiles();
722
723 /**************/
724
725     //! Get the list of the files managed by the Salome_file.
726     /*!
727       The list can be empty.
728     */
729     Engines::files getFilesInfos();
730
731     //! Get a file managed by the Salome_file.
732     /*!
733
734       \param file_name the name of the file.
735
736       \return CORBA file reference.
737
738       \exception raised if the file doesn't exist.
739     */
740     Engines::file  getFileInfos(in string file_name) raises (SALOME::SALOME_Exception);
741
742     //!  Return the state of the Salome_file.
743     Engines::SfState getSalome_fileState();
744
745
746     //! Set the container where files are.
747     /*!
748
749       \param container container CORBA's reference.
750     */
751     void setContainer(in Engines::Container container);
752   };
753
754   /*! \brief Interface of fileRef.
755      The fileTransfer and fileRef interfaces provide a file transfer service
756      between different computers.
757
758      A fileRef object is associated to an original file (origFileName) on a
759      machine (refMachine).
760      It is created by a container (factoryServer) on refMachine,
761      with createFileRef(in string origFileName) method.
762      The fileRef object maintains a list of (machine,filename) for copies. 
763      If a copy exists on myMachine, getRef(myMachine) returns the file name
764      of the copy on myMachine, else returns empy string.
765      If there is no copy on myMachine, method getFileTransfer() from container
766      factoryServer on refMachine provides a fileTransfer object dedicated to
767      CORBA file copy.
768      After the copy, addRef(myMachine, localFileNameOnMyMachine) registers
769      the file name of the copy on myMachine.
770   */
771   interface fileRef
772   {
773     //! the original file
774     readonly attribute string origFileName;
775     //! the machine of the original file
776     readonly attribute string refMachine;
777
778     Container getContainer();
779
780     boolean addRef(in string machine,
781                    in string fileName);
782
783     string getRef(in string machine);
784   };
785 };
786
787 #endif