小糊涂学symbian日记(5)(转)

应用程序能够很自然的分为engine、UI和view组件,他们相互依赖又逻辑上各自分开。

每个程序都有三个各自不同的UID值,以用来在系统中唯一标识自己。

SymbianOS是一个庞大的操作系统,拥有数百个类和上千个成员函数,和其他的庞大的系统一样,symbianOS也可以进行分类,比较常用的是子系统分类方法。如应用程序引擎子系统就包括了各种在标准应用程序中处理数据的API。

在symbianOS中subsystem大多是按照APIs来分类的,也并不是非要一对一的二进制库或头文件来标识。

symbianOS的子系统有很多,我们逐个来描述(注意有些子系统如Narrow Band Protocols, Web Browser, Wap Browser等目前还没有可用的APIs)

Base
------
归类为Base的API组是任何程序设计人员所不能忽略的,无论你要写什么程序。对于初涉symbian系统编程的人员来说,也是非常非常基础的编程意识就是!——尽量使用专为移动设备系统设计的类库,而不是那些标准的c库函数或标准的c++库(或是什么STL),这个很重要,习惯于编写良好风格c/c++在这里可能要大跌眼镜了,呵呵。这就是意味着那些Base APIs类中包括处理字符串、数组、链表、错误处理甚至是整型实型这些基本类型。

事实上,它还包括真正的系统编程用API,那些涉及到系统核心的线程、进程和内存处理等。

Graphics
----------
Graphics sub-component contains the APIs for drawing to particular types of phones,such as the screen and printers, embedding picture objects, and font and bitmap handling.

这个子模块还包括Window Server Client-Side API——它提供了用来绘制窗口和发送窗口事件的函数,以及动画API,使得动画可以运行在一个较高优先级的系统线程内。


Application Framework
-----------------------
应用程序框架,正如名字所示,定义了应用程序的结构和基本的用户接口处理。

Applications here has a narrower sense than just program: it implies a program with a user interface, rather than say, a server program that runs in the background doing a system task. It can also imply a whole other group of requirements such as how the documents (data) that the application handles are presented to the user.

除了上面说的以外,它还包括处理诸如用户接口控制、文字布局和front end processors(非键盘输入机制就象是手写识别一样)

The phone manufacturer adds their own specialist APIs that provide user interface elements suitable for the screen and input mechanisms that it uses. However, the base classes for these and many of the key application concepts are defined by this subsystem.

Enginess and utilites
----------------------
Application Engines 这类API提供了访问the application data of the core application.它可以使得第三方程序与核心应用更亲密的接触。

Alongside the Application Engines APIs, as specialist manipulators of data, are the Multi Media Server APIs, which provides audio and image manipulation, and the Application Services APIs, which provides a range of utility services to applications, from logging and system information, to vCard and vCalendar handling.

Communications
-----------------
有大量丰富的用于通信有关的API,他们和我们前面看到的几类API有很大的不同。

Comms Infrastructure,这类API提供了通信和网络的框架和系统服务。它为希望使用特殊通信技术(如红外和串口)的用户提供支持。

At a higher-level, Messaging provides a framework for multi-protocol messaging and support for particular messaging protocols, and Telephony provides a comparable framework for telephony services. Finally, WAP Stack provides access to a WAP protocol stack.

[命名约定]
在symbian系统平台中,使用了一组标准约定来命名它们的类、结构、变量、函数、宏、枚举和常量。

Class names
------------
大部分的类名都拥有一个前缀C、T、R、或M,它们的意思如下:
C:heap-allocated classes, that are derived from a base class CBase
T:value classes, that do not own any external object(如TInt、TReal等)
R:resource classes, that contain handles to a real resource which is maintained elsewhere
M:interface classes, that define abstract protocol definitions that are implemented by derived classes

注意,由静态成员函数单独组成的类是没有任何前缀字母的,类名通常是一个名词,指明了类的含义。

Struct names
--------------
结构类型可以认为是与T类很相似的,比如也没不拥有外部对象,并且也习惯性的在结构名开头添加前缀T(有时可能是S)

Variable names
---------------
成员变量的名字由i打头(如iMember),这使得它很容易的检查一些与清除有关的规则是否执行了;
参数的名字由a打头(如aControl或aIndex);
局部变量的名字没有这样的前缀字母;
全局变量一般是不提倡使用的,实在要用那就要以一个大写字母打头。

