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