Tuesday, September 28, 2010

Introduction to BREW SDK papers (2)



The second part - the emulator to run "Hello BREW"

Knowledge in the following points before this study, you need the following environment:

1. Microsoft Visual C + + 6.0 庐 (or later)

2. Version 1.1 of the BREW SDK.

To find the minimum system requirements, and to obtain more detailed information, SDK's installation instructions, please see the README file SDK 1.1. Note, here I assume that you have read this article before the series, "What is the BREW" and the first article in this series, "The first part - prior knowledge." I further assume that you have created a module information file (helloBREW.mif) and a BREWx applet resource files (helloBREW.bar) and copy them to the respective "... yourBREWdirExamplesmif256Color" and "... yourBREWdirExamplesen256Color" two directories . Also, "... yourBREWdirExampleshelloBREW" directory must be useful BREW resource editor generated helloBREW_res.h file an application with the BREW Application Wizard to create the source file (helloBREW.c). If you need to know more, you can read the first part mentioned above, or read the SDK documentation that came with.

In this routine, you need to know the file name is very important. In particular, the application directory and module information file (. Mif) to target. Dll files with the same name (that is, the same prefix). Note that you can open the Project Settings dialog box (select Project menu> Settings) and define the Link tab. Dll file name. If you do it in the first part, and should already have the right in the appropriate directory name of the file.

Finally, remind, in this article, "small programs" and "application" will alternately use the two words, represents the same thing.

Setting Visual C + +



Figure 1

In the first part of the set of all essential items are from the BREW Application Wizard to manage it. But we still need to provide an executable file to run in debugging stage. Dll files, but also to ensure that BREW applications can be found. Dll file. To meet the first requirement, we need to provide for the BREW_Emulator.exe path, shown in Figure 1.
To meet the second requirement, we must ensure that the linker will helloBREW.dll written in the project root directory (... helloBREW), instead of the default debug directory (... helloBREWdebug). Because the simulator automatically find the directory named helloBREW helloBREW.dll. Figure 2 shows the Visual C + + Project Settings dialog box in the Link tab of the output file name should be entered.



Figure 2

Understand the source code
First let us look at the application generally helloBREW project wizard generated source code. If you have not so made, please use the Visual C + + open helloBREW project, and then select FileView and expand Source Files folder. You can see the three source code files: AEEAppGen.c, AEEModGen.c, and helloBREW.c. The first two files allow our application to bind to the BREW application execution environment (AEE). AEEModGen.c management modules, each module (module) is basically dependent on each other, including one or more small programs (applets). When an end user activates an application, AEE create a module from the module calls each application must provide the AEEClsCreateInstance () function, followed by examples of applications.
This allows us to begin to understand a small program (applet) and applications (application) can be (more relaxed) to exchange the use of reason. Why? Because applets can be understood as a container, he admits only allows developers to create interactive features and AEE, and run the device all the files. For example, such a container can provide services on the shell interfaces and interfaces on the device display. So that we can consider an application is a small program created with the development of any function. In fact, if in this case we use C + + theory to explain, helloBREW (developers create features) to public from BREW-AEEApplet structure of inheritance, from this perspective, an application is a small program (is a relationship between ). AEEAppGen.c provide AEEApplet_New () function, helloBREW will call this function to set the helloBREW AEEApplet part of the application. Soon we will discuss in more detail AEEClsCreateInstance () and AEEApplet_New ().



Figure 3

