Salome HOME
[EDF27816] : methods to position environment of slave containers.
[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     FieldsDict get_os_environment();
84
85     /*! \brief Loads a new component class (dynamic library).
86
87       \param componentName like COMPONENT, (Python or C++ implementation)
88                            try to make a Python import of COMPONENT,
89                            then a lib open of libCOMPONENTEngine.so
90       \param reason      in case of error (return false) a string explaining the error
91       \return true if load successful or already done, false otherwise
92     */
93     boolean load_component_Library(in string componentName, out string reason);
94
95     //! Create a new servant instance of a component.
96     /*!
97       Component library must be loaded.
98       \param componentName Name of the component which will be registered
99                            in Registry and Name Service,
100                          (instance number suffix added to the registered name)
101       \return a loaded component
102     */
103     Engines::EngineComponent create_component_instance(in string componentName);
104
105     //! Create a new Python servant instance of a generic service.
106         /*!
107           This simply loads the service in the current container by importing the
108           corresponding Python module.
109           Warning: no internal registration is done, so it is up to the caller to
110           manage the various instantiation.
111           \param serviceName Name of the service
112           \param reason  in case of error (return void string) a string explaining the error
113           \return the IOR of the loaded service.
114         */
115     string create_python_service_instance(in string serviceName,
116                                           out string reason);
117
118     //! Create a new servant instance of a component with environment variables specified.
119     /*!
120       Component library must be loaded.
121       \param componentName Name of the component which will be registered
122                            in Registry and Name Service,
123                          (instance number suffix added to the registered name)
124       \param env         a dict of env variables
125       \param reason      in case of error (return nil) a string explaining the error
126       \return a loaded component
127     */
128     Engines::EngineComponent create_component_instance_env(in string componentName,
129                                                            in FieldsDict env,
130                                                            out string reason);
131     //! Find a servant instance of a component
132     /*!
133       \param registeredName  Name of the component in Registry or Name Service,
134                              without instance suffix number
135       \return the first instance found
136     */
137     EngineComponent find_component_instance(in string registeredName);
138
139     //! Find a servant instance of a component, or create a new one.
140     /*!
141       Loads the component library if needed.
142       Only applicable to multiStudy components.
143       \param nameToRegister Name of the component which will be registered
144                             in Registry (or Name Service)
145       \param componentName  Name of the constructed library of the %component
146                             (not used any more, give empty string)
147       \return a loaded component
148     */
149     EngineComponent load_impl(in string nameToRegister,
150                               in string componentName);
151
152     //! Remove the component servant, and deletes all related objects
153     /*!
154       \param component_i     Component to be removed
155     */
156     void remove_impl(in EngineComponent component_i);
157     
158     //! In case of SSL mode Returns entry to Embedded NS
159     EmbeddedNamingService get_embedded_NS_if_ssl();
160     
161     boolean is_SSL_mode();
162
163     //!  Unload component libraries from the container.
164     void finalize_removal() ;
165
166     //!  Determines whether the server has been loaded or not.
167     void ping();
168
169     //!  Name of the %container
170     readonly attribute string name ;
171
172     //!  working directory of the %container
173     readonly attribute string workingdir ;
174
175     //!  name of the %container log file (this has been set by the launcher)
176     attribute string logfilename ;
177
178     //!  Shutdown the Container process.
179     void Shutdown();
180
181     //!  Returns the hostname of the container
182     string getHostName();
183
184     //!  Returns the PID of the container
185     long getPID();
186
187     //! Kill the container
188     /*!
189       Returns True if the %container has been killed.
190       Kept for Superv compilation but can't work, unless oneway...
191       TO REMOVE !
192     */
193     boolean Kill_impl() ;
194
195     //! Create a fileRef
196     /*!
197       returns a fileRef object if origFileName exists and is readable
198       else returns null object. Only one fileRef is created for a given
199       file name, so, several calls with the same file name returns the
200       same object.
201     */
202     fileRef createFileRef(in string origFileName);
203
204     //! Create a Salome_file
205     /*!
206       returns a Salome_file object if origFileName exists and is readable
207       else returns null object.
208
209       \param origFileName name of the file to be managed (can contain the path).
210
211       \return Salome_file CORBA reference.
212     */
213     Salome_file createSalome_file(in string origFileName);
214
215     //! Create a fileTransfer
216     /*!
217       returns a fileTransfer object used to copy files from the container
218       machine to the clients machines. Only one fileTransfer instance is
219       created in a container.
220     */
221     fileTransfer getFileTransfer();
222
223     //! Copy a file from a remote host (container) to a local file
224     /*!
225       \param contai the remote container
226       \param remoteFile the file on the remote host to copy
227       \param localFile the local file to create by copy
228      */
229     void copyFile(in Container contai, in string remoteFile, in string localFile);
230
231     //! Create a PyNode in the container
232     /*!
233       \param nodeName the name of the PyNode
234       \param code python code as text to load in the node
235      */
236     PyNode createPyNode(in string nodeName, in string code)  raises(SALOME::SALOME_Exception);
237
238     //! Retrieves the last created PyNode instance with createPyNode.
239     PyNode getDefaultPyNode(in string nodeName);
240
241     //! Create a PyScriptNode in the container
242     /*!
243       \param nodeName the name of the PyScriptNode
244       \param code python code as text to load in the node
245      */
246     PyScriptNode createPyScriptNode(in string nodeName, in string code)  raises(SALOME::SALOME_Exception);
247
248     void removePyScriptNode(in string nodeName) raises(SALOME::SALOME_Exception);
249
250     //! Retrieves the last created PyScriptNode instance with createPyScriptNode.
251     PyScriptNode getDefaultPyScriptNode(in string nodeName);
252
253     //! This method remove all refs of PyScriptNode servant objects stored in server.
254     /*!
255      * 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.
256      */
257     void cleanAllPyScripts();
258
259     //! Return number of CPU cores in the calculation node.
260     long getNumberOfCPUCores();
261
262     //! Return a load of each CPU core.
263     vectorOfDouble loadOfCPUCores() raises(SALOME::SALOME_Exception);
264
265     //! Set custom script to calculate a load of each CPU core.
266     /*!
267       \param script Python script to execute
268      */
269     void setPyScriptForCPULoad(in string script);
270
271     //! Nullify custom script to calculate each CPU core's load.
272     void resetScriptForCPULoad();
273
274     //! Get total physical memory of calculation node, in megabytes.
275     long getTotalPhysicalMemory();
276
277     //! Get used physical memory of calculation node, in megabytes.
278     long getTotalPhysicalMemoryInUse();
279
280     //! Obtain physical memory, used by the current process, in megabytes.
281     long getTotalPhysicalMemoryInUseByMe();
282   };
283
284   /*! \brief Interface of the %component.
285   This interface is used for interaction between the %container and the
286   %component and between the components inside the container.
287   */
288   interface EngineComponent
289   {
290     //!  The name of the instance of the %Component
291     readonly attribute string instanceName ;
292
293     //!  The name of the interface of the %Component
294     readonly attribute string interfaceName ;
295
296     //!  Determines whether the server has already been loaded or not.
297     void ping();
298
299     boolean isSSLMode() raises(SALOME::SALOME_Exception);
300     //! Remove component instance from container
301     /*!
302       Deactivates the %Component.
303       -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
304       use remove_impl from Container instead !
305     */
306     void destroy() ;
307
308     //!  Returns the container that the %Component refers to.
309     Container GetContainerRef() ;
310
311     //! Set component instance properties
312     /*!
313       Gives a sequence of (key=string,value=any) to the component.
314       Base class component stores the sequence in a map.
315       The map is cleared before.
316       This map is for use by derived classes.
317     */
318     void setProperties(in FieldsDict dico);
319
320     //! Get component instance properties
321     /*!
322       returns a previously stored map (key=string,value=any) as a sequence.
323       See setProperties(in FieldsDict dico).
324     */
325     FieldsDict getProperties();
326
327     //! Set an option value
328     /*!
329       This method is to set an option specific to a certain EngineComponent.
330     */
331     void SetOption(in string optionName, in string value);
332
333     //! Return an option value
334     /*!
335       This method is to get value of an option specific to a certain EngineComponent.
336     */
337     string GetOption(in string optionName);
338
339     //! Set name of a node in a graph (for %SUPERVISOR use)
340     /*!
341       This method is used by the %SUPERVISOR component. It sets the names of
342       the graph and of the node.
343       \param aGraphName Name of graph
344       \param aNodeName  Name of node
345     */
346     void Names( in string aGraphName , in string aNodeName ) ;
347
348     //! Kill the component (if you can)
349     /*!
350       Returns True if the %Component has been killed.
351     */
352     boolean Kill_impl() ;
353
354     //! Stop the component (if you can)
355     /*!
356       Returns True if the activity of the %Component has been stopped.
357       (It's action can't be resumed)
358     */
359     boolean Stop_impl() ;
360
361     //! Suspend the component
362     /*!
363       Returns True if the activity of the %Component has been suspended.
364       (It's action can be resumed)
365     */
366     boolean Suspend_impl() ;
367
368     //! Resume the component
369     /*!
370       Returns True if the activity of the %Component has been resumed.
371     */
372     boolean Resume_impl() ;
373
374     //! Get the cpu used
375     /*!
376       Returns the Cpu used
377     */
378     long CpuUsed_impl() ;
379
380     //! Get a python dump
381     /*!
382       Returns a python script, which is being played back reproduces
383       the data model of component
384     */
385     TMPFile DumpPython(in boolean isPublished,
386                        in boolean isMultiFile,
387                        out boolean isValidScript);
388
389
390     //! Returns a CORBA Ref of a input Salome_file managed by a service.
391     /*!
392
393       \param service_name service's name.
394       \param file_name name of the requested file.
395
396       \return CORBA Ref of the requested file.
397
398       \exception contains information of what if the component cannot
399       sends the file's reference.
400     */
401     Engines::Salome_file getInputFileToService(in string service_name,
402                                                in string Salome_file_name) raises(SALOME::SALOME_Exception);
403
404     //! Check service input files (transfer them if needed)
405     /*!
406       This method is used before the activation of the service. It calls
407       recvFiles() on all the input Salome_file files of the service.
408
409       Before each recvFiles(), it uses the callback method named configureSalome_file.
410       This method allows the user to configure the files managed by the Salome_file.
411
412       By default, there is no files managed when a Salome_file is created,
413       but the supervisor set some files managed by the Salome_file from the information contained
414       into the schema file.
415
416       \param service_name service's name.
417
418       \exception contains information about files that are not in a good state.
419     */
420     void checkInputFilesToService(in string service_name)           raises(SALOME::SALOME_Exception);
421
422     //!  This method adds a input Salome_file to a service of the component.
423     /*!
424
425       \param service_name service's name.
426       \param Salome_file_name name of the Salome_file
427
428       \return a reference of the Salome_file
429
430       \exception raises an exception if there is already
431       a Salome_file with this name for the service.
432     */
433     Engines::Salome_file setInputFileToService(in string service_name,
434                                                in string Salome_file_name)   raises(SALOME::SALOME_Exception);
435
436     //!  Returns a CORBA Ref of a output Salome_file managed by a service.
437     /*!
438
439       \param service_name service's name.
440       \param file_name name of the requested file.
441
442       \return CORBA Ref of the requested file.
443
444       \exception contains information of what if the component cannot
445       sends the file's reference.
446     */
447     Engines::Salome_file getOutputFileToService(in string service_name,
448                                                 in string Salome_file_name) raises(SALOME::SALOME_Exception);
449
450     //! Check service output files (transfer them if needed)
451     /*!
452       This method is used at the end of the service. It calls
453       recvFiles() on all the output Salome_file files of the service.
454
455       Before each recvFiles(), it uses the callback method named configureSalome_file.
456       This method allows the user to configure the files managed by the Salome_file.
457
458       By default, there is no files managed when a Salome_file is created,
459       but the supervisor set some files managed by the Salome_file from the information contained
460       into the schema file.
461
462       \param service_name service's name.
463
464       \exception contains information about files that are not in a good state.
465     */
466     void checkOutputFilesToService(in string service_name)        raises(SALOME::SALOME_Exception);
467
468     //!  This method adds an output Salome_file to a service of the component.
469     /*!
470
471       \param service_name service's name.
472       \param Salome_file_name name of the Salome_file
473
474       \return a reference of the Salome_file
475
476       \exception raises an exception if there is already
477       a Salome_file with this name for the service.
478     */
479     Engines::Salome_file setOutputFileToService(in string service_name,
480                                                 in string Salome_file_name)  raises(SALOME::SALOME_Exception);
481
482     //! Indicate if the component instance provides custom information about its objects.
483     /*!
484       Returns true if the component provides custom information about its objects, false otherwise.
485       Should be redefined in the certain component to return true in case of this
486       component provides such information.
487     */
488     boolean hasObjectInfo();
489
490     //! Get custom information about the given object.
491     /*!
492       This method is used to get the custom information about the given object.
493       Should be redefined in the certain component in case of this
494       component provides such information.
495       It is worth using this method only if hasObjectInfo() method returns true.
496
497       \param entry object's entry.
498
499       \return an information about the given object.
500     */
501     string getObjectInfo(in string entry);
502
503     //! Get version of the component
504     /*!
505       This method is supposed to be implemented in all derived classes; default implementation
506       returns "unknown" string that means that no version information about the component is available.
507       \note The version of the component is stored to the study, as a part of general persistence
508       mechanism; once stored, version information in the study cannot be changed.
509
510       \return string containing component's version, e.g. "1.0"
511     */
512     string getVersion();
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 information 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 information 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 information 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 empty 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