两种类型的资源探测器

xml文件资源探测器

目录资源探测器

系统内置的资源探测器(核心)

数据库定义目录资源探测器  -base_application_datable  关注dbschema  

service资源探测器  -base_application_service  关注services.xml  

语言包资源探测器  -base_application_lang

缓存更新探测器  -base_application_cache_expires

位置解释

base-》app名称

application-》lib/application

datable-》datable.php文件

其余的资源探测器,都通过service的形式注册,注册点为app_content_detector (detector探测器的意思)

这里怎么实现的过会再说???

查看系统里目前已注册的资源探测器

dev:show services | grep -i app_content_detector (dev:show services 所有注册的service,grep -i app_content_detector从这些注册的service中找资源探测器)//这个命令只适合与linux

windows命令未找到,等找到会补上---------------------------------------------------???

资源探测器开放!!!

级联结构

Iterator(迭代器)接口

base_application_prototype_content 使用 Iterator 接口(implements)  

位置app/base/lib/application/prototype/content.php 

base_application_prototype_filepath 继承 base_application_prototype_content

base_application_prototype_xml 继承 base_application_prototype_content

filepath.php提供可以遍历目录里所有文件或目录的接口

xml.php提供可以遍历xml文件下某个节点下所有子节点的接口

例子

开发xml文件资源探测器

desktop作为例子

菜单探测器针对desktop.xml内寻找permissions下所有permission子节点

<desktop>
<permissions>
<permission id="shopsetting" display='true'>商店设置 </permission>
<permission id="setting" display='true'>数据管理</permission>
<permission id="performance" display='true'>缓存,队列,计划任务管理</permission>
<permission id="users" display='true'>权限管理</permission>
<permission id="other" display='true'>其他</permission>
</permissions> </desktop>

建立探测器类文件(那个app下探测什么,该探测器继承与那类探测器)

<?php
class desktop_application_permission extends base_application_prototype_xml{
}

位置app/desktop/lib/application/permission.php

注册成service

在service中进行注册

app/desktop/desktop.xml(配置文件)(app_conetent_detector  service box id意思)

<services>
...
<service id="app_content_detector">
<class>desktop_application_permission</class>
</service>
...
</services>

补充desktop_application_permission类

<?php
class desktop_application_permission extend base_application_prototype_xml{
var $xml='desktop.xml';//指定要探测的xml资源文件,本例中会调用app/desktop/desktop.xml
var $xsd='desktop_content';//指定xml对应的xsd位置,本例是app/desktop/xmlschema/content.xsd(为何不是desktop_xmlschema_content)
var $path='permissions/permission';//指定xml节点
}

desktop.xml下permissions节点下所有permission子节点

current

设置当前遍历子节点的内容$current和当前元素的键$key

通过$this->iterator()->current()可以获取当前xml子节点的array数据

本例中是当前permissions/permission节点数据

<?php
class desktop_application_permission extends base_application_prototype_xml{
function current(){
$this->current = $this->iterator->current();
$this->key = $this->current['id'] ;
return $this;
}
}

install

install app_name时调用

需要重载,安装当前遍历节点的数据

<?php
class desktop_application_permission extend base_application_prototype_xml{
function row(){
$row = array(
'menu_type'=>$this->content_typename();
'app_id'=>$this->target_app->app_id
);
$row['menu_title']=$this->current['value'];
$row['display'] = $this->current['display'];
$access_opct=array(
'show'=>$this->current['show'],
'save'=>$this->current['save']
);
$row['addon']=serialize($access_opct);
$row['permission']=$this->current['id']//$this->key;
return $row;
}
   function install(){
     kernel:log('Installing'.$this->content_typename().' '.$this->key());
     return app:get('desktop')->model('menus')->insert($this->row());
   }  
}

到这里就解释了资源探测器的作用了,探测资源,获取资源,操作资源

clear_by_app

资源卸载,在uninstall app_name时调用

<?php
class desktop_application_permission extends base_application_prototype_xml {
function clear_by_app($app_id){
if(!$app_id){
return false;
}
app::get('desktop')->model('menus')->delete(array(
'app_id'=>$app_id,'menu_type' => $this->content_typename()));
}

update

资源更新 update app_name时调用 不需要重载(基类有这个函数)

active_by_app

active app_name时调用 不需要重载(基类有这个函数)

pause_by_app

pause app_name时调用 不需要重载(基类有这个函数)

如何开发目录型资源探测器

类似

去掉$xml和$xsd属性

去掉current()函数,基类提供的函数默认设置$key为文件名/目录名

增加filter()函数,可以只遍历$path目录下关注的文件和目录

增加getPathname(),可以取得当前节点的目录名

增加getFilename(),可以取得当前节点的文件名

ecos资源探测器的更多相关文章