Now we are part of how the combination of these with a basic concept, let us look at the BREW Application Wizard generates the framework code. Figure 3 shows the source code, only the most basic parts. As to include the header file, you may have guessed, AEEModGen. Contains AEEModGen.c statement, AEEAppGen.h also declared AEEAppGen.c. AEEShell.h API provides a shell interface to the statement. If you want to know more about this important interface can be included in the BREW SDK BREW API Reference in search IShell. Here we will not be in-depth study will add our own code in helloBREW.c.
Now, we skip helloBREW_HandleEvent () define the term AEEClassCreateInstance () (also may be AEEClsCreateInstance (), translators note). This function is helloBREW where access to the AEE. When the AEE to start the application, send a request, AEEModGen.c defined AEEModCreateInstance () to call a small program (applet) type AEEClassCreateInstance () function. Because BREW is single-threaded, so that every module in the number of small programs, at the same time only a small program is activated. By calling ISHELL_StartApplet (), a small program can be another small program starts. In this case, the current small program was suspended in favor of using ISHELL_StartApplet () provided by the class ID called AEEClassCreateInstance (). Obviously, AEEClassCreateInstance () needs module in a class ID for each branch of logic. In our module, only a small program, so AEEClassCreateInstance () only need to deal with a class ID.
In the previous article, we remember helloBREW.mif file generated a helloBREW the class ID. MIF Editor to create a helloBREW.bid file, which use # define to the class ID is defined as: AEECLSID_HELLOBREW. Clearly, this module from the module information file (helloBREW.mif) documents obtained class ID, and as the first parameter passed to the AEEClsCreateInstance ().
The second parameter, pIShell, is a IShell pointer, is loaded in the module when the first offered by the AEE. Call AEEApplet_New () when, AEEApplet structure m_pIShell members must be set to pIShell. This IShell pointer provides all the API interfaces helloBREW on IShell visit.
The third parameter, po, is a pointer to a pointer that contains the helloBREW module, this parameter will be called AEEApplet_New () when the structure of m_pIModule AEEApplet initialization parameters. Our code does not relate to this pointer. AEEAppGen.c defined AEEAppletRelease () function takes the pointer at the end of the helloBREW release dynamically allocated when the module.
Finally, ppObj is the point of ordinary pointer. Here ** with a void type, since * ppObj can point to two things. Fortunately, we only need the type of object relations IApplet. If you use a little rusty on the pointer, you must use double indirect addressing to ensure that when AEEApplet_New () return * ppObj IApplet point to a valid object. If ppObj simply defined as void * ppObj (ie a single indirect addressing), ppObj in AEEApplet_New () returns will not be changed. C language's parameter passing mechanism will only be to AEEApplet_New () pass ppObj a simple pointer copy, without altering the AEEClsCreateInstance () any original value. Because we want AEEApplet_New () changes in AEEClsCreateInstance () referenced in the same hands, we can only pass the value of participation, rather than the formal parameters.
Passed to AEEApplet_New () function, the reciprocal of the second parameter is a pointer to the application event we handle the pointers. When AEE Upon receipt of Quwang helloBREW event will call this function. If the last parameter non-empty, we need to pass a pointer to an application termination function releases dynamically allocated data. This PFNFREEAPPDATA is a function pointer, this function receives IApplet * type of parameter and return void. To demonstrate, we will helloBREW have added such a function.
We look helloBREW_HandleEvent () framework of the code. The first parameter points to IApplet instance. In this function, where, pi will be used to access a small program m_pIShell and m_pIDisplay data members. When we helloBREW add your own code, we will discuss this in more detail.
The second parameter, eCode, as its name refers to what action is used to detect lead helloBREW_HandleEvent () is called the event code. The last two parameters include the type of event data. AEE.h in the header file can be found in the full, detailed list of events, as well as through the event type parameter wParam and dwParam description of the data provided. BREW SDK in the user guide can be found a more friendly and more readable list of events, including various key events and key code and the content of wParam and dwParam event type description.
Add source code
Now let us helloBREW add our own code. You can "... yourBREWdirExamplesHelloWorld" under the helloworld.c see a simple version of "hello". In order to prevent duplication and to make our example more interesting, we will create your own small program data structures and InitAppData () and FreeAppData () function, from a resource file (helloBREW.bar reference to the first part of the prior knowledge) to load the string and BREW-IStatic controller with display them.



Figure 4

As shown on Figure 4, we need to include the header files in the list of additional AEEStdLib.h. This header file includes MALLOC () and FREE (), and the BREW API Reference helper functions mentioned.
Then, our application needs to be able to access helloBREW.bid the class ID and helloBREW_rew.h the string ID.
Finally, Figure 4 shows the definition of some constants; a defined buffer size, a defined edge of the screen and the static number of pixels between the border control.



Figure 5

Figure 5 from the definition of data structure of our small program began. Note that a very important point is that where an application can not have any static (global) data. So our application data structures are defined as the global data structure (struct, at least C program is that). And we let AEEClsCreateInstance () to manage the heap instance. This brings attention to another very important point: the device's stack space is very limited. For example, Kyocera QCP3035e only 500 bytes of available stack space. Obviously, you need to minimize the use of the stack, in order to achieve this, you can call the function level to a minimum, as much as possible of non-atomic (can be split, translators note) local variables assigned to the heap, and when need to pass data from more than four hours, or use the pointer.
Application data structure provides a container for loading the entire application life cycle, the programmer need to safeguard their belongings. This includes the application AEEApplet section, where you can visit the shell, display, and maintenance of the module pointer. AEEApplet this data structure must be the first member, which is mandatory. Another member of this data structure is used to show that we define a pointer to a string of IStatic controller pointer.



Figure 6

Figure 6 shows through our revised AEEClassCreateInstance () function. First and foremost, we modify the incoming AEEAppletNew () the first parameter. In addition to the AEEApplet helloBREW need some space, we need to use AEEApplet_New () to process the data structure for small IStatic * allocate space. To achieve this, we will be sizeof (hb_app) passed to AEEApplet_New () as the first parameter, instead of the original sizeof (AEEApplet).
The second step, in order to helloBREW add a FreeAppData () function, we need to AEEApplet_New () pass a pointer (hb_FreeAppData ()) as the last parameter. This function will be registered into the AEE and the application automatically when the call termination. Figure 9 shows the hb_FreeAppData () definition. As you can see, the basic task of this function is called ISTATIC_Release () to release IStatic controller.
AEEClsCreateInstance () the last change is the call hb_InitAppData (), where our applet data structure IStatic * member is initialized to NULL, as shown in Figure 9.



Figure 7

Shown in Figure 7, helloBREWHandleEvent () on BREW Application Wizard generates a large number of changes the initial code. At the top, we define a point to our applet data structure pointer, and will be the first parameter of this function, IApplet * assigned to the pointer. The event handler, this pointer is used to access some of the m_pIShell helloBREW in AEEApplet members, in addition to providing us used to represent IStatic controller m_pIStat pointer access.

The beginning of the EVT_APP_START, we define the first local variable is AEEDeviceInfo type variable. This structure includes the preservation device screen size and color depth of the member variable. A more detailed description of data members of the BREW API Reference in the final data structure (data types, the translator note) section found. I remember I warned about minimizing the use of stack space, we should be in the heap to allocate memory for this structure, and definition of indicators to monitor it locally. Because of this small program run out of stack space need not worry about the risk, for simplicity's sake, I will define the structure of local variables.

Next, we see a simple rectangular object (AEERect), we used to determine the size and location of the static controller, and several caches were stored m_pIStat determine the title and text. AECHAR is uint16 type definitions (typedef) (reference AEE.h), and uint16 is an unsigned short integer type definition (see AEEComdef.h). This AECHAR can be used to store Unicode character set, or a wide (wide characters) type variable. This wbufTtl and wbufTxt point is the wide-character set consisting of a null-terminated string. Reference BREW API Reference chapter in the Helper function to understand the wide-character set string manipulation tools.

Verify the validity of the End m_pIShell, we can assign calls to a di. Next, the screen size of the members of di.cxScreen and di.cyScreen be used to set the controller with a static position, size of the rectangular object. The screen coordinate system, the origin is the upper left corner of the display, the time when we x coordinate increases to the right, to move down y coordinate increases.

Call ISHELL_CreateInstance () when the designated AEECLSID_STATIC as requested interface class ID. Assuming success, the function call returns m_pIStat will point to a valid IStatic. Other interface class ID can be found in the aeeclassids.h. Create a IStatic, we call ISTATIC_SetRect () to set its rectangle, will point to just initialize the rectangle structure pointer passed to him.

Defined for the buffer before (wbufTtl, wbufTxt) allocate the memory, we call ISHELL_LoadResString () twice: once for the IStatic the title, one text. Both the title and the text buffer will be submitted to the ISTATIC_SetText (). ISTATIC_SetProperties () is used to define the location of the title and text, and call ISTATIC_Redraw () static on the screen controller. Reference BREW API Reference section in the IStatic can learn more about these functions, the calling method.

Note BREW tolerate memory leaks. So you need to be certain that all of the MALLOC () calls are corresponding with on the FREE () call, while ISHELL_CreateInstance () call corresponding to a pair of I * _Release () call. The bottom in EVT_APP_START release (FREE ()) using the two buffer (buffer). HelloBREW in hb_FreeAppData () call Istatic_Release () when the release Istatic instance.



Figure 8

Figure 8 shows the helloBREWHandleEvent () of the remainder. Here we added a EVT_KEY event for the application of mobile phones on the "CLR" key standards. When the "CLR" button is pressed, we return FALSE to inform AEE through should close the application. In the mobile phone "CLR" button preset means "back on the level", your application should implement this action.

Because the release of m_pIStat things by hb_FreeAppData () processing, so we EVT_APP_STOP event handler is not needed to do anything.



Figure 9

Run helloBREW



Figure 10

Now to start the BREW Simulator (Emulator), by clicking the BREW SDK program group shortcuts, you can click the Visual C + + in the red exclamation point painted on the button to start the simulator.

BREW SDK program group, click the shortcut, or click Visual C + + in the red exclamation point to start the BREW Simulator. With left and right arrow keys in the BREW Application Manager Location helloBREW, is selected, you can see in the simulator center of the screen shows the 85 脳 40 we have a big map. Press Enter on the keyboard, the simulator will display shown in Figure 10, the second frame of the image.

As I defined a MIF helloBREW.mif another directory, so you show the first frame simulator may not be as the same as shown in Figure 10. I do to avoid that comes in a lot of examples in the SDK application's icon in the icon to find helloBREW. In other words, the emulator only displays the current directory in the specified MIF effective. Mif file the application. You can move the generated helloBREW.mif, for example, ".. yourBREWdirExamplesyourmif256Color", and then the tools menu in the simulator will set it to start the mif directory. Detailed guidance can refer to the BREW MIF settings editor guide.

Debugging with emulator
If you follow the guidance of the beginning of this article to set the Visual C + + part, as usual you can use Visual C + + debugger. For example, to believe AEEClsCreateInstance () did work as expected, you can place the cursor in this function, and click the Debug toolbar's "Run to Curor". Then you can run a single step function, set to monitor certain variables, jumped into the other function, or the cursor and handle other functions or events again, click on "Run to Curor". If you have Visual C + + debugger does not know, you should read the Visual C + + comes with the relevant sections of the document.

If the simulator can not start when the phone interface display Sharp Z800, you can use the File> Load Device ... to replace the analog equipment. In the "... yourBREWdirdevices" select Z800 phone device file to qsc end, and click Open to load the device.

Note that 2.0SDK last brought the simulator in a combination of more stringent test reactor, which will help you find memory leaks, array bounds in the early development process such as possible errors. 2.0 The simulator can be used in conjunction with the 1.x of the SDK. On how to install one machine information such as multiple versions of the SDK installation instructions refer to SDK2.0.







相关链接:



SQL any



DVR-MS to MPEG



A domestic room, map description IDC



QuickTime to MPEG



What rod dealer OUTLETS



Mito Xiu a plus for the perfect



Registry Tools evaluation



MKV to Xbox 360



Comment Font Tools



3% discount notebook supplier return profits behind



Hot Graphic Viewers



2009 CAXA Ten News



Domestic Long Road CAXA CAD Lead The Way Down To Earth



Carried out in the end to P2P: the story about the Jxta (2)



Flash MX Features Tours Of The Three



No comments:

Post a Comment