Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************************[libaroma]*
- * Copyright (C) 2011-2015 Ahmad Amarullah (http://amarullz.com/)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *______________________________________________________________________________
- *
- * Filename : aromart_core.c
- * Description : AROMA Runtime core source
- *
- * + This is part of libaroma, an embedded ui toolkit.
- * + 27/06/15 - Author(s): Ahmad Amarullah
- *
- */
- #ifndef __libaromart_core_c__
- #define __libaromart_core_c__
- #include "aromart_internal.h"
- static LART _lart={0};
- /* get aroma runtime instance */
- LART * lart(){
- return &_lart;
- }
- /* init runtime */
- byte lart_init_runtime(){
- int host_pipes[2];
- int remote_pipes[2];
- pipe(host_pipes);
- pipe(remote_pipes);
- lart()->mpid = getpid();
- pid_t pid = fork();
- if (pid==0){
- /* system ui */
- lart()->spid = getpid();
- lart()->rfd = remote_pipes[0];
- lart()->wfd = host_pipes[1];
- close(remote_pipes[1]);
- close(host_pipes[0]);
- return 2; /* sysui process */
- }
- else if (pid){
- lart()->spid = pid;
- lart()->rfd = host_pipes[0];
- lart()->wfd = remote_pipes[1];
- close(host_pipes[1]);
- close(remote_pipes[0]);
- return 1; /* manager process */
- }
- return 0; /* failed */
- }
- /* start runtime */
- int lart_start(
- LART_APP_RUN_HANDLER run_handler,
- LART_SYSTEM_UI_HANDLER sysui_handler
- ){
- byte process_type = lart_init_runtime();
- if (process_type==2){
- /* sys ui */
- int ret=lart_sysui(sysui_handler);
- exit(ret);
- return 0;
- }
- else if (process_type==1){
- /* app manager */
- return lart_app_manager(run_handler);
- }
- return 0;
- }
- #endif /* __libaromart_core_c__ */
- /********************************************************************[libaroma]*
- * Copyright (C) 2011-2015 Ahmad Amarullah (http://amarullz.com/)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *______________________________________________________________________________
- *
- * Filename : aromart_app.c
- * Description : AROMA Runtime application handler
- *
- * + This is part of libaroma, an embedded ui toolkit.
- * + 27/06/15 - Author(s): Ahmad Amarullah
- *
- */
- #ifndef __libaromart_app_c__
- #define __libaromart_app_c__
- #include "aromart_internal.h"
- /* application instance */
- static LARTAPP * _lart_app = NULL;
- /* run callback */
- static LART_APP_RUN_HANDLER _lart_app_run_cb=NULL;
- /* get application instance */
- LARTAPP * lart_app(){
- return _lart_app;
- }
- /* run application */
- int lart_app_run(char * program, char * param){
- if (_lart_app_run_cb){
- return _lart_app_run_cb(program, param);
- }
- LARTLOGE("No Application Callback...");
- return -1;
- }
- /* application command */
- byte lart_app_command(
- byte cmd,
- dword param,
- voidp data,
- size_t data_len,
- dwordp res_param,
- voidp * res_data,
- size_t * res_data_len
- ){
- if (!lart_app()){
- return LART_RES_ERR;
- }
- return lart_command(
- lart_app()->wfd,
- lart_app()->rfd,
- cmd,
- param,
- data,
- data_len,
- res_param,
- res_data,
- res_data_len
- );
- }
- /* create new application */
- pid_t lart_app_create(
- int appid,
- char * program,
- char * param,
- int wfd,
- int rfd,
- int efd,
- int dpi
- ){
- pid_t apid = fork();
- if (apid==0){
- int app_ret = -1;
- _lart_app = (LARTAPP *) calloc(sizeof(LARTAPP),1);
- _lart_app->aid = appid;
- _lart_app->pid = getpid();
- _lart_app->wfd = wfd;
- _lart_app->rfd = rfd;
- _lart_app->efd = efd;
- _lart_app->dpi = dpi;
- {
- char canvas_name[256];
- snprintf(canvas_name,256,"@appfb-%i",appid);
- _lart_app->cfb = libaroma_canvas_shmem_open(canvas_name);
- snprintf(canvas_name,256,"@appsb-%i",appid);
- _lart_app->csb = libaroma_canvas_shmem_open(canvas_name);
- }
- if (_lart_app->cfb&&_lart_app->csb){
- LARTLOGI("INIT NEW APPLICATION (id:%i,pid:%i,path:%s)",
- _lart_app->aid, _lart_app->pid, program?program:""
- );
- if (lart_libaroma_start()){ /* now init app libaroma */
- /* run application */
- app_ret = lart_app_run(program, param);
- }
- lart_libaroma_end();
- }
- else{
- LARTLOGE("NEW APPLICATION ERROR - Cannot open shared canvas "
- "(id:%i,pid:%i,path:%s)",
- _lart_app->aid, _lart_app->pid, program?program:""
- );
- }
- /* close canvases */
- if (_lart_app->cfb){
- libaroma_canvas_free(_lart_app->cfb);
- }
- if (_lart_app->csb){
- libaroma_canvas_free(_lart_app->csb);
- }
- /* send exit message */
- lart_app_command(LART_REQ_CMD_EXIT,0,NULL,0,NULL,NULL,NULL);
- /* exit log */
- LARTLOGI("APPLICATION EXITED (id:%i,pid:%i,path:%s)",
- _lart_app->aid, _lart_app->pid, _lart_app->program
- );
- /* free application instance */
- free(_lart_app);
- _lart_app=NULL;
- exit(app_ret);
- }
- return apid;
- }
- /* start app manager */
- int lart_app_manager(
- LART_APP_RUN_HANDLER run_handler
- ){
- byte running = 1;
- int res=0;
- _lart_app_run_cb = run_handler;
- while (running){
- dword param = 0;
- voidp data = NULL;
- size_t len = 0;
- byte status = lart_rrecv(¶m, data, &len);
- switch (status){
- case LART_ROOT_MSG_CREATE_APP:
- {
- LART_NEW_APP_RES_DATA res={0};
- res.aid = 0;
- res.pid = -1;
- if ((len==sizeof(LART_NEW_APP_DATA))&&(data)){
- LART_NEW_APP_DATA * reqapp = (LART_NEW_APP_DATA *) data;
- res.aid = reqapp->appid;
- res.pid = lart_app_create(
- reqapp->appid,
- reqapp->program,
- reqapp->param,
- reqapp->wfd,
- reqapp->rfd,
- reqapp->efd,
- reqapp->dpi
- );
- lart_rsend(
- LART_ROOT_MSG_CREATE_APP_RES,
- 1 /* processed */, &res, sizeof(LART_NEW_APP_RES_DATA)
- );
- }
- else{
- lart_rsend(
- LART_ROOT_MSG_CREATE_APP_RES,
- 0, NULL, 0 /* failed - bad message */
- );
- }
- }
- break;
- case LART_ROOT_MSG_TERMINATED:
- {
- /* terminate runtime */
- running = 0;
- res = (int) param;
- }
- break;
- }
- if (len>0){
- free(data);
- data=NULL;
- len=0;
- }
- }
- return res;
- }
- #endif /* __libaromart_app_c__ */
- /********************************************************************[libaroma]*
- * Copyright (C) 2011-2015 Ahmad Amarullah (http://amarullz.com/)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *______________________________________________________________________________
- *
- * Filename : aromart_sysui.c
- * Description : AROMA Runtime system ui
- *
- * + This is part of libaroma, an embedded ui toolkit.
- * + 27/06/15 - Author(s): Ahmad Amarullah
- *
- */
- #ifndef __libaromart_sysui_c__
- #define __libaromart_sysui_c__
- #include "aromart_internal.h"
- /* start sysui */
- int lart_sysui(LART_SYSTEM_UI_HANDLER sysui_handler){
- int res=0;
- if (libaroma_start()){
- ... sys ui stuff ...
- }
- libaroma_end();
- return res;
- }
- #endif /* __libaromart_sysui_c__ */
- /********************************************************************[libaroma]*
- * Copyright (C) 2011-2015 Ahmad Amarullah (http://amarullz.com/)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *______________________________________________________________________________
- *
- * Filename : aromart_driver.c
- * Description : AROMA Runtime client driver
- *
- * + This is part of libaroma, an embedded ui toolkit.
- * + 27/06/15 - Author(s): Ahmad Amarullah
- *
- */
- #ifndef __libaromart_driver_c__
- #define __libaromart_driver_c__
- #include "aromart_internal.h"
- /* hid event message */
- typedef struct{
- byte type;
- int key;
- byte state;
- int x;
- int y;
- byte ret;
- } LART_HID_EVENT;
- /* static driver variable */
- static int _lart_hid_rfd =0;
- static int _lart_hid_wfd =0;
- static int _lart_hid_active=0;
- /* Framebuffer Driver */
- byte lart_fb_release(LIBAROMA_FBP me){ return 1; }
- byte lart_fb_start_post(LIBAROMA_FBP me){ return 1; }
- byte lart_fb_post(
- LIBAROMA_FBP me, wordp __restrict src,
- int dx, int dy, int dw, int dh,
- int sx, int sy, int sw, int sh
- ){
- return 1;
- }
- byte lart_fb_end_post(LIBAROMA_FBP me){
- return lart_app_command(LART_REQ_CMD_FB_SYNC,0,NULL,0,NULL,NULL,NULL);
- }
- byte lart_fb_init(LIBAROMA_FBP me){
- me->internal = NULL;
- me->release = &lart_fb_release;
- me->w = lart_app()->cfb->w;
- me->h = lart_app()->cfb->h;
- me->sz = me->w*me->h;
- me->start_post = &lart_fb_start_post;
- me->end_post = &lart_fb_end_post;
- me->post = &lart_fb_post;
- me->snapshoot = NULL;
- me->config = NULL;
- me->dpi = lart_app()->dpi;
- me->double_buffer = 1;
- me->internal_canvas = 1;
- me->canvas = lart_app()->cfb;
- return 1;
- }
- /* HID Driver */
- void lart_hid_post(
- byte type,
- int key,
- byte state,
- int x,
- int y,
- byte ret){
- if (_lart_hid_active){
- LART_HID_EVENT ev={0};
- ev.type=type;
- ev.key=key;
- ev.state=state;
- ev.x=x;
- ev.y=y;
- ev.ret=ret;
- write(_lart_hid_wfd,&ev,sizeof(LART_HID_EVENT));
- }
- }
- void lart_hid_release(LIBAROMA_HIDP me){
- if (_lart_hid_active){
- _lart_hid_active=0;
- lart_hid_post(0,0,0,0,0,LIBAROMA_HID_EV_RET_EXIT);
- close(_lart_hid_wfd);
- }
- }
- byte lart_hid_getinput(LIBAROMA_HIDP me, LIBAROMA_HID_EVENTP dest_ev){
- LART_HID_EVENT ev;
- while(_lart_hid_active){
- if (read(_lart_hid_rfd,&ev,sizeof(LART_HID_EVENT))==sizeof(LART_HID_EVENT)){
- if (ev.ret==LIBAROMA_HID_EV_RET_EXIT){
- break;
- }
- dest_ev->type=ev.type;
- dest_ev->key=ev.key;
- dest_ev->state=ev.state;
- dest_ev->x=ev.x;
- dest_ev->y=ev.y;
- return ev.ret;
- }
- }
- close(_lart_hid_rfd);
- return LIBAROMA_HID_EV_RET_EXIT;
- }
- byte lart_hid_init(LIBAROMA_HIDP me){
- if (_lart_hid_active){
- return 0;
- }
- int pipes[2];
- pipe(pipes);
- me->internal = NULL;
- me->release = &lart_hid_release;
- me->getinput = &lart_hid_getinput;
- _lart_hid_rfd = pipes[0];
- _lart_hid_wfd = pipes[1];
- _lart_hid_active = 1;
- return 1;
- }
- /* libaroma app scope start & end function */
- byte lart_libaroma_start(){
- /* set custom initializer */
- libaroma_fb_set_initializer(lart_fb_init);
- libaroma_hid_set_initializer(lart_hid_init);
- if (!libaroma_fb_init()) {
- LARTLOGE("lart_libaroma_start cannot start framebuffer...");
- return 0;
- }
- if (!libaroma_font_init()) {
- LARTLOGE("lart_libaroma_start cannot start font engine...");
- return 0;
- }
- if (!libaroma_hid_init()) {
- LARTLOGE("lart_libaroma_start cannot start hid engine...");
- return 0;
- }
- if (!libaroma_msg_init()) {
- LARTLOGE("lart_libaroma_start cannot start message queue...");
- return 0;
- }
- if (!libaroma_lang_init()) {
- LARTLOGE("lart_libaroma_start cannot start language engine...");
- return 0;
- }
- if (!libaroma_timer_init()) {
- LARTLOGE("lart_libaroma_start cannot start timer engine...");
- return 0;
- }
- if (!libaroma_wm_init()){
- LARTLOGE("lart_libaroma_start cannot start window manager...");
- return 0;
- }
- return 1;
- }
- void lart_libaroma_end(){
- libaroma_wm_release();
- libaroma_timer_release();
- libaroma_lang_release();
- libaroma_msg_release();
- libaroma_hid_release();
- libaroma_font_release();
- libaroma_fb_release();
- }
- #endif /* __libaromart_driver_c__ */
Advertisement
Add Comment
Please, Sign In to add comment