  1. eCos中的线程与同步

    http://blog.csdn.net/ooaven/article/details/6280018 先看一下eCos线程的创建.控制以及优先级的操作这三个方面的知识,主要是对它的实现方式及API做 ...

  2. ecstore实现图片分离(静态资源分离)配置文件

    转载http://bbs.ec-os.net/read.php?tid=854 图片分离涉及到三个config设置#define('APP_STATICS_HOST', 'http://192.168 ...

  3. C 语言资源大全中文版

    C 语言资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-c 是 koz.ross 发起维护的 C 语言资源列表,内容包括了: ...

  4. Github资源汇集

    Github资源汇集 突然发现申请博客园已经两年有余,没有发表过一篇文章,十分惭愧.言归正传,先分享一下两年来收集的部分编程资源,大部分为Github上的项目.虽然网上这样的分享已不在少数,但不如我理 ...

  5. OpenRisc-34-ORPSoC跑eCos实验

    引言 ORPSoC目前支持好几种OS,除了前面一直介绍的linux,还支持eCos,eCos是RTOS,如果你的系统对时间的要求比较高,那eCos会是一个不错的选择. 本小节就简单介绍一下,在ORPS ...

  6. Python 库,资源

    库名称简介 Chardet字符编码探测器,可以自动检测文本.网页.xml的编码. colorama主要用来给文本添加各种颜色,并且非常简单易用. Prettytable主要用于在终端或浏览器端构建格式 ...

  7. MIT挑战(如何在12个月内自学完成MIT计算机科学的33门课程|内附MIT公开课程资源和学习顺序

    译者注:本文译自Scott H. Young的博客,Scott拥有超强的学习能力,曾在12个月内自学完成麻省理工学院计算机科学的33门课程.本文就是他个人对于这次MIT挑战的介绍和总结. 版权声明:本 ...

  8. Docker背后的内核知识——cgroups资源限制(转)

    时间 2015-04-20 21:10:00 InfoQ 原文  http://www.infoq.com/cn/articles/docker-kernel-knowledge-cgroups-re ...

  9. PHP 优秀资源汇集(照搬)

    文章目录 原文地址: https://shockerli.net/post/php-awesome/ GitHub: https://github.com/shockerli/php-awesome ...

随机推荐

  1. go share library

    http://blog.ralch.com/tutorial/golang-sharing-libraries/ Sharing Golang packages to C and Go Sun, Au ...

  2. 倒计时demo

    #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (strong,nonatom ...

  3. js设置全局变量ajax中赋值

    js设置全局变量,在ajax中给予赋值赋值不上问题解决方案 方案一. //在全局或某个需要的函数内设置Ajax异步为false,也就是同步. $.ajaxSetup({async : false}); ...

  4. Android OpenGL ES(二)OpenGL ES管道(Pipeline) .

    大部分图形系统都可以比作工厂中的装配线(Assemble line)或者称为管道(Pipeline).前一道的输出作为下道工序的输入.主CPU发出一个绘图指令,然后可能由硬件部件完成坐标变换,裁剪,添 ...

  5. webservice(soap)接口的加密,SHA-1实现

    import java.io.UnsupportedEncodingException;import java.security.MessageDigest;import java.security. ...

  6. 关键自li,em,dl,ul,ol,footer,header,nav,aside,article

    section 版块 用于划分页面上的不同区域,或者划分文章里不同的节 header 页面头部或者版块(section)头部 footer 页面底部或者(section)底部 nav 导航 (包含链接 ...

  7. PHP AJAX技术

    AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. AJAX 通过在后台与服务器进行少量数据交换,使网页实现异步更新.这意味着可以在不重载整个页面的情况下,对网页的某些部分进行更 ...

  8. PAT1006

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  9. L7,too late

    words: parcel,包裹 detective,侦探 expect,期待 airfield,飞机起落的场地 guard,警戒,守卫,n precious,adj,珍贵的 stone,石头 exp ...

  10. debug经验汇总

    (1)使用pstack (2)调试core文件 # gdb ./segment core (3)使用strace strace -tt -f -s 1234 -o /tmp/strace.cwc -p ...