You Are Here:

Community: Wiki

This page was last modified on 7 September 2009, at 07:17.

Creating C Python extensions using Carbide.c++

From Forum Nokia Wiki

Reviewer Approved   

Contents

Overview

This tutorial explains how to make PyS60 extensions using Carbide.c++.

Preconditions

First, install the Nokia S60 Platform SDKs for Symbian OS, which can be found here. (In this tutorial we used the S60 3rd Edition, FP2 v1.1 SDK). These SDKs contain some files needed to compile the extension. However, they do not contain Python files, such as python.h and python222.lib. To add these important files, install the Python for S60 SDKs on an installed S60 SDK. First, get PythonForS60_X_X_X_SDK_3rdEd.zip here, where X is the version of the package (in this tutorial we used PyS60 v1.4.5). Next, unzip the contents of the internal zip file (named sdk_files.zip) into the SDK folder (in this case, C:\S60\devices\S60_3rd_FP2_SDK_v1.1). This operation will add Python files to the D:\S60\devices\S60_3rd_FP2_SDK_v1.1\epoc32 folder.

After installing the SDK and Python files, install Carbide.c++, which is an excellent integrated development environment (IDE) to create C/C++ software for the S60 platform. The Carbide.c++ installation file can be found here.


Importing the example

Now, get the example package here and unzip it.

Open Carbide.c++ and go to File->;Import. Chose Symbian OS->;Symbian OS Bld.inf file and click the Next button.


Image:Project1.JPG

Browse the bld.inf file, which is in the group folder located in the unzipped example package and click Next.

Image:Bldinf.JPG

Choose Phone Release (GCCE) and click Next and Finish.

Image:Gcce.JPG

Now you can see the example files.

Image:Files.JPG

This is a very simple example showing an empty information note.

Analysing the example

The project includes, the most important files to be analyzed here are none.h and none.cpp.

In the none.h file we have included a few useful header files.

  • e32base.h: For CBase;
  • e32std.h: For descriptors;
  • aknnotewrappers.h: For notes (remember, our example uses an information note);
  • Python.h: For Python issues;
  • symbian_python_ext_util.h: For error handling.
#ifndef __NONE_H__
#define __NONE_H__
 
// Include Files
 
#include // CBase
#include // TBuf
#include
#include "Python.h"
#include "symbian_python_ext_util.h"
 
// Class Definitions
 
class Cnone : public CBase
{
public:
// new functions
IMPORT_C static Cnone* NewL();
IMPORT_C static Cnone* NewLC();
IMPORT_C ~Cnone();
 
public: // new functions, example API
IMPORT_C void ShowConfirmationNote();
 
private: // new functions
Cnone();
void ConstructL();
 
private: // data
};
 
#endif // __NONE_H__

Other items in this file are constructors and methods definitions, such as the ShowConfirmationNote() method.

In the none.cpp file you can see the include statement of none.h. Going down, you’ll see the ShowConfirmationNote() method, which only calls the ExecuteLD() method of a CAknInformationNote object. This function does what we want (the execution of an empty information note), but it cannot be called directly from Python. Thus, you must create a function that is callable from Python. This function receives Python parameters, converts these parameters to C language, calls Symbian C++ methods, and returns a Python object to the caller.

#include "none.h"	// Cnone
#include "none.pan" // panic codes
 
// Member Functions
 
EXPORT_C Cnone* Cnone::NewLC()
{
Cnone* self = new (ELeave) Cnone;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
EXPORT_C Cnone* Cnone::NewL()
{
Cnone* self = Cnone::NewLC();
CleanupStack::Pop(self);
return self;
}
 
Cnone::Cnone()
// note, CBase initialises all member variables to zero
{
}
 
void Cnone::ConstructL()
{
}
 
EXPORT_C Cnone::~Cnone()
{
}
 
EXPORT_C void Cnone::ShowConfirmationNote()
{
CAknInformationNote* dialog = new(ELeave)CAknInformationNote();
dialog->ExecuteLD();
}
 
static PyObject* show_note(PyObject* /*self*/, PyObject* args)
{
 
TInt error;
Cnone* obj = Cnone::NewL();
TRAP(error, obj->ShowConfirmationNote());
if (error)
return SPyErr_SetFromSymbianOSErr(error);
delete obj;
Py_INCREF(Py_None);
return Py_None;
}
 
static const PyMethodDef none_methods[] =
{
{
"show_note", (PyCFunction)show_note, METH_VARARGS, "shows a note."
},
{
0, 0
}
};
 
DL_EXPORT(void) init_none()
{
Py_InitModule("none", (PyMethodDef*) none_methods);
}

The show_note function receives two PyObject parameters. The first is the self parameter and the second is the tuple containing arguments. In the body of this function we call the ShowConfirmationNote method into a TRAP. The TRAP pulls a nonzero error code into an integer if an error has occurred. The SPyErr_SetFromSymbianOSErr(error) statement is called if an error has occurred. It just converts Symbian OS errors to Python errors. If no errors occurred, the note will be displayed and the function will return a Py_None.

Next, we have a PyMethodDef, which is a table containing Python function names to their C function implementations. It also has a flag telling the interpreter the calling convention to be used for the C function. Normally it should always be "METH_VARARGS" or "METH_VARARGS | METH_KEYWORDS". If you wish to add more functions, you will need to add these functions to this table.

The next function is init_none(). This function passes the method table to the interpreter in the module's initialisation function. The initialisation function must be named initname(), where name is the name of the module and should be the only non-static item defined in the module file. It calls the function Py_InitModule, which receives the module name and table name described above.

Building the example

First, using Carbide.c++, go to the group folder and open none.mmp file. In the Overview tab we have Target name (none.pyd), Target type (DLL), and UID 2 (must be 0x1000008d).

Image:Overview.JPG

Open the Libraries tab and add euser.lib, python222.lib, avkon.lib, eikcdlg.lib, and eikctl.lib libraries.

Image:Libraries.JPG

Open the Options tab and add these paths to System includes (under Compiler Settings): \epoc32\include, \epoc32\include\libc and \epoc32\include\python. Also add these capabilities: LocalServices, NetworkServices, ReadUserData, UserEnvironment, and WriteUserData.

Image:Mmpoptions.JPG

Go to menu Project->Properties. Then expand the Carbide.c++ option and select Build Configurations.

Image:Pkgproperties.JPG

On the SIS Builder tab, click the Add button and browse the ‘.pkg’ file (which is under sis folder). Choose the Output File Name and select the Don't sign sis file. Click the OK button.

Image:Sisoptions.JPG

Go to menu Project->Freeze Exports. Finally, go to menu Project->Build Project.

Postconditions

If everything runs without problems, the sis file will be created and placed inside the sis folder.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fAE5fsimpleE5ftimeoutE5fapplicationX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxAE20simpleE20timeoutE20applicationE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZpythonQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f60QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d06X qfnZuserE5ftagQSxbindingX qfnZuserE5ftagQSxchangeX qfnZuserE5ftagQSxkeyX qfnZuserE5ftagQSxpythonX qfnZuserE5ftagQSxpythonX qfnZuserE5ftagQSxs60X qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