openoffice启动代码分析

该文主要是windows平台下的代码分析,暂不针对其他平台。

1、相关宏的定义

在openoffice的源代码main\sal\inc\sal有个main.h的文件:其内容大致如下:

#define SAL_MAIN_IMPL \
int SAL_CALL main(int argc, char ** argv) \
{ \
	int ret; \
	sal_detail_initialize(argc, argv); \
	ret = sal_main(); \
	sal_detail_deinitialize(); \
	return ret; \
}

#define SAL_WIN_WinMain \
int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
{ \
	int argc = __argc; char ** argv = __argv; \
    (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
	return main(argc, argv); \
}

#define SAL_IMPLEMENT_MAIN() \
    static int  SAL_CALL sal_main(void); \
    SAL_MAIN_IMPL \
    SAL_WIN_WinMain \
	static int SAL_CALL sal_main(void)

/*
	"How to use" Examples:

	#include <sal/main.h>

	SAL_IMPLEMENT_MAIN()
	{
		DoSomething();

		return 0;
	}

	SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
	{
		DoSomethingWithArgs(argc, argv);

		return 0;
	}

*/

2、启动代码

在main\desktop\source\app目录下有个Main.c文件,其大致内容如下:
#include "sal/config.h"

#include "sal/main.h"

#include "sofficemain.h"

SAL_IMPLEMENT_MAIN() {
    return soffice_main();
}

把前面的宏定义联系起来,其代码大致如此:
static int  SAL_CALL sal_main(void);
int SAL_CALL main(int argc, char ** argv)
{
	int ret; 
	sal_detail_initialize(argc, argv); 
	ret = sal_main(); 
	sal_detail_deinitialize(); 
	return ret;
}

int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) 
{
	int argc = __argc; char ** argv = __argv; 
  (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ 
	return main(argc, argv);
}

static int SAL_CALL sal_main(void)
{
	return soffice_main();
}

这样的话,就知道其在windows平台下的功能函数入口点在soffice_main()中。

下面附上一段官方有关openOffice启动的分析:
  1. Construct the application object (“the desktop”) (C++ constructor).
  2. Invoke the “int main(int argc, char **argv)“ function of the executable (“soffice.bin”).
    1. Initialize VCL.
      1. Initialize the application object (“the desktop”).
        1. Bootstrap the initial Uno component context (Unos root object).
        2. Set the Uno service manger for the process.
        3. Create the configuration manager.
        4. Detect the locale and customize the configuration manager.
        5. Create the OOo to OOo IPC (Inter Process Communication) thread (named pipe communication).
        6. Activate the runtime error handler.
    2. Invoke the “main” method of “the desktop” object.
      1. Handle bootstrap errors (show possible bootstrap errors to user and exit application).
      2. Create and expose the “splash screen”.
      3. Check for “user” configuration data, if not available, then:
        1. Create “user” configuration data..
      4. Check command line arguments for requested UNO acceptors, if requested, then:
        1. Create Uno acceptors.
      5. Initialize the UCB.
      6. Create directory for temporary data.
      7. Set user interface and application locale.
      8. Create global broadcaster service for application/document events.
      9. If “user” configuration data has been newly created, start wizard for license agreement/user data input.
      10. If no command line arguments have been passed, then:
        1. Create one instance framework desktop service.
        2. Create startup module service.
        3. Create frame and connects startup module to frame.
      11. If “quickstart” option has been passed on command line, then:
        1. Create “quickstarter” service, if available. (Note: the “quickstarter” is currently available on Windows only.)
      12. If to-be-loaded documents have been passed on command line, then:
        1. Post document-load commands into event loop.
      13. If to-be-printed documents have been passed on command line, then:
        1. Post document-print commands into event loop.
      14. If “headless mode” has been passed on command line, then
        1. Switch to internal dialogs (file open, printer select, etc.).
      15. Post IPC thread enable into event loop.
      16. Enter the global application message loop.
        1. Dispatch GUI and command messages, e.g.
          1. document creation / loading / printing,
          2. Uno acceptor creation / deletion,
          3. window messages (redraw, move, mouse click, keyboard, etc.).
        2. Leave loop, if
          1. “terminate” has been called on “the desktop” object, or
          2. Menu-bar “File – Exit” or
          3. keyboard shortcut “CTRL-Q” has been invoked.
      17. Close all open documents (asks for allowance for modified documents).
      18. Block all IPC thread requests.
      19. Remove the global temporary directory.
      20. Stop all Uno acceptors
      21. De-initialize the UCB.
    3. De-initialize VCL.
      1. De-initialize “the desktop” object.
      2. Store all configuration changes.
      3. Dispose the Uno component context.
      4. Disable the IPC thread.
  3. Destruct “the desktop” object (C++ destructor).


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值