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