📄 mainpage.docs
字号:
In case you like to start developing a new module, pleasecontact Sofia-SIP development team so that they can help you to set upthe basic module for you.An overview of the contents of a module directory: - file \<modulename\>.docs \n Main documentation file for the module. See @ref module_docs for more information - subdirectory pictures \n Contains any pictures/images that are needed by the module documentation. The file formats to use are GIF (for html pages) and EPS (for latex). If some program (e.g. MS Visio) is used to create the pictures, also the original files must be stored here.\n (Note that old modules may have "images" subdirectory instead of "pictures") - files Makefile.am \n See section @ref build "dealing with GNU Autotools" below. - (optionally) source code file(s) of the module and module tests. The source code file(s) can also be located in subdirectories if necesary. @section oo_with_c Writing Object-Oriented CodeWhile C does not provide any special object-oriented features on its own, itis possible to program in object-oriented way using C, too. Sofia code makeuse of many object-oriented features while being written entirely in C.@subsection oo_hiding Data HidingData hiding is a practice that makes separation between two modules veryclear. Outside code cannot directly access the data within a module, but ithas to use functions provided for that purpose. Data hiding also makes iteasier to define a protocol between two objects - all communication happensusing function calls.How to implement data hiding in C? Easiest answer is to only declare datastructures in the header files, not to define them. We have a typedef #msg_tfor @link msg_s struct msg_s @endlink in <msg.h>, but the actual structureis defined in <msg_internal.h>. Programs outside @b msg module does not haveaccess to the @link msg_s struct msg_s @endlink, but they have to to accessthe #msg_t object through method functions provided in <msg.h>. The @b msgimplementation is also free to change the internal layout of the structure,only keeping the function interface unmodified.@subsection oo_interface InterfacesAbstract interface is another object-oriented practice used in Sofia. Bestexample of that would be audio codec interface in @b ac module. Theinterface defined in <ac.h> is shared with all different audio codecs, bethey simple as G.711 or complex as AMR-WB.Abstract interface is achieved using virtual function table, just as C++typically implements abstract classes and virtual functions. Each codecdefines a structure containing functions implementing the interface, andreturns a pointer to the structure within a codec instance.@subsection oo_derived Inheritance and Derived ObjectsInheritance is a object-oriented practice that has limited use in Sofia. Most common example of inheritance is use of #su_home_t. Many objects arederived from #su_home_t, which means that they can use the varioushome-based memory management functions from <su_alloc.h>. In this sence, inheritance means that a pointer to a derived object can becasted as a pointer to a base object. In other words, the derived objectmust have the base object at the beginning of its memory area:@codestruct derived { struct base base[1]; int extra; char *data;};@endcodeThere are three alternatives to cast a pointer to derived to a pointer tobase:@codestruct base *base1 = (struct base *)derived;struct base *base2 = &derived->base;struct base *base3 = derived->base;@endcodeThe third alternative works because base was used as a 1-element array.@subsection oo_templates TemplatesThere are a few template types implemented as macros in Sofia libraries. Most typical example is hash table in <htable.h>, which can be used todefine hash tables types and accessor functions for different objects.@section memory Memory ManagementThe home-based memory management is useful when a lot of memory blocks are allocated for given task. The allocations are done via the memory home, which keeps a reference to each allocated memory block. When the memory home is then freed, it will free all memory blocks to which it has reference. This simplifies application logic because application code does not need to keep track of the allocated memory and free every allocated block separately.See documentation of <su_alloc.h> and @ref su_alloc "memory managment tutorial"for more information of memory management services.@subsection contextdata Memory management of context dataA typical example of use of a memory home is to have a memory home structure(su_home_t) as part of operation context information structure.@code /* context info structure */ struct context { su_home_t ctx_home[1]; /* memory home */ other_t *ctx_other_stuff; /* example of memory areas */ ... }; /* context pointer */ struct context *ctx; /* Allocate memory for context structure and initialize memory home */ ctx = su_home_clone(NULL, sizeof (struct context)); /* Allocate memory and register it with memory home */ ctx->ctx_other_stuff = su_zalloc(ctx->ctx_home, sizeof(other_t)); ... processing and allocating more memory ... /* Release registered memory areas, home, and context structure */ su_home_zap(ctx->ctx_home);@endcode@subsection combining Combining allocationsAnother place where home-based memory management makes programmerslife easier is case where a sub-procedure makes multiple memory allocations and, in case the sub-procedure fails, all the allocations must be released and, in case the sub-procedure is succesfull, all allocations must becontrolled by upper level memory management.@code /* example sub-procedure. top_home is upper-level memory home */ int sub_procedure( su_home_t *top_home, ... ) { su_home_t temphome[1] = { SU_HOME_INIT(temphome) }; ... allocations and other processing ... /* was processing successfull ? */ if (success) { /* ok -> move registered allocated memory to upper level memory home */ su_home_move( top_home, temphome ); } /* destroy temporary memory home (and registered allocations) */ /* Note than in case processing was succesfull the memory */ /* registrations were already moved to upper level home. */ su_home_deinit(temphome); /* return ok/not-ok */ return success; }@endcode@section testing Testing Your CodeSee <tstdef.h> for example of how to write module tests with macros providedby Sofia.Here are some ideas of what you should test:- "Smoke test" \n See that the module compiles, links and executes.- Module API functions should be tested with\n - valid args - not valid args- Aim for 100% line coverage\n (If there is a line of code that you have not tested, you don't know if its working.) \n For selected part of code you should also aim for 100% brach/path coverage.\n But be anyway reasonable with these because in practise complete coverage is next to impossible to achive (so 80% is ok in practise).- Create test to check assumptions and/or tricks used in code.\n For example if you rely on some compiler feature, create a test that will fail with a compiler that does not have that feature.@subsection check Running Module TestsAutomake, which is now used to build most of Sofia modules, has builtinsupport for unit tests. To add an automatically run test to your module,you just have to add the following few lines to your module's Makefile.am(of course, you have to write the test programs, too):@codeTESTS = my_test_foo my_test_barcheck_PROGRAMS = my_test_foo my_test_barmy_test_foo_SOURCES = foo.c foo.hmy_test_foo_LDADD = -L. -lmymy_test_bar_SOURCES = bar.c bar.hmy_test_foo_LDADD = -L. -lmy@endcodeEach test program should either return zero for success or a non-zeroerror code in its main function. Now when you run "make check",@b my_test_foo and @b my_test_bar will be built and then run. Make will print asummary of how the tests went. As these tests are run from the build system, the tests must be non-interactive (no questions asked) and not rely on any files that are not in CVS.Sofia-SIP's top-level makefile contains a recursive check target, so you can use "cd sofia ; make check" to run all the existing testswith a single command.@section build Dealing with GNU AutotoolsSofia-SIP build system is based on the GNU tools make, autoconf and automake. This toolset has become the de-facto way of building Linux software. Because of this there is a lot of publicly available documentationabout these tools, and of course, lots and lots of examples.A good introduction to these tools is available at<a href="http://developer.gnome.org/doc/books/WGA/generating-makefiles.html">developer.gnome.org</a>. <a href="http://sources.redhat.com/autobook">Autobook</a>provides more detailed documentation for autoconf and automake.The <a href="http://www.gnu.org/manual/make/">GNU make manual</a> is also a good source of information.@subsection autotools_diagram Autotools workflow@image latex autotools.eps@image html autotools.gif@subsection configure_in configure.inThe @b configure.in file (newer autoconf versions use also @b configure.ac)contains the primary configuration for autoconf. Configure.in containschecks for all external libraries, non-standard language and compilerfeatures, that are needed to build the target module.This file is created by the developer of the module.@subsection sofia_m4 m4 filesSofia-SIP's own autoconf macros are stored in the top-level direcry called @bm4. These macros, along with all other macros used by @b configure.in, arecopied into the module-specific @b aclocal.m4 file by an utility calledaclocal.Contact Sofia-SIP development team, if you need changes to these files.@subsection aclocal_m4 aclocal.m4The aclocal.m4 contains the definitions of the autoconf macros used in @b configure.in.This file is generated by aclocal command.@subsection Makefile_am Makefile.amMakefile.am is where you define what programs and libraries should be built, and also what source files are needed to create them.When you run automake, it creates the file Makefile.in.This file is created by the developer of the module.@subsection configure configureWhen you run configure script, it performs all the checks defined in @b configure.in and then replaces all @b xxx.in files with equivalent @b xxx files. All @c @@FOO@@ variables in the source @b *.in files are replaced with values found during the configuration process. For instancethe variable @c @@srcdir@@ in @b Makefile.in is replaced in @b Makefile with the source directory path (useful when compiling outside the main source tree).This file is generated by autoconf command.@subsection config_status config.statusThis script stores the last parameters given to configre command.If necessary you can rerun the last given configure command (with givenparameters) by using command "config.status -r" or "config.status --reschedule".This file is generated by configure command.@subsection config_cache config.cacheThis file contains results of the various checks that configure command performed. In case the configure command didn't work, you might try todelete this file and run the configure command again.This file is generated by configure command.@subsection Makefile MakefileThe @b Makefile contains the actual rules how to build the target libraries and program. It is used by the @c make program. @b Makefile is generated from @b Makefile.in when you run @c autoconf command.Ensure that "make dist" and "make install" targets work.This file is generated by configure command (via config.status).@subsection config_h config.hThis file contains C language defines of various confurable issues.This file is generated by configure command.*//**@page debug_logs Debugging LogsThe Sofia-SIP components can output various debugging information. The detail ofthe debugging output is determined by the debugging level. The level isusually module-specific and can be modified by module-specific environmentvariable. There is also a default level for all modules, controlled byenvironment variable #SOFIA_DEBUG.The environment variables controlling the logging and other debug output areas follows:- #SOFIA_DEBUG Default debug level (0..9)- #NUA_DEBUG User Agent engine (<a href="nua/index.html">nua</a>) debug level (0..9)- #SOA_DEBUG SDP Offer/Answer engine (<a href="soa/index.html">soa</a>) debug level (0..9)- #NEA_DEBUG Event engine (<a href="nea/index.html">nea</a>) debug level (0..9)- #IPTSEC_DEBUG HTTP/SIP autentication module debug level (0..9)- #NTA_DEBUG Transaction engine debug level (0..9)- #TPORT_DEBUG Transport event debug level (0..9) - #TPORT_LOG If set, print out all parsed SIP messages on transport layer - #TPORT_DUMP Filename for dumping unparsed messages from transport- #SU_DEBUG <a href="nea/index.html">su</a> module debug level (0..9)The defined debug output levels are:- 0 fatal errors, panic- 1 critical errors, minimal progress at subsystem level- 2 non-critical errors- 3 warnings, progress messages- 5 signaling protocol actions (incoming packets, ...)- 7 media protocol actions (incoming packets, ...)- 9 entering/exiting functions, very verbatim progress*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -