To this download PDF document: http://www.move2008.com/down/download.asp? Downid = 1 & id = 122
Symbian OS C for Windows C Programmers
Andy Weinstein, Degel Software LtdVersion 1.0, OCT 2002
1 Introduction. This article discusses problems that a typical Windows C programmer may encounter when exposed to the Symbian operating system. We have developed three successful versions of the Symbian operating system to make us very clear that it is difficult to work in this environment where it is not a rich and stable environment. One reason for Symbian success is that many mobile phone manufacturers are very unwanted to be tied to Microsoft this thief boat, and the other reason is that Symbian integrates a lightweight, first-class system, while providing such a wide range of functions. Some prompts here may be helpful for developing Symbian operating system applications.
2. Documents and resources. For an ordinary Windows programmer, he first noticed the Symbian operating system is that the Symbian development document is too small compared to Microsoft's senior highly sophisticated equipment. Although this situation is improved, some API classes still have no related documents. For example, CEIKRICHTEXTEDITOR This class has no independent entry in the document. CRICHText This class includes most related functions, which have been incorporated, but you may not know when to use this control for the first time (see us below for the object structure). Relative to a lot of human material to improve the document, the easiest way is based on the fact that Symbian provides a lot of source code (although not the entire operating system) and routine. The programmer does not need to guess the behavior of many APIs - they just want to see the implementation. If this is not enough, Symbian provides source code for some components, such as Word. The API and routines are combined to meet the needs of most programmers. From version 6.0, the SYMBian operating system is open to its PlatinumPartner Program, http://www.symbian.com/partners/part-platnm.html member is open. This requires additional registration. One of the impacts of this project is that the complete source code of some old version of the development package is no longer available. Instead, Symbian or Nokia company continues to improve the document, while providing continuous expansion routines. For example, the documentation provided with Series 60 has an independent entry called "How to operate RICH Text" (although Ceikrichtexteditor still has no entry). There are many other useful "how to" articles in the documentation. In Series 60, the combination of documents and routines is obvious - there is a routine to each Avkon UI class in the document. The Windows programmer has a thing to learn is a lack of useful external resources, although this situation is being improved. "Professional Symbian Programming '(PSP) contains many useful information, but it is not suitable as a quick reference, and it is the 5th edition of the Symbian operating system - the new version will be in 2003 Earlier is earlier. PSP is still not considered, but the situation has changed, especially at the UI level. There is a book called "Symbian Equipment Wireless Java") may be updated, and it can be used for C developers. There is also a "Symbian OS Communications Programming" and "Series 60 and Symbian Output" ('Programming for Series 60 and Symbian OS') has also been placed. More details can be found at http://www.symbian.com/books/index.html. The online documentation and Q-A resources have indeed contributed to the blank. Symbian has set up "Symbian Developer Network", which is a network resource for analog forum, FAQ, sample, and other useful information. Its address is http://www.symbian.com/developer. Nokia also has a similar project called "NOKIA Forum", the URL is located at http://www.forum.nokia.com. Wherever you go, it is not necessarily, and you will not have an answer if you posted a question - this depends on your other development partners.
Symbian and NOKIA's internal personnel sometimes appear here, but if you want to get exact reply from the population of knowing the answer, you need to pay registration. Symbian's payment registration address in "Partner Program" in http://www.symbian.com/partners/part-servs.html, NOKIA can be found in "Developer Support, Technical Case Solving" from the Nokia Forum. But look at the free resource first: there is a lot of useful latest information and resources, including the timed development package upgrade. 3. Object structure. The Symbian operating system has a time that takes time is familiar with him is very powerful. For example, a list box (List box) is not an object - but four: list box objects, model (Model), view (view), and Drawer. The functional division between them is expected and is very in line with logic. Edit control is more complicated. At first glance, it seems to have only two main objects: UI control and a text object that contains processing text. But the formatted operation introduces a further object formatted and formatted to paragraph formatting. These, according to the order, use the independent Mask object to indicate the formatted API call you want to place any given call position. So the operation text is displayed as a black body or a non-black body, and it also affects the code to CEIKRICHTEXTETOR, CPAraformat, TcharFormatmask, CParaFormat, and CParaformatmask.
Here is such code: tcharformat defaultformat; tcharformatmask formatmask; formatMask.setttrib (EattFontStrokeweweight); crichtext * text = idisplay-> richtext (); text-> reset (); for (int i = 0; i <10; i) {TPtrC boldText = getBoldPiece (i); TPtrC plainText = getRomanPiece (i); ... TInt insertPos = text-> DocumentLength (); text-> SetInsertCharFormatL (* iCharFormat, formatMask, insertPos); text-> InsertL (insertPos, boldText); text-> CancelInsertCharFormat (); insertPos = text-> DocumentLength (); text-> SetInsertCharFormatL (defaultFormat, formatMask, insertPos); text-> InsertL (insertPos, plainText); text-> CancelInsertCharFormat () ;} CParaFormat paraFormat; TParaFormatMask paraFormatMask; iDisplay-> RichText () -> GetParaFormatL (& paraFormat, paraFormatMask, 0, iDisplay-> TextLength ()); paraFormatMask.ClearAll (); paraFormatMask.SetAttrib (EAttLineSpacing); paraFormatMask.SetAttrib (EAttLineSpacingControl ); paraformat.ilinespacingcontrol = cparaformat :: ElinespacingexactlyintWips; cgraphicsdevice * screenDeendevice = ieikonenv-> screenDeendevice (); Tint Pa raDelta; ... TInt lineHeight = screenDevice-> VerticalPixelsToTwips (iRegularFont-> HeightInPixels () paraDelta); paraFormat.iLineSpacingInTwips = lineHeight; iDisplay-> RichText () -> ApplyParaFormatL (& paraFormat, paraFormatMask, 0, iDisplay-> TextLength ( )))); But this is not all - About text view objects, especially CTextView and CTextLayout, along with their help objects. When we want to locate the scroll point in editing control, we have to understand the location of CTextView, and how to get it, and how to get it, there are CtextView :: setViewl , TViewyposqualifier :: setSpot and TViewyposqualifier :: setmakelinefullyvisible.
They look like this: TInt yPos = iDisplay-> TextView () -> ViewRect () iBr.iY; TViewYPosQualifier yPosQualifier; yPosQualifier.SetHotSpot (TViewYPosQualifier :: EFViewBottomOfLine); yPosQualifier.SetMakeLineFullyVisible (TViewYPosQualifier :: EFViewForceLineFullyVisible);. Idisplay-> textView () -> setviewl (idisplay-> textLength (), ypos, yposqualifier, ctextview :: efviewdiscardAllFormat); Who wants to get? One of our colleagues does not believe that this is the only way to be, but he tries a variety of different ways to prove this by using many (a variety of) in various APIs in each class. a little. This complexity we are describing is actually because the features provided by the Symbian operating system are too rich, and it is important to understand this. Once you know this area, you will be so grateful to the Symbian operating system. Then you will soon find that you can predict where you need the function hide. So duplicate, you will find that our confusion that we start now has become aesthetic enjoyment. 4. String. Strings, ah, strings in Symbian! There is no doubt that the implementation of Symbian is well thought out, strong and economical. It is also undoubtedly that this represents a rich disease. The string is implemented by the mechanism of Symbian as "descriptor", which is related to the following classes: TDESC, TBUFCBASE, TDES, TPTRC, TBUFC, HBUFC, TBUF, and TPTR. This does not include the direct amount of TLITC manipulation, it is not a descriptor. I have not mentioned Unicode yet, although it is obviously very payment. These classes allow you to accurately use the least amount of memory to store different types of strings, while also allowing them to "clean". But every time you have to consider which is not a interesting thing, this situation is unavoidable, because different APIs have different parameters or return values. There is a small example of a name into the sample message: _LIT (KBoilerplate, "Hello there,% S"); TPtrC name = GetPointerIntoNameDescriptorWithoutAllocatingAnyMemory (); TPtr finishedProduct = HBufC :: NewLC (KBoilerplate () Length () name. .Length ()) -> des (); finishedProduct.Format (kboilerplate (), & name); // This code has also lacking a line, which will be added and discussed below. Nothing at all provides a string similar to the MFC string or a Java string - fully dynamic. Division of String and StringBuffer in Java has little value for the issues we discussed here. Symbian's worthwhile thing is that they do these documents very well. But what you really need is not frequent reading it frequently. Symbian thinks about the limited robots in development, which is undeniable that this is essential for some applications and platforms. However, on the current, a Symbian operating system C programmer feels like those early IBM PC programmers, they are dealing with Intel's segmentation structure, but the 68000 chip is large and single addressing space makes Apple. It is a cool choice.
5. Cleaning stack and error handling. The error handling framework for the Symbian operating system is mainly the cleaning stack, which is an element that is unfamiliar with a Windows programmer. Just like a descriptor, it is very elegant, Symbian announces much more effective than the exception handling mechanism than the C language. In a article called "Symbian operating system programming terminology", you can get it from http://www.symbian.com. However, it is almost a certain "correct thing" at the system level to slow down application development. Symbian designs such a framework for applications that need to run for a long time for a limited resource condition, which requires the development time to pay for strong mass. The type of type using try / catch is of course briefly, but it is frequent to put the memory into the memory into and pop up the cleaning stack when it is appropriate. It will occasionally. When this happens, you have to spend a lot of time to track asymmetry caused in your code. As a programmer that is unfamiliar with the descriptor and cleaning stack, how to fall into the predicament, let's take a look at an example of string: _LIT (Kboilerplate, "Hello the,% s"); tptrc name = getPointAntonameDescriptorwithoutAllocatingAnameMemory ( ); Tptr finishedProduct = hbufc :: newlc (kboilerplate (). Length () name.Length ()) -> des (); finishedProduct.Format (kboilerplate (), & name); // The following is the lack of one line - - See the previous comments // cleanupstack :: POP (); this code does push memory into the cleaning stack, but only the data type of the variable, you can't find this. This is because we use a convenient way to define a TPTR to hold FinishedProduct and assure the value of HBUFC :: Newlc (...) -> DES () to it. HBUFC is an identifier that has allocated memory on the pile, but if we only see the left, it may ignore the fact that the des () shortcut will be used. Newlc also pushes allocated memory into the cleaning stack. Once we finished FinishedProduct, it is best to call cleanupstack :: POP (), otherwise our cleaning stack will be unbalanced. The problem is that we may not find this imbalance first until it triggers an error. There is also a more interesting thing than tracking this asymmetrical.
6. Application framework. The Symbian operating system is indeed provided with a class to establish an application, but at the same time, it is very small to establish a frame code that is capable of establishing an unsatisfactory application interface. To handle this event, it is only manually. This example is of course easy to understand how to do it, but in fact, every screen picture is designed to carefully consider it, it is a matter of time, and it is easy to incur a mistake. Starting from the Symbian operating system 6.1, the Symbian operating system adds a very simple mechanism to use the unique ID number to achieve switching between different screens, but there are many things to do. Here, there is an example of most primary situations: this is not used here to add a control to the screen, but use two objects called CountComponTrols and ComponentControl in the view object, the latter must return value from 0 to the former. Each integer is returned to the UI control. To add a control, in addition to constructing, adjust the size, active in the appropriate location, you must be accumulated in the code, you have to add a CASE to the Switch statement in the ComponentControl function. The Symbian operating system does provide a perfect way to establish dialogs based on resource files. When you declare the dialog box in the resource file, you don't have to address these things directly. However, since the dialog only allows control in a column column, it may not be appropriate for complex screen settings in some advanced applications.
7. Window problem. The Symbian operating system does not encourage the use of "own window" control. That is to say, a control does not always hold the own window (in the sense of the graphic object controlled by the window system that is cut in the z-axis sequence). Because these objects use system resources, the application should simply perform a suitable painting function to specify the boundaries of its rectangle. This may feel different for developers who are used to each control have a real window, but it is not difficult to master this. Although the standard UI control set of the Symbian operating system is very rich and strong, it occasionally occasionally incorrectly. For example, we already have an edit box with a scroll bar, now you have to use another control to replace it. Just allow the edit box to be invisible and can not solve the problem. Some of the edit boxes, including scroll bars, still exist in a variety of interest but unacceptable ways. We believe that this may be attributed to the complex object structure of the edit box mentioned earlier; it seems that it is necessary to hide this distributed structure. We finally reposition it to resolve it outside the picture. With this method, we explore some other possibilities, and also studied things like control stacks and Symbian calling pop-up windows. This can make you press the button to activate the pop-up selection list. Demonstration here: iPopout = new (ELeave) CEikColumnListBox; iPopout-> ConstructL (NULL, CEikListBox :: EPopout); iPopout-> CreateScrollBarFrameL (); iPopout-> ScrollBarFrame () -> SetScrollBarVisibilityL (CEikScrollBarFrame :: EOff, CEikScrollBarFrame: : EAuto); iPopout-> SetObserver (this); TSize popoutSize = TSize (width, height); TPoint popoutOrigin = TPoint (topLeft, bottomRight); iPopout-> Model () -> SetItemTextArray (iArray); iPopout-> Model ( ) -> SetOwnershipType (ELbmDoesNotOwnItemArray); iPopout-> ItemDrawer () -> columnData () -> SetColumnWidthPixelL (0, firstColWidth); iPopout-> ItemDrawer () -> columnData () -> SetColumnWidthPixelL (1, secondColWidth); iPopout- > SetExtent (popoutOrigin, popoutSize); iPopout-> SetCurrentItemIndex (0); iEikonEnv-> AddDialogLikeControlToStackL (iPopout); iPopout-> ActivateL (); iPopout-> DrawNow (); a very old and very interesting learning experience is a must Hand writing code to refresh and display the contents of the list box. The brush code is complicated, and it is not a way to track all insertions and deletions. No matter what refresh rate, we all want the code to get the result of the correct display of the refresh process regardless of what is refreshed, and cannot throw away the position and constituency of the scroll bar, and cannot produce unnecessary flash screen and flashing. The Symbian operating system provides the feature called HandleItemOvall and HandleItemAdditionL in the Basic List box class. There is also a setcurrentItemIndex that sets the current item. However, there is no documentation on how these functions work in the version 5 of the Symbian operating system.
We can only know that the source code is implicitly used by the study source, but HandleItemRemovAll is not responsible for heavy painting. Reset called HandleItemRemovAll has to be understood by source code, and the current item index needs to be refreshed after calling HandleItemRemovAll. This dissemination of this treatment is very strange to have a lot of potential problems. But there is a good news to be included in the current Symbian operating system documentation, all of which are included in the place you can find. As other aspects of Symbian, which are previously used, in the field, in order to make the total overhead of the system as low as possible, some applications' code overhead is also taken into account. Symbian's identity is characterized by elegance and the consistency in most cases, and now it is already very good in documentation, and he makes creating smoothed graphics actions relatively simple.
8. Messages, asynchronous services and activity objects. MFC hides the Windows message examples of the WINDOWS message exemplary in the news cycle and scheduling mechanism for the primary or understanding of the message loop and scheduling mechanism. In the Symbian operating system, drive applications is a completely different and powerful mechanism, called active objects. It is closely combined with the client-server-side structure of the Symbian operating system, providing a variety of system services, and can also create a clean and standard interface for programmers to create any asynchronous services you may need to create for applications. Briefly, CACTIVESCHEDULER executes a Windows message loop, providing a shared multitasking within a given thread, and the CACTIVE (one active object) acts as a message handler. In the Symbian's UI frame, this is better than the MFC to better: the received message is always a method that can be overloaded by the framework to pre-defined - such as OfferKeyEventl (Processing Keyboard). The timer is an instance of a simple system service using the Activity Object Frame. Unlike Windows, STARTTimer is called to trigger the WM_TIMER message, and the Symbian operating system interacts by a CTIMER object with the system clock service, and the RTimer is called according to the time interval specified by the API. The programmer inherits from CTimer to an object and overloads the RUNL method. Other asynchronous system services, such as the camera function on the NOKIA 7650 is also provided by a similar method. CcaperaManager defines an active object to raise a photo operation and get a notification. The actual asynchronous service is provided by RcameraServ, but typical programmers do not need to address any client-server or explicit process communication issues. When using an active object, keep in mind that the activity object is very important to perform this very important criterion at the scheduled plan. That is to say, when will the CACTIVESCHEDULER call a CACTIVE object's Runl method? · The CACTIVE object must be "event". This is made by calling CACTIVE :: SetACTIVE, usually completed in response to an active object yourself. · The status of the CACTIVE object, indicated by the member variable iStatus, must not be Krequestpending. This value indicates that the object is waiting for the service to complete. The variable ISTATUS is usually set to Krequestpend when a service request is proposed. iStatus then updates by the server provider at the end of the service. · CACTIVESCHEDULER needs to receive a signal - the signal is issued by the asynchronous service at the end. When the essay process emits an end signal for the application, it will generate a "lost" signal when there is no CACTIVE object. This may happen in the following cases: • You forgot to use CACTIVE :: SetACTIVE to make the activity object in the "activity" state. • The service provider forgets the value of non-krequestpending when making a signal to complete the signal. This will only appear when you write the wrong service provider - typical applications use system-defined services. · The service provider issues a not only termination signal to the same operation. The third case may occur in the case where the service provider is designed to be carefully designed. For example, there is a service that has ended and informs the client, but the client is just a request to cancel the service before receiving this notification. Service providers must ignore this current unreasonable request. If the service provider does not ignore this request, but a response to it and give an additional signal saying is over, what will be? In this case, the additional signal will eventually become a "lost" signal and will cause the program error. This is very difficult for error correction, because the "lost" signal is detected by CACTIVESCHEDULER, and does not display the responsibility of the CACTIVE object.
The CACTIVE object must ensure that the termination signal associated with the service in various cases is appropriate. There should be typical in the release program with a CACTIVE :: Cancel call. If the Cancel is not called, the object is deleted when the request is still suspended, and the error will happen. Moreover, each CACTIVE object is required to ensure that any service requested by the service request is canceled. Otherwise, Cactive :: Cancel will wait for the termination signal of the service provider. Both errors are difficult to detect because they are only discovered when there is a significant request. Conclusion We hope this article will start the work under the Symbian operating system to provide a worthy expectation and useful help on the WINDOWS programmer. We expect to see how the Symbian operating system and related programming examples of this new market will develop.