⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 package.contents.html

📁 ecos源代码包
💻 HTML
📖 第 1 页 / 共 3 页
字号:
NAME="PACKAGE.HEADERS">Exported Header Files</H2
><P
>A package's exported header files should specify the interface
provided by that package, and avoid any implementation details.
However there may be performance or other reasons why implementation
details occasionally need to be present in the exported headers.</P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>Not all programming languages have the concept of a header file. In
some cases the component framework would need extensions to support
packages written in such languages. </P
></BLOCKQUOTE
></DIV
><P
>Configurability has a number of effects on the way exported header
files should be written. There may be configuration options which
affect the interface of a package, not just the implementation. It is
necessary to worry about nested <TT
CLASS="LITERAL"
>#include's</TT
> and how
this affects package and application builds. A special case of this
relates to whether or not exported header files should
<TT
CLASS="LITERAL"
>#include</TT
> configuration headers. These configuration
headers are exported, but should only be <TT
CLASS="LITERAL"
>#include'd</TT
>
when necessary.</P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="PACKAGE.HEADERS.FUNCTIONS">Configurable Functionality</H3
><P
>Many configuration options affect only the implementation of a
package, not the interface. However some options will affect the
interface as well, which means that the options have to be tested in
the exported header files. Some implementation choices, for example
whether or not a particular function should be inlined, also need to
be tested in the header file because of language limitations.</P
><P
>Consider a configuration option
<TT
CLASS="VARNAME"
>CYGFUN_KERNEL_MUTEX_TIMEDLOCK</TT
> which controls
whether or not a function <TT
CLASS="FUNCTION"
>cyg_mutex_timedlock</TT
> is
provided. The exported kernel header file <TT
CLASS="FILENAME"
>cyg/kernel/kapi.h</TT
> could contain the
following:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#include &lt;pkgconf/kernel.h&gt;
&#8230;
#ifdef CYGFUN_KERNEL_MUTEX_TIMEDLOCK
extern bool cyg_mutex_timedlock(cyg_mutex_t*);
#endif</PRE
></TD
></TR
></TABLE
><P
>This is a correct header file, in that it defines the exact interface
provided by the package at all times. However is has a number of
implications. First, the header file is now dependent on <TT
CLASS="FILENAME"
>pkgconf/kernel.h</TT
>, so any changes to
kernel configuration options will cause <TT
CLASS="FILENAME"
>cyg/kernel/kapi.h</TT
> to be out of date, and
any source files that use the kernel interface will need rebuilding.
This may affect sources in the kernel package, in other packages, and
in application source code. Second, if the application makes use of
this function somewhere but the application developer has
misconfigured the system and disabled this functionality anyway then
there will now be a compile-time error when building the application.
Note that other packages should not be affected, since they should
impose appropriate constraints on
<TT
CLASS="VARNAME"
>CYGFUN_KERNEL_MUTEX_TIMEDLOCK</TT
> if they use that
functionality (although of course some dependencies like this may get
missed by component developers).</P
><P
>An alternative approach would be:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>extern bool cyg_mutex_timedlock(cyg_mutex_t*);</PRE
></TD
></TR
></TABLE
><P
>Effectively the header file is now lying about the functionality
provided by the package. The first result is that there is no longer a
dependency on the kernel configuration header. The second result is
that an application file using the timed-lock function will now
compile, but the application will fail to link. At this stage the
application developer still has to intervene, change the
configuration, and rebuild the system. However no application
recompilations are necessary, just a relink.</P
><P
>Theoretically it would be possible for a tool to analyze linker errors
and suggest possible configuration changes that would resolve the
problem, reducing the burden on the application developer. No such
tool is planned in the short term.</P
><P
>It is up to component writers to decide which of these two approaches
should be preferred. Note that it is not always possible to avoid
<TT
CLASS="LITERAL"
>#include'ing</TT
> a configuration header file in an
exported one, for example an option may affect a data structure rather
than just the presence or absence of a function. Issues like this will
vary from package to package.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="PACKAGE.HEADERS.INCLUDES">Nested <TT
CLASS="LITERAL"
>#include's</TT
></H3
><P
>As a general rule, unnecessary <TT
CLASS="LITERAL"
>#include's</TT
> should be
avoided. A header file should <TT
CLASS="LITERAL"
>#include</TT
> only those
header files which are absolutely needed for it to define its
interface. Any additional <TT
CLASS="LITERAL"
>#include's</TT
> make it more
likely that package or application source files become dependent on
configuration header files and will get rebuilt unnecessarily when
there are minor configuration changes.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="PACKAGE.HEADERS.CONFIGINCLUDES">Including Configuration Headers</H3
><P
>Exported header files should avoid <TT
CLASS="LITERAL"
>#include'ing</TT
>
configuration header files unless absolutely necessary, to avoid
unnecessary rebuilding of both application code and other packages
when there are minor configuration changes. A
<TT
CLASS="LITERAL"
>#include</TT
> is needed only when a configuration option
affects the exported interface, or when it affects some implementation
details which is controlled by the header file such as whether or not
a particular function gets inlined.</P
><P
>There are a couple of ways in which the problem of unnecessary
rebuilding could be addressed. The first would require more
intelligent handling of header file dependency handling by the tools
(especially the compiler) and the build system. This would require
changes to various non-eCos tools. An alternative approach would be to
support finer-grained configuration header files, for example there
could be a file <TT
CLASS="FILENAME"
>pkgconf/libc/inline.h</TT
> controlling which
functions should be inlined. This could be achieved by some fairly
simple extensions to the component framework, but it makes it more
difficult to get the package header files and source code correct:
a C preprocessor <TT
CLASS="LITERAL"
>#ifdef</TT
> directive does not
distinguish between a symbol not being defined because the option is
disabled, or the symbol not being defined because the appropriate
configuration header file has not been <TT
CLASS="LITERAL"
>#include'd</TT
>.
It is likely that a cross-referencing tool would have to be developed
first to catch problems like this, before the component framework
could support finer-grained configuration headers.</P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="PACKAGE.DOCUMENTATION">Package Documentation</H2
><P
>On-line package documentation should be in HTML format. The component
framework imposes no special limitations: component writers can decide
which version of the HTML specification should be followed; they can
also decide on how best to cope with the limitations of different
browsers. In general it is a good idea to keep things simple.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="PACKAGE.TESTS">Test Cases</H2
><P
>Packages should normally come with one or more test cases. This allows
application developers to verify that a given package works correctly
on their particular hardware and in their particular configuration,
making it slightly more likely that they will attempt to find bugs in
their own code rather than automatically blaming the component
writers.</P
><P
>At the time of writing the application developer support for building
and running test cases via the component framework is under review and
likely to change. Currently each test case should consist of a single
C or C++ source file that can be compiled with the package's set of
compiler flags and linked like any application program. Each test case
should use the testing API defined by the infrastructure. A
magically-named calculated configuration option of the form
<TT
CLASS="VARNAME"
>CYGPKG_&lt;PACKAGE-NAME&gt;_TESTS</TT
> lists the test
cases.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="PACKAGE.HOST">Host-side Support</H2
><P
>On occasion it would be useful for an <SPAN
CLASS="APPLICATION"
>eCos</SPAN
> package to be shipped
with host-side support. This could take the form of an additional tool
needed to build that package. It could be an application intended to
communicate with the target-side package code and display monitoring
information. It could be a utility needed for running the package test
cases, especially in the case of device drivers. The component
framework does not yet provide any such support for host-side
software, and there are obvious issues related to portability to the
different machines that can be used for hosts. This issue may get
addressed in some future release. In some cases custom build steps can
be subverted to do things on the host side rather than the target
side, but this is not recommended.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="package.versions.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="cdl-guide.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="package.distrib.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Package Versioning</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="package.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Making a Package Distribution</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -