MYCP开发指南系列之:开发第一个C++ APP
2010-08-06 10:20
330 查看
1
开发第一个
C++ APP
C++ APP是MYCP
业务层组件,用于处理业务逻辑。
1.1
cspApp.cpp
文件
新建一个cspApp.cpp文件,或者利用VC
新建一个普通DLL
类型工程项目。
1.2
添加头文件
#include<CGCBase/httpapp.h>
#include
<CGCBase/cgcServices.h>
using
namespace
cgc;
1.3
实现应用服务接口
classCAppService
: public
cgcServiceInterface
{
public
:
typedef
boost::shared_ptr<CAppService> pointer;
static
CAppService::pointer create(void
)
{
return
CAppService::pointer(new
CAppService());
}
virtual
tstring serviceName(void
) const
{return
_T("AppService"
);}
protected
:
virtual
bool
callService(int
function, const
cgcValueInfo::pointer&
inParam, cgcValueInfo::pointer outParam)
{
theApplication->log(LOG_INFO,
"AppService callService = %d/n"
,
function);
return
true
;
}
virtual
bool
callService(const
tstring& function, const
cgcValueInfo::pointer& inParam, cgcValueInfo::pointer outParam)
{
theApplication->log(LOG_INFO,
"AppService callService = %s/n"
,
function.c_str());
return
true
;
}
virtual
cgcAttributes::pointer getAttributes(void
) const
{return
theAppAttributes;}
};
定义CappService
服务接口,继承于cgcServiceInterface
,实现callService
函数,getAttributes
函数用于实现组件的参数管理,详细代码请看samples/cspApp/cspApp.cpp
文件。
1.4
导出应用服务接口
extern"C"
void
CGC_API
CGC_GetService(cgcServiceInterface::pointer & outService, const
cgcValueInfo::pointer& parameter)
{
CAppService::pointer appService
= CAppService::create();
appService->initService();
outService = appService;
cgcAttributes::pointer
attributes = theApplication->getAttributes();
assert (attributes.get() !=
NULL);
theAppAttributes->setAttribute(ATTRIBUTE_NAME,
outService.get(), appService);
}
extern
"C"
void
CGC_API CGC_ResetService(cgcServiceInterface::pointer
inService)
{
if
(inService.get() == NULL) return
;
theAppAttributes->removeAttribute(ATTRIBUTE_NAME,
inService.get());
inService->finalService();
}
1.5
编译部署
编译cspApp工程,生成cspApp.dll
或者libcspApp.so
文件,复制文件到$(MYCP_BINPATH)/modules
目录。
修改$(MYCP_BINPATH)/conf/modules.xml
文件,在app
配置项增加一个组件配置项;
<app>
…
<module>
<file>cspApp</file>
<allowall>1</allowall>
</module>
…
</app>
设置组件文件,允许开放所有函数。
1.6
CSP
调用
cspApp
组件
以下内容为调用cspApp组件的CSP
代码,详细请看bin/web/samples/csp-app.csp
文件:
<csp:define type="app" id="$var_app" name="cspApp" />
<h1>Call APP Function</h1>
call $var_app "info" function.<br>
<csp:app:call id="$var_app" name="info" />
call result: <%=_$result%><br>
<br>
<b>See MYCP console print info.</b><br>
cspApp SourceCode see Samples/cspApp/cspApp.cpp<br>
<h1>APP Get/Set Function</h1>
set $var_app p1 = 1111111<br>
<csp:app:set id="$var_app" name="p1" in="1111111" />
get $var_app p1 to $var_p2<br>
<csp:app:get id="$var_app" name="p1" out="$var_p2" />
$var_p2 = <%=$var_p2%><br>
<h1>Final APP</h1>
<csp:reset id="$var_app" />
$var_app reset ok<br>
浏览器访问如下图:
1.7
配置访问
C++ APP
组件
以上例子演示如何定义一个C++ APP组件,在页面退出的时候需要清空该组件变量;为了方便开发者使用C++ APP
应用组件;MYCP
支持通过配置apps.xml
文件,部署好所有的C++ APP
应用组件,配置好的应用组件,直接在CSP
页面用A$
变量直接使用,不需要定义,和清空操作。
配置例子请看conf/HttpServer/apps.xml
文件;
使用例子请看bin/web/samples/csp-app-fs.csp
文件等例子;
1.8
总结
本节学习如何开发一个C++ APP应用组件,包括定义实现服务接口、实现接口函数、接口参数管理和导出服务接口等。
相关文章推荐
- MYCP开发指南系列之:开发第一个C++ APP
- MYCP开发指南系列之:开发第一个RCA应用组件
- MYCP开发指南系列之:开发第一个客户端程序
- MYCP开发指南系列之:开发第一个C++ Servlet
- MYCP开发指南系列之:开发第一个C++ Servlet
- Web程序员开发App系列 - 开发我的第一个App,源码下载
- Win10 UWP开发系列:使用VS2015 Update2+ionic开发第一个Cordova App
- Windows8开发指南(16)开发基于Windows8的第一个metro界面C++程序
- Windows8开发指南(16)开发基于Windows8的第一个metro界面C++程序
- Win10 UWP开发系列:使用VS2015 Update2+ionic开发第一个Cordova App
- umboy技术系列之RMS开发技术:RMS-SP2-AdministrationToolkit使用指南
- 系列:iOS开发-OC、C++以及C之间的区别
- Android开发指南-窗口小部件(App Widgets)
- Android开发指南肥鱼优化系列之(六)ActivityManager初步分析
- JNI/NDK开发指南(六)--C/C++访问Java实例变量和静态变量
- 基于Basic4android的Android应用开发指南——第一个Basic4android程序(1)
- Struts1.x系列教程(1):用MyEclipse开发第一个Struts程序
- linux C/C++开发环境搭建指南
- C/C++开发语言系列之26---C++复制(拷贝)构造函数
- C#微信公众号开发系列教程二(新手接入指南)