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