Running an Active Object in OpenC

本文介绍如何在 OpenC 项目中使用 Symbian C++ 的 ActiveObject 类实现异步操作。通过示例代码展示了创建并运行周期性任务的方法。

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)

内容概要:本文系统阐述了企业新闻发稿在生成式引擎优化(GEO)时代下的全渠道策略与效果评估体系,涵盖当前企业传播面临的预算、资源、内容与效果评估四大挑战,并深入分析2025年新闻发稿行业五大趋势,包括AI驱动的智能化转型、精准化传播、首发内容价值提升、内容资产化及数据可视化。文章重点解析央媒、地方官媒、综合门户和自媒体四类媒体资源的特性、传播优势与发稿策略,提出基于内容适配性、时间节奏、话题设计的策略制定方法,并构建涵盖品牌价值、销售转化与GEO优化的多维评估框架。此外,结合“传声港”工具实操指南,提供AI智能投放、效果监测、自媒体管理与舆情应对的全流程解决方案,并针对科技、消费、B2B、区域品牌四大行业推出定制化发稿方案。; 适合人群:企业市场/公关负责人、品牌传播管理者、数字营销从业者及中小企业决策者,具备一定媒体传播经验并希望提升发稿效率与ROI的专业人士。; 使用场景及目标:①制定科学的新闻发稿策略,实现从“流量思维”向“价值思维”转型;②构建央媒定调、门户扩散、自媒体互动的立体化传播矩阵;③利用AI工具实现精准投放与GEO优化,提升品牌在AI搜索中的权威性与可见性;④通过数据驱动评估体系量化品牌影响力与销售转化效果。; 阅读建议:建议结合文中提供的实操清单、案例分析与工具指南进行系统学习,重点关注媒体适配性策略与GEO评估指标,在实际发稿中分阶段试点“AI+全渠道”组合策略,并定期复盘优化,以实现品牌传播的长期复利效应。
【EI复现】基于主从博弈的新型城镇配电系统产消者竞价策略【IEEE33节点】(Matlab代码实现)内容概要:本文介绍了基于主从博弈理论的新型城镇配电系统中产消者竞价策略的研究,结合IEEE33节点系统进行建模与仿真分析,采用Matlab代码实现。研究聚焦于产消者(兼具发电与用电能力的主体)在配电系统中的竞价行为,运用主从博弈模型刻画配电公司与产消者之间的交互关系,通过优化算法求解均衡策略,实现利益最大化与系统运行效率提升。文中详细阐述了模型构建、博弈机制设计、求解算法实现及仿真结果分析,复现了EI期刊级别的研究成果,适用于电力市场机制设计与智能配电网优化领域。; 适合人群:具备电力系统基础知识和Matlab编程能力,从事电力市场、智能电网、能源优化等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①学习主从博弈在电力系统中的建模方法;②掌握产消者参与电力竞价的策略优化技术;③复现EI级别论文的仿真流程与结果分析;④开展配电网经济调度与市场机制设计的相关课题研究。; 阅读建议:建议读者结合提供的Matlab代码,深入理解博弈模型的数学表达与程序实现细节,重点关注目标函数构建、约束条件处理及算法收敛性分析,可进一步拓展至多主体博弈或多时间尺度优化场景。
f:\myopencv\myproject\app.py:130: SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma? ('��ֵ������', self.threshold_debug, 'disabled') # ��ֵ�����԰�ť Traceback (most recent call last): File "f:\myopencv\myproject\app.py", line 249, in <module> a = app(window, 'ͼ��������') # ��ʼ��Ӧ�� ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "f:\myopencv\myproject\app.py", line 36, in __init__ self.tool_buttons = self.init_toolbar() ^^^^^^^^^^^^^^^^^^^ File "f:\myopencv\myproject\app.py", line 130, in init_toolbar ('��ֵ������', self.threshold_debug, 'disabled') # ��ֵ�����԰�ť ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'tuple' object is not callable [Done] exited with code=1 in 0.287 seconds [Running] python -u "f:\myopencv\myproject\app.py" f:\myopencv\myproject\app.py:130: SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma? ('��ֵ������', self.threshold_debug, 'disabled') # ��ֵ�����԰�ť Traceback (most recent call last): File "f:\myopencv\myproject\app.py", line 249, in <module> a = app(window, 'ͼ��������') # ��ʼ��Ӧ�� ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "f:\myopencv\myproject\app.py", line 36, in __init__ self.tool_buttons = self.init_toolbar() ^^^^^^^^^^^^^^^^^^^ File "f:\myopencv\myproject\app.py", line 130, in init_toolbar ('��ֵ������', self.threshold_debug, 'disabled') # ��ֵ�����԰�ť ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'tuple' object is not callable
03-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值