Salome HOME
f399b33086ed94bae5b7fe87bd0866e2a4721516
[modules/kernel.git] / idl / SALOME_Component.idl
1 // Copyright (C) 2007-2014  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     //! Create a PyScriptNode in the container
226     /*!
227       \param nodeName the name of the PyScriptNode
228       \param code python code as text to load in the node
229      */
230     PyScriptNode createPyScriptNode(in string nodeName, in string code)  raises(SALOME::SALOME_Exception);
231   };
232
233   /*! \brief Interface to pass data files from the client side to the SALOME Container.
234     Passes data from client side to the SALOME container (where component engine is running)
235     size via the CORBA bus as a stream of bytes.
236   */
237
238   interface DataContainer
239   {
240     //! This operation returns the stream with the data file content.
241     TMPFile get();
242     
243     //! Returns the name of the document corresponding to this data container.                                                                                  
244     string name();
245     
246     //! Returns the identifier of the document corresponding to this data container.
247     string identifier();
248
249     //! Returns the extension (type) of the document corresponding to this data container.
250     //! It is taked from the SIMAN URL.
251     string extension();
252
253     //! Defines the extension. It is required is extension of the file is not
254     //! matched with a read extension: archived file, for example.
255     void setExtension(in string extension);
256   };
257                                       
258
259   /*! \brief Interface of the %component.
260   This interface is used for interaction between the %container and the
261   %component and between the components inside the container.
262   */
263   interface EngineComponent
264   {
265     //!  The name of the instance of the %Component
266     readonly attribute string instanceName ;
267
268     //!  The name of the interface of the %Component
269     readonly attribute string interfaceName ;
270
271     //!  Determines whether the server has already been loaded or not.
272     void ping();
273
274     //!  Get study associated to component instance
275     /*!
276       get study associated to component instance
277       \return -1: not initialised (Internal Error)
278                0: multistudy component instance
279               >0: study id associated to this instance
280     */
281     long getStudyId();
282
283     //! Remove component instance from container
284     /*!
285       Deactivates the %Component.
286       -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
287       use remove_impl from Container instead !
288     */
289     void destroy() ;
290
291     //!  Returns the container that the %Component refers to.
292     Container GetContainerRef() ;
293
294     //! Set component instance properties
295     /*!
296       Gives a sequence of (key=string,value=any) to the component. 
297       Base class component stores the sequence in a map.
298       The map is cleared before.
299       This map is for use by derived classes. 
300     */
301     void setProperties(in FieldsDict dico);
302
303     //! Get component instance properties
304     /*!
305       returns a previously stored map (key=string,value=any) as a sequence.
306       See setProperties(in FieldsDict dico).
307     */
308     FieldsDict getProperties();
309
310     //! Set an option value
311     /*!
312       This method is to set an option specific to a certain EngineComponent.
313     */
314     void SetOption(in string optionName, in string value);
315
316     //! Return an option value
317     /*!
318       This method is to get value of an option specific to a certain EngineComponent.
319     */
320     string GetOption(in string optionName);
321
322     //! Set name of a node in a graph (for %SUPERVISOR use)
323     /*!
324       This method is used by the %SUPERVISOR component. It sets the names of
325       the graph and of the node.
326       \param aGraphName Name of graph
327       \param aNodeName  Name of node
328     */
329     void Names( in string aGraphName , in string aNodeName ) ;
330
331     //! Kill the component (if you can)
332     /*!
333       Returns True if the %Component has been killed.
334     */
335     boolean Kill_impl() ;
336
337     //! Stop the component (if you can)
338     /*!
339       Returns True if the activity of the %Component has been stopped.
340       (It's action can't be resumed)
341     */
342     boolean Stop_impl() ;
343
344     //! Suspend the component
345     /*!
346       Returns True if the activity of the %Component has been suspended.
347       (It's action can be resumed)
348     */
349     boolean Suspend_impl() ;
350
351     //! Resume the component
352     /*!
353       Returns True if the activity of the %Component has been resumed.
354     */
355     boolean Resume_impl() ;
356
357     //! Get the cpu used
358     /*!
359       Returns the Cpu used 
360     */
361     long CpuUsed_impl() ;
362     
363     //! Get a python dump
364     /*!
365       Returns a python script, which is being played back reproduces
366       the data model of component
367     */    
368     TMPFile DumpPython(in Object theStudy,
369                        in boolean isPublished,
370                        in boolean isMultiFile,
371                        out boolean isValidScript);
372
373     
374     //! Returns a CORBA Ref of a input Salome_file managed by a service.
375     /*!
376
377       \param service_name service's name.
378       \param file_name name of the requested file.
379
380       \return CORBA Ref of the requested file.
381
382       \exception contains informations of what if the component cannot 
383       sends the file's reference.
384     */
385     Engines::Salome_file getInputFileToService(in string service_name, 
386                                                in string Salome_file_name) raises(SALOME::SALOME_Exception);
387
388     //! Check service input files (transfer them if needed) 
389     /*!
390       This method is used before the activation of the service. It calls
391       recvFiles() on all the input Salome_file files of the service. 
392       
393       Before each recvFiles(), it uses the callback method named configureSalome_file.
394       This method allows the user to configure the files managed by the Salome_file.
395
396       By default, there is no files managed when a Salome_file is created, 
397       but the supervisor set some files managed by the Salome_file from the information contained
398       into the schema file.
399
400       \param service_name service's name.
401
402       \exception contains informations about files that are not in a good state.
403     */
404     void checkInputFilesToService(in string service_name)           raises(SALOME::SALOME_Exception);
405
406     //!  This method adds a input Salome_file to a service of the component.
407     /*!
408
409       \param service_name service's name.
410       \param Salome_file_name name of the Salome_file
411
412       \return a reference of the Salome_file
413
414       \exception raises an exception if there is already
415       a Salome_file with this name for the service.
416     */
417     Engines::Salome_file setInputFileToService(in string service_name,
418                                                in string Salome_file_name)   raises(SALOME::SALOME_Exception);
419
420     //!  Returns a CORBA Ref of a output Salome_file managed by a service.
421     /*!
422
423       \param service_name service's name.
424       \param file_name name of the requested file.
425
426       \return CORBA Ref of the requested file.
427
428       \exception contains informations of what if the component cannot 
429       sends the file's reference.
430     */
431     Engines::Salome_file getOutputFileToService(in string service_name, 
432                                                 in string Salome_file_name) raises(SALOME::SALOME_Exception);
433
434     //! Check service output files (transfer them if needed) 
435     /*!
436       This method is used at the end of the service. It calls
437       recvFiles() on all the output Salome_file files of the service. 
438       
439       Before each recvFiles(), it uses the callback method named configureSalome_file.
440       This method allows the user to configure the files managed by the Salome_file.
441
442       By default, there is no files managed when a Salome_file is created, 
443       but the supervisor set some files managed by the Salome_file from the information contained
444       into the schema file.
445
446       \param service_name service's name.
447
448       \exception contains informations about files that are not in a good state.
449     */
450     void checkOutputFilesToService(in string service_name)        raises(SALOME::SALOME_Exception);
451
452     //!  This method adds an output Salome_file to a service of the component.
453     /*!
454
455       \param service_name service's name.
456       \param Salome_file_name name of the Salome_file
457
458       \return a reference of the Salome_file
459
460       \exception raises an exception if there is already
461       a Salome_file with this name for the service.
462     */
463     Engines::Salome_file setOutputFileToService(in string service_name,
464                                                 in string Salome_file_name)  raises(SALOME::SALOME_Exception);
465
466     //! Indicate if the component instance provides custom information about its objects.
467     /*!
468       Returns true if the component provides custom information about its objects, false otherwise.
469       Should be redefined in the certain component to return true in case of this
470       component provides such information.
471     */
472     boolean hasObjectInfo();
473     
474     //! Get custom information about the given object.
475     /*!
476       This method is used to get the custom information about the given object.
477       Should be redefined in the certain component in case of this
478       component provides such information.
479       It is worth using this method only if hasObjectInfo() method returns true.
480       
481       \param entry object's entry.
482       \param studyId study id
483
484       \return an information about the given object.
485     */
486     string getObjectInfo(in long studyId, in string entry);
487
488     //! Get version of the component
489     /*!
490       This method is supposed to be implemented in all derived classes; default implementation
491       returns "unknown" string that means that no version information about the component is available.
492       \note The version of the component is stored to the study, as a part of general persistence
493       mechanism; once stored, version information in the study cannot be changed.
494
495       \return string containing component's version, e.g. "1.0"
496     */
497     string getVersion();
498
499     //! Generic Import operation to let the component to import data, corresponding to it.
500     /*!
501       \param studyId indentifier of the study where the data must be placed
502       \param data data for import: usually this is just imported file content
503       \param options additional options for Importat operation
504       \return the sequence of identifiers of the importedData in the component (to use later in the export function)
505     */
506     ListOfIdentifiers importData(in long studyId, in DataContainer data, in ListOfOptions options);
507     
508     //! Generic Export operation to ket the component export all modified data corresponding to it.
509     /*!
510       \param studyId identifier of the study that contains the exported data
511      */
512     ListOfData getModifiedData(in long studyId);
513   };
514
515   /*!
516     \brief Base interface of the %component that supports exporting data.
517   */
518   interface ImportableComponent
519   {
520     /*! \brief Get a list of supported formats */
521     SALOME::StringSeq GetImportableFormats();
522     boolean           ImportDataAs(in string format, in SALOME::GenericObj exporter);
523   };
524
525   //!  A block of binary data used for file transfer. The maximum size of the block is defined on server side.
526   typedef sequence<octet> fileBlock;
527
528   /*! \brief Interface of fileTransfer.
529      The fileTransfer and fileRef interfaces provide a file transfer service
530      between different computers.
531   */
532   interface fileTransfer : SALOME::GenericObj
533   {
534     //! Open the file transfer
535     /*!
536       open method returns a key (fileId) that identifies the structure
537       (ex: C FILE), associated to the original file on the server.
538       The structure is created by a container for transfer of files availables
539       on the computer which runs the container.
540       Each open gives a unique fileId, to allow concurrent reads of the same
541       File.
542     */
543     long open(in string fileName);
544     //! Open the file transfer in write mode for file fileName
545     /*!
546       \param fileName the file to copy into with putBlock
547       \return the id to use with putBlock
548     */
549     long openW(in string fileName);
550
551     //! Close the file transfer
552     /*!
553     when the file transfer is finished, close method releases structures 
554     created by open method, identified by fileId.
555     */
556     void close(in long fileId);
557
558     //! Get a file data block
559     /*!
560       Get successive blocks of octets from the original file.
561       The last block is empty, and identifies the end of file.
562     */
563     fileBlock getBlock(in long fileId);
564
565     //! Put a file data block
566     /*!
567        \param fileId identification of the file obtained by openW
568        \param block a data block to copy into the file identified by fileId
569     */
570     void putBlock(in long fileId, in fileBlock block);
571
572   };
573
574   //!  A file managed by a Salome_file. 
575   struct file {
576     //! file name
577     string file_name;
578     //! path name
579     string path; 
580     string type;
581     string source_file_name;
582     //! status ("present" or "notpresent")
583     string status; 
584     long   node;
585     Engines::Container container;
586   };
587
588   //!  A sequence of Engines::file.
589   typedef sequence<Engines::file> files;
590
591
592   //!  The state of a Salome_file. 
593   struct SfState {
594     //! file name
595     string  name; 
596     //! hdf5 file where the file can be saved
597     string  hdf5_file_name; 
598     //! number of files managed
599     long    number_of_files; 
600     //! information if all the files are received
601     boolean files_ok; 
602
603   };
604
605   /*! \brief Interface of a Salome_file managed
606     This file is independent of a Salome module. It can managed one or more
607     real files. It's useful for parallel files. Currently Salome_file cannot manage
608     two files that have the same name but not the same path.
609   */
610   interface Salome_file : Engines::fileTransfer
611   {
612     //!  Load a Salome_file from a hdf5 file.
613     /*!
614
615       \param hdf5_file name (with path) of the hdf5_file.
616
617       \exception contains informations of errors if the loading doesn't succeed.
618      */
619     void load(in string hdf5_file)                            raises (SALOME::SALOME_Exception);
620
621     //!  Save a Salome_file into a hdf5_file.
622     /*!
623
624       \param  hdf5_file name (with path) of the hdf5_file.
625
626       \exception contains informations of errors if the save doesn't succeed.
627
628     */
629     void save(in string hdf5_file)                            raises (SALOME::SALOME_Exception);
630
631     //!  Save a Salome_file into a hdf5_file. 
632     /*!
633       All files that are managed are saved into the hdf5_file
634
635       \param  hdf5_file name (with path) of the hdf5_file.
636
637       \exception contains informations of errors if the save doesn't succeed.
638
639     */
640     void save_all(in string hdf5_file)                            raises (SALOME::SALOME_Exception);
641
642 /**************/
643
644     //!  Add a Local file to the Salome_file.
645     /*!
646
647       \param file_name name of the file with the path.
648
649       \exception raised if the file is already added into the Salome_file.
650     */
651     void setLocalFile(in string comp_file_name) raises (SALOME::SALOME_Exception);
652
653     //!  Add a Distributed file to the Salome_file.
654     /*!
655
656       \param comp_file_name name of the file with the path.
657
658       \exception raised if the file is already added into the Salome_file.
659     */
660     void setDistributedFile(in string comp_file_name) raises (SALOME::SALOME_Exception);
661
662     //!  Connect a Salome_file with another Salome_file.
663     /*!
664       It works only if the Salome_file managed only one file
665
666       \param source_Salome_file Salome_file that managed the distributed version of the file.
667
668       \exception raised if there is more or less than one file.
669     */
670     void connect(in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception);
671
672     //!  Connect the managed file file_name to a Salome_file.
673     /*!
674
675       \param file_name name of the file without the path.
676       \param source_Salome_file Salome_file that managed the distributed version of the file.
677
678       \exception raised if the file doesn't exist.
679     */
680     void connectDistributedFile(in string file_name,
681                                 in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception);
682     
683     //!  Connect the file_name with a Distributed file_name.
684     /*!
685
686       \param file_name name of the file without the path.
687       \param source_file_name It's the name of the file managed by the distributed source Salome_file.
688
689       \exception raised if the file doesn't exist.
690     */
691     void setDistributedSourceFile(in string file_name,
692                                   in string source_file_name) raises (SALOME::SALOME_Exception);
693
694 /**************/
695
696     //! Get all the distributed files managed by the Salome_file and check all the local files.
697     /*!
698
699       \exception raised if some of the files are not ok.
700     */
701     void recvFiles()                                            raises (SALOME::SALOME_Exception) ;
702
703 /**************/
704
705     //!  Remove a file of the Salome_file.
706     /*!
707
708       \param file_name name of the file.
709
710       \exception raised if the file doesn't exist.
711     */
712     void removeFile(in string file_name)                    raises (SALOME::SALOME_Exception);
713
714     //!  Remove all the files of the Salome_file.
715     void removeFiles();
716
717 /**************/
718
719     //! Get the list of the files managed by the Salome_file.
720     /*!
721       The list can be empty.
722     */
723     Engines::files getFilesInfos();
724
725     //! Get a file managed by the Salome_file.
726     /*!
727
728       \param file_name the name of the file.
729
730       \return CORBA file reference.
731
732       \exception raised if the file doesn't exist.
733     */
734     Engines::file  getFileInfos(in string file_name) raises (SALOME::SALOME_Exception);
735
736     //!  Return the state of the Salome_file.
737     Engines::SfState getSalome_fileState();
738
739
740     //! Set the container where files are.
741     /*!
742
743       \param container container CORBA's reference.
744     */
745     void setContainer(in Engines::Container container);
746   };
747
748   /*! \brief Interface of fileRef.
749      The fileTransfer and fileRef interfaces provide a file transfer service
750      between different computers.
751
752      A fileRef object is associated to an original file (origFileName) on a
753      machine (refMachine).
754      It is created by a container (factoryServer) on refMachine,
755      with createFileRef(in string origFileName) method.
756      The fileRef object maintains a list of (machine,filename) for copies. 
757      If a copy exists on myMachine, getRef(myMachine) returns the file name
758      of the copy on myMachine, else returns empy string.
759      If there is no copy on myMachine, method getFileTransfer() from container
760      factoryServer on refMachine provides a fileTransfer object dedicated to
761      CORBA file copy.
762      After the copy, addRef(myMachine, localFileNameOnMyMachine) registers
763      the file name of the copy on myMachine.
764   */
765   interface fileRef
766   {
767     //! the original file
768     readonly attribute string origFileName;
769     //! the machine of the original file
770     readonly attribute string refMachine;
771
772     Container getContainer();
773
774     boolean addRef(in string machine,
775                    in string fileName);
776
777     string getRef(in string machine);
778   };
779 };
780
781 #endif