Tizen 应用程序的入口文件的主要部分是什么?

What are the major parts of a Tizen application's entry file?

本文关键字:是什么 应用程序 入口 文件 Tizen      更新时间:2023-10-16

由于Tizen仍然不太受欢迎,我找不到Tizen应用程序入口文件的解释。根据下面的示例代码,有人能解释一下Tizen入口文件的特定部分吗(主函数返回值,#ifdef,args…)?

#include <new>
#include "MultipointTouch.h"
using namespace Tizen::Base;
using namespace Tizen::Base::Collection;
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
_EXPORT_ int OspMain(int argc, char* pArgv[]);
/**
 * The entry function of Tizen C++ application called by the operating system.
 */
int
OspMain(int argc, char* pArgv[])
{
    AppLog("Application started.");
    ArrayList args;
    args.Construct();
    for (int i = 0; i < argc; i++)
    {
        args.Add(*(new (std::nothrow) String(pArgv[i])));
    }
    result r = Tizen::App::Application::Execute(MultipointTouch::CreateInstance, &args);
    TryLog(r == E_SUCCESS, "[%s] Application execution failed", GetErrorMessage(r));
    args.RemoveAll(true);
    AppLog("Application finished.");
    return static_cast<int>(r);
}
#ifdef __cplusplus
}
#endif // __cplusplus
  • #ifdef __cplusplus
    extern "C

不是Tizen特有的。它所做的是"使C++中的函数名具有'C'链接(编译器不会破坏名称),以便客户端C代码可以使用仅包含函数声明的'C'兼容头文件链接到(即使用)您的函数。"(源代码)。


  • int OspMain(int argc, char* pArgv[])

OspMain只是Tizen原生应用程序(即应用程序启动时操作系统调用的应用程序中的第一个函数)的入口点,与其他操作系统/框架中的mainWinMain非常相似。


  • args

App Execute方法需要参数作为Strings的列表。因此,OspMain函数在调用Execute方法之前负责构建该列表;从argv中的每个char*创建String,并且将这些Strings放置在ArrayList(这是IList接口的实现)中。


  • 返回值

OspMain的返回类型是int,但它从Execute接收的结果代码是result类型,因此它将result强制转换为int。如果你想了解更多关于C++类型转换的信息,这里有很多问题。


最后,我认为作为一名应用程序开发人员,很少有人会关心Entry文件。它是由IDE自动为您创建的,而不是您通常会更改的内容。