Running an Active Object in OpenC
来源:互联网 发布:淘宝可以办假的毕业证 编辑:程序博客网 时间:2024/05/24 00:14
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
#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)
- Running an Active Object in OpenC
- Applied Long-Running Active Object Pattern
- Active Object and sample code in symbian
- Putting an NSTextView Object in an NSScrollView
- OPENC++
- Active Object
- active object
- Process of creating an object in Java
- ways to creat an object in javascript
- How to inherit an Object in JavaScript
- How to clone an object in JavaScript
- Active Object -An Object Behavioral Pattern for Concurrent Programming 主动对象模式 (转)
- How can i check if an app running in Android?
- Inside The C++ Object Model(Note):sizeof in an object
- 干活来袭:Effective Concurrency: Know When to Use an Active Object Instead of a Mutex
- 学习记录: Server Error in '/' Application. Object reference not set to an instance of an object
- Becoming an Active Learner
- Base class for cloning an object in C#
- Android 中的长度单位详解 dp、sp、px、in、pt、mm
- 新的Symbian OS 9 可执行文件格式(E32Image)
- 构造函数和变量初始化顺序
- 团购网站 购物js
- PKU 3537
- Running an Active Object in OpenC
- Windows CE S3C2440A显示驱动编码分析
- 积分啊
- linux spi驱动分析
- c++ 动态数组的实现
- Taobao分布式文件系统TFS简析
- 汇编指令表
- 写了个监控的shell ,望指点
- Struts1.x的三种action的比较(笔记)