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