Lesson 6: Component Service in CAR

Overview
While the client/server version of "Hello World" on Elastos.

HelloWorldServer.eco is the server -a CAR component which could be loaded at runtime.

Helloworld3.ecx is the client -an exacutable program with a special "ElastosMain" entry point.

Sample: HelloWorld Component as a Server
1. Create a new directory under ~/Elastos/Samples/GettingStarted. Switch into the ~/Elastos/Samples/GettingStarted directory. Create a new directory named HelloWorld3'. and create two sub-directories named HelloWorldServer and HelloWorldClient respectively.

2. Create and define the HelloWorldServer.car file under the HelloWorldServer directory. The content of the HelloWorldServer.car file is listed below.

//========================================================================== // Copyright (c) 2000-2013, Elastos, Inc. All Rights Reserved. //==========================================================================
 * HelloWorldServer.car

module {   interface IHello { Hello; }

interface IWorld { World; }

class CHelloWorldServer { interface IHello; interface IWorld; } }

3. Open ARM Android SDK tool environment.

4. Switch into ~/Elastos/Samples/GettingStarted/HelloWorld3/HelloWorldServer

5. emake HelloWorldServer.car -After emake finishes successfully, three new files will be created automatically in the same directory. The C/C++ code skeleton will already be written; it will be up to you to implement them.


 * HelloWorldServer.cpp


 * 1) include "CHelloWorldServer.h"
 * 2) include 

ECode CHelloWorldServer::Hello {   printf("Hello\n"); return NOERROR; }

ECode CHelloWorldServer::World {   printf("World\n"); return NOERROR; }


 * HelloWorldServer.h
 * 1) ifndef __CHELLOWORLDSERVER_H__
 * 2) define __CHELLOWORLDSERVER_H__


 * 1) include "_CHelloWorldServer.h"

CarClass(CHelloWorldServer) { public: CARAPI Hello;

CARAPI World;

private: // TODO: Add your private member variables here. };

TARGET_NAME= HelloWorldServer TARGET_TYPE= eco
 * 1) endif // __CHELLOWORLDSERVER_H__
 * sources

SOURCES = HelloWorldServer.car SOURCES += CHelloWorldServer.cpp

LIBRARIES = $(XDK_USER_LIB)/Elastos.Runtime.lib LIBRARIES += $(XDK_USER_LIB)/Elastos.Utility.lib LIBRARIES += $(XDK_TARGETS)/Elastos.Runtime.eco LIBRARIES += $(XDK_TARGETS)/Elastos.Utility.eco LIBRARIES += $(XDK_USER_LIB)/crt0.lib

Back