配置ICE开发环境
Berkeley DB expat OpenSSL bzip2 mcpp
set THIRDPARTY_HOME = d:\ice3party
nmake -f Makefile.mak STATICLIBS=yes OPTIMIZE=yes
6. 最最后,把bin目录加入path变量,以便让系统能找到ICE的dll文件(其实主要是三个dll文件,ice33.dll、iceutil33.dll和bzip2.dll)
ICE的HelloWorld
- module Demo {
- interface Printer {
- void printString(string s);
- };
- };
slice2cpp Printer.ice
下表是Slice与C++的映射关系
#include | #include |
#ifndef | #ifndef |
#define | #define |
#endif | #endif |
module | namespace |
bool | bool |
byte | Ice::Byte |
short | Ice::Short |
int | Ice::Int |
long | Ice::Long |
float | Ice::Float |
double | Ice::Double |
string | Ice::string |
enum | enum(不支持指定数字) |
struct | struct |
class | class(所有方法都是纯虚函数) |
interface | struct(所有方法都是纯虚函数,没有成员变量) |
sequence<T> | std::vector<T> |
dictionary<Key,Value> | std::map<Key,Value> |
exception Err | class Err:public Ice:UserException |
nonmutating方法限定符 | const方法 |
idempotent方法限定符 | - |
out 参数限定符 | 引用类型 |
* | 对应类型的代理类 |
- namespace Demo {
- struct Printer {
- virtual void printString(string s) = 0;
- };
- };
编写服务器端代码:
- 新建一个控制台项目
- 将$ICE\include添加到头文件目录列表中
- 将$ICE\lib\ice.lib和iceutil.lib(对应的Debug版本是iced.lib和iceutild.lib)链接入项目
- 把生成Printer.cpp加入项目
- #include <ice/ice.h>
- #include "printer.h" //slice2cpp生成的文件
- using namespace std;
- using namespace Demo;
- //实现printString方法
- struct PrinterImp : Printer{
- virtual void printString(const ::std::string& s,
- const ::Ice::Current& = ::Ice::Current())
- {
- cout << s << endl;
- }
- };
- int main(int argc, char* argv[])
- {
- Ice::CommunicatorPtr ic;
- try{
- // 初始化Ice运行库
- ic = Ice::initialize(argc, argv);
- // 建立ObjectAdapter,命名为SimplePrinterAdapter
- // 使用默认协议(一般是tcp)并在10000端口监听。
- Ice::ObjectAdapterPtr adapter
- = ic->createObjectAdapterWithEndpoints(
- "SimplePrinterAdapter", "default -p 10000");
- // 把我们实现的Printer加入ObjectAdapter,并命名为SimplePrinter
- Ice::ObjectPtr object = new PrinterImp;
- adapter->add(object, ic->stringToIdentity("SimplePrinter"));
- adapter->activate();
- // 等待直到Communicator关闭
- ic->waitForShutdown();
- }
- catch(const Ice::Exception &e){
- cerr << e << endl;
- }
- catch(const char* msg){
- cerr << msg << endl;
- }
- // 回收Ice运行库所用的资源
- if(ic) ic->destroy();
- return 0;
- }
客户端代码:
- #include <ice/ice.h>
- #include <printer.h>
- using namespace std;
- using namespace Demo;
- int main(int argc, char* argv[])
- {
- Ice::CommunicatorPtr ic;
- try{
- // 初始化Ice运行库
- ic = Ice::initialize(argc, argv);
- // 在10000端口取得SimplePrinter代理对象
- Ice::ObjectPrx base = ic->stringToProxy("SimplePrinter:default -p 10000");
- // 把对象转换成Printer代理
- PrinterPrx printer = PrinterPrx::checkedCast(base);
- if(!printer) throw "Invalid Proxy!";
- // 能过这个代码调用printString方法
- printer->printString("Hello World!");
- }
- catch(const Ice::Exception &e){
- cerr << e << endl;
- }
- catch(const char* msg){
- cerr << msg << endl;
- }
- // 回收Ice运行库所用的资源
- if(ic) ic->destroy();
- return 0;
- }
使用Ice::Application简化代码的编写
virtual int run(int, char*[]) = 0;
服务器端:
- #include <ice/ice.h>
- #include "printer.h"
- using namespace std;
- using namespace Demo;
- struct PrinterImp : Printer{
- virtual void printString(const ::std::string& s, const ::Ice::Current& = ::Ice::Current())
- {
- cout << s << endl;
- }
- };
- class MyApp : public Ice::Application{
- public:
- virtual int run(int, char*[]){
- Ice::CommunicatorPtr& ic = communicator();
- Ice::ObjectAdapterPtr adapter
- = ic->createObjectAdapterWithEndpoints(
- "SimplePrinterAdapter", "default -p 10000");
- Ice::ObjectPtr object = new PrinterImp;
- adapter->add(object, ic->stringToIdentity("SimplePrinter"));
- adapter->activate();
- ic->waitForShutdown();
- return 0;
- }
- };
- int main(int argc, char* argv[])
- {
- MyApp app;
- return app.main(argc, argv);
- }
客户端:
- #include <ice/ice.h>
- #include <printer.h>
- using namespace std;
- using namespace Demo;
- class MyApp: public Ice::Application{
- public:
- virtual int run(int, char*[])
- {
- Ice::CommunicatorPtr ic = communicator();
- Ice::ObjectPrx base = ic->stringToProxy("SimplePrinter:default -p 10000");
- PrinterPrx printer = PrinterPrx::checkedCast(base);
- if(!printer) throw "Invalid Proxy!";
- printer->printString("Hello World!");
- }
- };
- int main(int argc, char* argv[])
- {
- MyApp app;
- return app.main(argc,argv);
- }
相关推荐
第 6 章 客户端的 Slice-to-C++ 映射 第 7 章开发 C++ 文件系统客户 第 8 章 客户端的 Slice-to-Java 映射 第 9 章开发 Java 文件系统客户 第 10 章 服务器端的 Slice-to-C++ 映射 第 11 章开发 C++ 文件系统服务器 ...
第 6 章 客户端的 Slice-to-C++ 映射 143 6.1 本章综 143 6.2 引言 143 6.3 标识符的映射 144 6.4 模块的映射 144 6.5 Ice 名字空间 145 6.6 简单内建类型的映射 146 6.7 用户定义类型的映射 146 6.8 常量的映射 150...
* Slice 语言:Slice 语言是 Ice 的一种描述语言,用于定义接口、数据类型和异常处理机制。 Terminology 在 Ice 架构模型中,存在一些重要的术语: * Interface:接口是指在 Slice 语言中定义的接口,用于描述一...
string和slice.go
application in C++, Java, C#, Visual Basic, and Python. • Part II, Slice, explains the Slice definition language. After reading this part, you will have detailed knowledge of how to specify ...
平台编译环境:VS2017 ICE版本:3.7.7 ICEbuilder:5.0.9 源码中有两套程序: Server:启动服务器,等待连接 。连接后可双方通信 Client:连接服务器,与服务器通讯。...Slice: 手写几个接口即可。
ICE异步调用Demo(slice源码和C++源码) 服务器和客户端adm ami函数调用与异步分发 vs2008+ice3.4.1
Ice通过与编程语言无关的中立语言Slice(Specification Language fro Ice)来描述服务的接口,从而达到对象接口与其实现想分离的目的。 目前Ice平台支持客户端API的语言有C++、.NET、Java、Python、Object-C、...
Internet 通信引擎 (Ice) 为开发任务关键型网络应用程序提供了一个强大的、经过验证的平台。让 Ice 处理所有底层细节,例如网络连接、序列化和并发性,以便您可以专注于应用程序逻辑。...从 Slice 到 Python 的直观映射
slice2js gulp-ice-builder调用slice2js编译器。 您可以使用以下命令安装最新的 : npm install slice2js --save-dev 用法 const iceBuilder = require ( 'gulp-ice-builder' ) ; gulp . task ( "slice2js" , ( ) ...
中间件技术是计算机硬件和操作系统之上支持应用软件开发和运行的系统软件。它能够使应用软件相对独立于计算机硬件和操作系统平台。中间件具有标准的程序接口和协议,可以实现不同硬件和操作系统平台上的数据共享和...
NULL 博文链接:https://zhaoningbo.iteye.com/blog/1071365
qt使用ice时需要的代码转换工具。之前网上的版本最多支持到qt4.3,本版本支持qt5.3.0 ice3.5.1,应该是目前最新的版本。修改和增加的功能是手动修改的,并不一定适用所有项目,需要根据具体情况修改部分代码。
Ice通过与编程语言无关的中立语言Slice(Specification Language fro Ice)来描述服务的接口,从而达到对象接口与其实现想分离的目的。 目前Ice平台支持客户端API的语言有C++、.NET、Java、Python、Object-C、...
NULL 博文链接:https://zhaoningbo.iteye.com/blog/1135564
eclipse Slice2Java 控件 jar ,eclipse Slice2Java 控件 jar
Philips 机器进行BOLD-fMRI扫描时的扫描顺序选择卡说明,建议扫描前阅读,使用适当的slice order,也有利于在以后进行数据处理时输入正确的slice order
slice2js 将Slice文件编译为JavaScript。 安装 npm install slice2js --save-dev... 将DIR添加到Slice文件的包含路径。 -E 在标准输出上打印预处理器输出。 --stdout 将生成的代码打印到stdout。 --output-dir DI