Running an Active Object in OpenC
2010-10-17 11:50
316 查看
From Forum Nokia Wiki
http://wiki.forum.nokia.com/index.php/Running_an_Active_Object_in_OpenC
I just want to use some functions and classes of Symbian C++ in an Open C project. Because some classes are written as Active Object for asynchronisation. I am trying to find out, if it is possible to run an active class in a Open C program. And finally it works. At least on device, not yet on emulator by compiling.
Here is the code, may be someone needs it. I am using the example 'Periodic' from the SDK as the CActive class.
main.c
PeriodicTest.h
PeriodicTest.cpp
--paipeng 13:49, 20 March 2008 (EET)
http://wiki.forum.nokia.com/index.php/Running_an_Active_Object_in_OpenC
I just want to use some functions and classes of Symbian C++ in an Open C project. Because some classes are written as Active Object for asynchronisation. I am trying to find out, if it is possible to run an active class in a Open C program. And finally it works. At least on device, not yet on emulator by compiling.
Here is the code, may be someone needs it. I am using the example 'Periodic' from the SDK as the CActive class.
main.c
#include <stdio.h> #include <e32base.h> #ifdef __GCCE__ #include <staticlibinit_gcce.h> #endif #include "PeriodicTest.h" _LIT(KTxtEPOC32EX,"EPOC32EX"); void activeClassL() { CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); CPeriodicRunner* periodic = CPeriodicRunner::NewL(4); periodic->Start(); CActiveScheduler::Start(); periodic = NULL; // Delete active scheduler CleanupStack::PopAndDestroy(scheduler); } void runCActiveclass() { __UHEAP_MARK; CTrapCleanup* cleanup = CTrapCleanup::New(); TRAPD(error,activeClassL()); // more initialization, then do example __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error)); delete cleanup; __UHEAP_MARKEND; } int main() { runCActiveclass(); printf("finished!/n"); getchar(); return 0; }
PeriodicTest.h
#ifndef PERIODICTEST_H_ #define PERIODICTEST_H_ #include <e32base.h> #include <stdio.h> class CPeriodicRunner : public CActive { public: static CPeriodicRunner* NewL(TInt aTotalTicks); ~CPeriodicRunner(); // destruct and give statistics protected: CPeriodicRunner(TInt aTotalTicks); private: void ConstructL(); // second construction phase void RunL(); void DoCancel(); void DoTick(); // indirectly called public: void Start(); private: TInt iTotalTicks; RTimer timer; }; #endif /*PERIODICTEST_H_*/
PeriodicTest.cpp
#include "PeriodicTest.h" // protected C++ constructor CPeriodicRunner::CPeriodicRunner(TInt aTotalTicks) : CActive(EPriorityStandard), iTotalTicks(aTotalTicks) { } // private second-phase constructor void CPeriodicRunner::ConstructL() { timer.CreateLocal(); CActiveScheduler::Add( this ); } // construct, add CPeriodic to active scheduler, and start it CPeriodicRunner* CPeriodicRunner::NewL(TInt aTotalTicks) { CPeriodicRunner* self=new (ELeave) CPeriodicRunner(aTotalTicks); CleanupStack::PushL(self); self->ConstructL(); CleanupStack::Pop(); return self; } // destruct and give statistics CPeriodicRunner::~CPeriodicRunner() { timer.Close(); CActiveScheduler::Stop(); } void CPeriodicRunner::RunL() { if (iStatus == KErrNone) { DoTick(); } } void CPeriodicRunner::DoCancel() { } void CPeriodicRunner::Start() { timer.After(iStatus, 1000000); SetActive(); } // private void CPeriodicRunner::DoTick() { iTotalTicks--; printf("Periodic timer %d done/n", iTotalTicks); if(iTotalTicks==0) { delete this; } else { timer.After(iStatus, 1000000); SetActive(); } }
--paipeng 13:49, 20 March 2008 (EET)
相关文章推荐
- Native Client (NaCl) is an open-source technology for running native compiled code in the browser
- Remove openjdk in Ubuntu/Configure jdk and running adb in 64-bit Ubuntu
- 基于Eclipse的Perl的IDE软件EPIC出现Insecure dependency in open while running with -T switch错误!
- c++ what happens when a constructor throws an exception and leaves the object in an inconsistent state?
- the file is already open in an editor 解决方法
- 【iOS开发-27】解决方式:An error was encountered while running(Domain=FBSOpenApplicationErrorDomain, Code=4)
- An error was encountered while running (Domain = FBSOpenApplicationErrorDomain, Code = 4)
- xcode arc 下使用 block警告 Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code
- How do you make an object in C? Used in RTOS.
- How To Open An URL In Android’s Web Browser
- 运行Xcode时,提示:An error was encountered while running (Domain = FBSOpenApplicationErrorDomain, Code = 4)
- 20100507 学习记录: Server Error in '/' Application. Object reference not set to an instance of an object
- the file is already open in an editor 解决方法 .
- curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in
- 前天在一直Linux根文件系统时提示WARNING: Unable to open an in...
- 如何更改Inactive object的ownership
- [CVPR2018] An Analysis of Scale Invariance in Object Detection – SNIP
- The role of an object storage system in the cloud
- libhiredis.so.0.13: cannot open shared object file: No such file or directory in Unknown on line
- How To Open An URL In Android’s Web Browser