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