Difference between revisions of "Documentation/DevGuide/WritingUNO/Generating Source Code from UNOIDL Definitions"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m (Robot: Changing Category:Writing UNO Components)
Line 103: Line 103:
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Writing UNO Components]]
+
 
 +
[[Category:Documentation/Developers Guide/Professional UNO]]

Revision as of 06:46, 4 June 2008



The type description provided in .idl files is used in the subsequent process to create type information for the service manager and to generate header and class files. Processing the UNOIDL definitions is a three-step process.

  1. Compile the .idl files using idlc. The result are .urd files (UNO reflection data) containing binary type descriptions.
  2. Merge the .urd files into a registry database using regmerge. The registry database files have the extension .rdb (registry database). They contain binary data describing types in a tree-like structure starting with / as the root. The default key for type descriptions is the /UCR key (UNO core reflection).
  3. Generate sources from registry files using javamaker or cppumaker. The tools javamaker and cppumaker map UNOIDL types to Java and C++ as described in the chapter UNO Language Bindings. The registries used by these tools must contain all types to map to the programming language used, including all types referenced in the type descriptions. Therefore, javamaker and cppumaker need the registry that was merged, but the entire office registry as well. OpenOffice.org comes with a complete registry database providing all types used by UNO at runtime. The SDK uses the database (type library) of an existing OpenOffice.org installation.

The following shows the necessary commands to create Java class files and C++ headers from .idl files in a simple setup under Linux. We assume the jars from <OFFICE_PROGRAM_PATH>/classes have been added to your CLASSPATH, the SDK is installed in /home/sdk, and /home/sdk/linux/bin is in the PATH environment variable, so that the UNO tools can be run directly. The project folder is /home/sdk/Thumbs and it contains the above .idl file XImageShrink.idl.

  # make project folder the current directory
  cd /home/sdk/Thumbs
 
  # compile XImageShrink.idl using idlc 
  # usage: idlc [-options] file_1.idl ... file_n.idl
  # -C adds complete type information including services
  # -I includepath tells idlc where to look for include files
  #
  # idlc writes the resulting urds to the current folder by default
  idlc -C -I../idl XImageShrink.idl
 
  # create registry database (.rdb) file from UNO registry data (.urd) using regmerge
  # usage: regmerge mergefile.rdb mergeKey regfile_1.urd ... regfile_n.urd
  # mergeKey entry in the tree-like rdb structure where types from .urd should be recorded, the tree 
  # starts with the root / and UCR is the default key for type descriptions
  #
  # regmerge writes the rdb to the current folder by default
  regmerge thumbs.rdb /UCR XImageShrink.urd
 
  # generate Java class files for new types from rdb
  # -B base node to look for types, in this case UCR
  # -T type to generate Java files for
  # -nD do not generate sources for dependent types, they are available in the Java UNO jar files
  #
  # javamaker creates a directory tree for the output files according to 
  # the modules the given types were placed in. The tree is created in the current folder by default
  javamaker -BUCR -Torg.openoffice.test.XImageShrink -nD <OFFICE_PROGRAM_PATH>/types.rdb thumbs.rdb
 
  # generate C++ header files (hpp and hdl) for new types and their dependencies from rdb
  # -B base node to look for types, in this case UCR
  # -T type to generate C++ header files for
  #
  # cppumaker creates a directory tree for the output files according to
  # the modules the given types were placed in. The tree is created in the current folder by default
  cppumaker -BUCR -Torg.openoffice.test.XImageShrink <OFFICE_PROGRAM_PATH>/types.rdb thumbs.rdb

After issuing these commands you have a registry database thumbs.rdb, two header files XImageShrink.hpp and XImageShrink.hdl (the first is the one you must include in the source files implementing your component), and a Java class file XImageShrink.class. (In versions of OpenOffice.org prior to 2.0, javamaker produced Java source files instead of class files; you therefore had to call javac on the source files in an additional step.) You can run regview against thumbs.rdb to see what regmerge has accomplished.

 regview thumbs.rdb

The result for our interface XImageShrink looks like this:

 Registry "file:///home/sdk/Thumbs/thumbs.rdb":
 
 /
   / UCR
     / org
       / openoffice
         / test
           / XImageShrink 
             Value: Type = RG_VALUETYPE_BINARY
                    Size = 316
                    Data = minor version: 0
                           major version: 1
                           type: 'interface'
                           uik: { 0x00000000-0x0000-0x0000-0x00000000-0x00000000 }
 
                           name: 'org/openoffice/test/XImageShrink' 
                           super name: 'com/sun/star/uno/XInterface'
                           Doku: ""
                           IDL source file: "/home/sdk/Thumbs/XImageShrink.idl"
                           number of fields: 3
                           field #0: 
                           name='SourceDirectory' 
                           type='string' 
                           access=READWRITE 
   
                           Doku: ""
                           IDL source file: ""
                           field #1: 
                           name='DestinationDirectory' 
                           type='string' 
                           access=READWRITE 
                           
                           Doku: ""
                           IDL source file: ""
                           field #2: 
                           name='Dimension' 
                           type='com/sun/star/awt/Size' 
                           access=READWRITE 
                           
                           Doku: ""
                           IDL source file: ""
                           number of methods: 0
                           number of references: 0

Source generation can be fully automated with makefiles. For details, see the sections Running and Debugging Java Components and C++ Component below. You are now ready to implement your own types and interfaces in a UNO component. The next section discusses the UNO core interfaces to implement in UNO components.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools