CAmkES Tutorial
- Background
The fundamentals of CAmkES are the
component
, theinterface
and theconnection
. Components are logical groupings of code and resources. They communicate with other component instances via well-defined interfaces which must be statically defined, over communication channels.
1. Components
As briefly described above, we identify a component as a functional grouping of code and resources. We use the term component in CAmkES to refer to the type of our functional grouping (see the Component section in the manual). An example of this in concrete CAmkES syntax can be seen below:
component foo {
control;
uses MyInterface a;
attribute Int b;
}
we defined a component above whose type is foo. We later can use our foo type to define a component instance. For example, the statement component foo bar refers to a component instance bar whose type is foo.
Creating your first CAmkES application
In this tutorial we will create a simple ‘Hello World’ example within the CAmkES. This will invole creating a CAmkES component that will print “Hello CAmkES World” when it starts up.
1. First thing to do
./init --tut hello-camkes-0
cd hello-camkes-0_build
ninja
2. Looking at the sources
In the tutorial directory, you will find the following files:
-
CMakeLists.txt
- the file that defines how to build our CAmkES application -
client.c
- the single source file for our ‘Hello World’ client component -
hello.camkes
- Our CAmkES file describing our static system
CMakeLists.txt :
Every CAmkES project requires a CMakeLists.txt file to be incorporated in the seL4 build system. Our tutorial directory should contain the following CMakeLists.txt file:
# @TAG(DATA61_BSD)
cmake_minimum_required(VERSION 3.7.2)
project(hello-camkes-0 C)
ImportCamkes()
DeclareCAmkESComponent(Client SOURCES client.c)
DeclareCAmkESRootserver(hello.camkes)
GenerateCAmkESRootserver()
Our CMakeLists.txt file declares our Client
component, linking it with our client.c
source file. In addition it declares the CAmkES Root Server
using our hello.camkes
system description.
client.c :
For this tutorial we require our component to simply print “Hello CAmkES World”. We define this in a typical C file client.c:
/* @TAG(DATA61_BSD) */
/*
* CAmkES tutorial part 0: just a component.
*/
#include <stdio.h>
/* generated header for our component */
#include <camkes.h>
/* run the control thread */
int run(void) {
printf("Hello CAmkES World\n");
return 0;
}
Note above that in the source code of client.c
instead of typically using main, we place our runtime code in the function int run(void). run
is the entry point of a CAmkES component.
hello.camkes :
The hello.camkes
file is where we form our description of a static CAmkES system. Our .camkes files are written using the CAmkES syntax
. Employing the concepts discussed in the background section, we define the following:
/* @TAG(DATA61_BSD) */
/*
* CAmkES tutorial part 0: just a component.
*/
component Client {
control;
}
assembly {
composition {
component Client client;
}
}
In the source above we create a minimal static system with a single component instance. We define our component Client
and declare an instance of that component in our system.
网友评论