Symbian并没有使用什么诸如匈牙利命名法之类的法则以使得变量类型得以彰显。在这里顺便说一下,呵呵symbian SDK对这样的法则进行了很大的抨击,我个人保留自己的意见,大家有兴趣的话可以看看:)反正各说各有哩。

Function names
----------------
函数名应该指明他们的功用。经常使用动词。一个例外就是"getter"型函数,如果函数返回一个成员变量的值,那这个函数名通常定做是这个变量的名字,之不过没有i前缀:)如

inline RWindow& Window() const { return iWindow; };

而一个与"setter"有关的函数应该包括the word Set,如SetWindow()

正如以前说过的symbian平台并不使用c++标准的异常处理机制,它有着自己的一套方案。任何有可能引起异常的函数都应该有个L后缀:),这使得检查错误的这个基本处理更加容易。

注意,new(ELeave)函数也可能引起异常。

最基本的异常函数是User::Leave(),Any function that contains any of these, and does not trap them, might itself leave, and should be coded with a trailing L in its name. 如果一个函数调用另一个可能引起异常的函数,那它的名字最好也有L后缀。

和异常机制紧紧联系在一起的是清除栈,它在一个异常发生时,会恢复相应在堆上分配的内存。一个要把数据放在清除栈上的分配或构造函数应该以...LC()结尾。For instance, many new, PushL(), ConstructL() sequences are encapsulated in a NewLC()

function:
CS* s = CS::NewLC(p1, p2);

可以看出,我们分配了对象,初始化了它,并将它放入清除栈。This process may leave (if only through the PushL()!), so such funcionts always include an L, and are therefore ...LC().

A functon which takes ownership of its object and destroys it has a neme ending in ...D(). An example is the UI framework dialog protocol:

CEikDialog* dialog = new(ELeave) CBossSettingsDialog;
if (dialog->ExectueLD(R_BOSS_SETTINGS_DIALOG))

//handle successful settings
};

The ExecuteLD() function includes second-phase construction, execution of the dialog and then destruction.

Macro names
-------------
宏名都是大写字母组成的,并且各单词间有下划线连接。

Enumeration names
--------------------
Enumeration的命名应该遵循如下规则:
拥有前缀T;
enumeration的成员应该有前缀E;
类型和成员应该有一个明确的,有意义的名字

Enumerations的作用域应该放在相关类中。

class TDemo

public:
enum TShape { EShapeRound, EShapeSquare };
};

TDemo::TShape shape = TDemo::EShapeSquare;

Constant names
---------------
常量名都应该有个K前缀,如
const TInt KMaxNameLength = 0x20;


Layout conventions

和naming conventions一样,symbian平台代码的布局也有一定的规范。

Headers
----------
只选取有用的头文件来包含;
the standard anti-nesting method is used to avoid multiple inclusion of headers:for example,

// EG.H
//
// Copyright notice
//

#ifndef _EG_H_
#define _EG_H_
//...include files and declarations
#endif

Class layout
--------------
——General
  1、access control specifiers are always given for readability
  2、class members are declared in the following order: public member functions, protected member functions, private member functions, protected data, private data, public data. The appropriate access specifier is given at the start of each group.
  3、for readability, function arguments are named in the function declaration as well as the definition

——Virtual functions
  1、virtual functions that replace inherited behaviour are grouped together in the header, with a comment documenting from which class the behaviour is inherited
  2、the virtual keyword is not given for these functions
  3、虚函数不要写成内联形式,因为很难知道编译器是如何处理他们的。有个例外,就是虚析构函数可以是内联的。

——Inline functions
  1、要为内联函数指明关键字inline
  2、不要在类的说明中提供函数的处理,应该在头文件的末尾或者是一个单独的inl文件中处理

Class types

overview
----------
在symbain平台上的应用程序使用四种类形式,分别是:
1、value classes, or types,是由T开头的。其本身没有任何外部对象,包括直接(通过指针)或间接的(通过hanle)
2、heap-allocated class,是由C开头的。其都是从CBase类继承而来的。
3、resource classes,是由R开头的。R objects are handles to a real resource which is maintained elsewhere.
4、interface classes,是由M开头的。They define abstract protocol definitions that are implemented by derived classes

These types are closely related to the requirements of cleanup support.

value types-T classes
----------------------
大部分基础类型都是值类型,下面介绍的type or class,名字前面都冠以T
1、T types contain their value. They do not own any external object, either directly (by pointer) or indirectly (by handle).

