CASL is a software system designed with goal to provide hight-level component model of software services to application programmer.
CASL - is developed in Grad-Soft Ltd, Kiev, Ukraine in 2001.
More information can be found on our web site:
http://www.gradsoft.kiev.ua
It is just block of some functionality organized as:
Examples of CASL Service:
Appropriative UML diagram:
CASL Service is just a set of two classes:
CASL::Service
http://www.gradsoft.kiev.ua/common/Products/CASL/docs/API/Service.html
CASL::ServiceModule
Appropriative UML class diagram:
This is service, which output Hello, world on standart output.
001 #include <GradSoft/CASL.h>
002
003 /*
004 * part of CASL framework.
005 * (C) Grad-Soft Ltd, 2001
006 * http://www.gradsoft.com.ua
007 * $Id: DeploymentContainerProgrammingGuide_rus.tex,v 1.3 2001/12/20 18:05:14 rssh Exp $
008 */
009
010 /*
011 * this program illustrate how to build own service.
012 */
013
014 namespace GradSoft {
015
016 using namespace CASL;
017 using namespace std;
018
019 /**
020 * create our own service class.
021 * (what it do: check input and output files
022 **/
023 class HelloWorldService: public Service
024 {
025 public:
026
027 const char* name() const
028 { return "HelloWorld"; }
029
030 void run()
031 { cout << "Hello, world!" << endl; }
032
033 void close() {}
034
035 };
036
037 /**
038 * And ServiceModule
039 **/
040 class HelloWorldServiceModule: public ServiceModule
041 {
042 private:
043
044 // Dynamic module methods:
045
046 const char* name() const { return "HelloWorldService"; }
047 const char* author() const { return "Grad-Soft Ltd, Kiev, Ukraine"; }
048 int versionMajor() const { return 1; }
049 int versionMinor() const { return 0; }
050 int versionSubMinor() const { return 0; }
051
061 // and create service
071
081 Service* createService() { return new HelloWorldService(); }
082
083 };
084
085 // we need declare service module outside interface.
086 } // close namespace
087
088
089 GradSoft::HelloWorldServiceModule HelloWorld;
090
091 EXPORT_OBJECT(HelloWorld);
Class wich define service, printing Hello, world defined in lines
from 23 to 35.
As expected, the main work of service is placved in overloaded method run.
Also you see overloaded close method, which do nothing. CASL call this method after finishing of processing. We will describe CASL service API in details later, now let's return to out example:
In lines 40-83 you can see class, which is a Factory for our service.
Such class must be derived from class CASL::ServiceModule, which in
next step, is derived from GradSoft::DynamicModule from GradSoft
C++ ToolBox.
So, service class must implement dynamic module API in sence of
DynamicModules::ProgrammingGuide and provice method create
for creation of Service.
And at the end of file we define exported name with name, which math name of service.
Now, let's run our service. Compile HelloWorldService.cpp in shared library and create configuration file:
<?xml version="1.0"?> <!-- Configuration for running service 'Hello World' --> <CASL> <Service Name="HelloWorld" Library="libHelloWorld"> </Service> </CASL>
In which we define only this service without parameters.
Let's name it, for example, HelloWorld.xml
Now we can start this service with help of command
CASL --service-config HelloWorld.xml
As we see, this is example of service, which just do something in run, then exit (as usial program). We can imaginate other types od service behaviour:
run end expose API via additional
methods.) Examples:
requireThread to true.
In such case CASL shedule own tread for service during startup.
Appropriative simplicified UML interaction diagram :
http://www.gradsoft.kiev.ua/common/CASL/UML/DC_ThreadInteraction.png
Note, that the main document, which describe CASL API is API Reference
All CASL Exceptions must be inheriented from CASL::Error
Value API
-
is a polymorh data type, simular to
Variant in COM or Any × CORBA.
Value can be a combination of next elements:
<name,value>.
API NamedValues:
api
For creation of Value of some type you can apply appropriative static method of class Value; exists 2 ways for access to data inside value:
Value::CastMismath if this is impossible.
Value::CastMismath.
Example:
ValueProxy v = Value::createString("123");
int i = s.getAsInt();
Value::TypeMismath otherwise.
This data types represents part of string (or utf16 string) buffer. You can use them as strings, but with next pecularities:
std::auto_ptr).
We can set service parameters in CASL configuration file. For example:
<Service Name="MyService" Library="libMyLibrary"> <parameter> <name> nameOfParameter1 </name> <value> valueOfParameter1 </value> </parameter> <parameter> <name> nameOfParameter2 </name> <value> valueOfParameter2 </value> </parameter> </Service>
Service can read this parameters, using method getProperty(),
which returns object of type CASL::Value.
Typical pattern of usage:
string myParameter;
try {
myParameter = getProperty("ParamName").getAsString();
}catch(const NamedValues::NameNotFound& ex){
throw CASL::Error("Parameter 'ParamName' not set");
}
Or for non-string parameters:
int myParameter;
try {
myParameter = getProperty("ParamName").getAsInt();
}catch(const NamedValues::NameNotFound& ex){
throw CASL::Error("Parameter 'ParamName' not set");
}catch(const Value::CastMismath& ex){
throw CASL::Error("Parameter 'ParamName' must be int");
}
Developer of CASL Service can use standart CASL services and to underlying OS functionality using API of class ServerContext
For receiving ServerContext you can use protected method CASL::getServerContext which return meanfull value after initialization of Service.
We can use:
getLogger() and access methods
to logger streams are delegated into class CASL::Service
getService()
As you seen in C++ API for CASL::Service, one virtual method:
doCommand() was not described yet.
Via this method you can expose scripting API to you service, which would allow to call you service from CASL with help of scripting language, without any additional programming.