2、T types may be allocated either on the stack (C++ automatic variables) or as members of other classes.

——Constructor
  大多数T types都足够简单而不需要什么构造函数,如果要,那它的功用也就是初始化成员数据。

——Copy constructor and assignment operator
  一个拷贝构造函数(TX(const TX&))或是赋值操作(TX& operator=(const TX&))都是很少见。(这点和一般c++不同要注意)这是因为T型的拷贝很简单,一般只是成员之间的互相拷贝,而这个正是编译器自动生成的构造函数和赋值操作所完成的功能。

当然这些函数有时候是必须的——如果T class是一个模板类,parameterised by an integer length, which is also contained as a member of the class.如此的话,在一个TX<32>和TX<40>之间拷贝或赋值就需要费更多的周折,那就需要好好的对一个拷贝或赋值操作来进行明确编码了。

——Destructor
  T types没有析构函数,也没有人需要,因为没有外部的资源需要被清除(当T对象goes out of scope:)

——Orphaning
  T types 可以在堆栈中很安全的被释放,这意味着内存可以被被直接释放而不用去调用什么析构函数。这是因为T types不拥有外部资源,也就少了去处理它们的麻烦:)

——Function arguments
  T types may be passed by value, as well as by reference, in function arguments.

——Data members
  T types 可能包括其他的T type对象。此外,它还可能包括一个R对象,或是一个指向C对象的指针,provided these objects are owned by another class or function, which is responsible for these objects’ cleanup. In practice, this rarely occurs.

——Built-in C++ types
  All built-in C++ types satisfy the criteria for T classes. Built-in types are given typedef names beginning with T, e.g. TInt.


Standard class hierarchy-C classes and class CBase
------------------------------------------------------
大部分的类都是C class,他们都是直接或间接从CBase继承来的。
从CBas派生的类拥有如下特性:

1、他们都是在堆上分配的——不是在栈上,并且不应该是其他类的成员。
2、在C类对象的分配中,所有的成员数据都被初始化为binary zeroes
3、他们可以通过指针或引用被传递,并不需要一个明确的拷贝构造函数或赋值操作,除非有特殊意图。
4、they have non-trivial construction and, because of the possibility that a leave might occur during the construction process, a two-phase construction protocol is used, in which the c++ constructor is only uesed for aspects of construction which cannot leave, and a ConstructL() function is used for aspects of construction which might leave
5、他们有一个虚析构函数,用来做标准的清除工作。
6、因为虚析构函数的存在,所以使用清除栈来支持c对象的清除工作是很容易的。此外,因为C对象是分配在堆中的,所以在异常发生后必须被清除掉: this imposes a requirement for cleanup consciousness when dealing with all C classes在处理c类时就必须要有这个清除的意识。


Resoucrce types-R classes
---------------------------
R classes are proxies for object owned elsewhere. There are two main motivations for this:
1、the real object is owned by a server in a different thread or address space, or
2、the real object's implementation must be hidden from the client

下面是R对象的关键特征:
1、they contain a handle that is used to pass on requests to other objects.
2、they are opened using an "open" function particular to the R class, and closed using a "close" function particular to the class.如果一个R对象打开后就必须被关闭。一般来说,如果负责打开对象的那个线程被中断了,那和该对象联系在一起的资源就被自动关闭了。
3、they may be freely bitwise copied
4、他们没有明确的构造、析构或拷贝构造函数以及赋值操作。

R classes use a variety of protocols to meet these needs:
1、the nature of the handle many differ from R class to R class
2、there is no common base class for all R classes
3、the initialisation function has a variety of names: also possible are Open()、Create()、Allocate()等
4、the termination function has a variety of names: also possible are Close()、Destroy()、Free()等
5、since R classes own external resources, there is a requirement for cleanup: this is handled in various ways depending on the class

Interface types-M classes
----------------------------
M classes定义了抽象的protocols或接口。其具体的处理被它的派生类所提供

M classes拥有下列约束:
1、他们不应该包括任何成员数据
2、他们不应该包括构造或析构函数,以及对诸如=操作的重载

M classes 通常包括一系列定义抽象接口的纯虚函数,有些M classes可能提供成员函数的处理,尽管有上面的约束。

M classes是symbian平台上唯一使用多重继承的类。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-126254/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-126254/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值