[OpenNebula]中间件訪问驱动程序
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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. */
/* -------------------------------------------------------------------------- */ #ifndef MAD_H_
#define MAD_H_ #include <pthread.h>
#include <sys/types.h> #include <map>
#include <string>
#include <sstream> #include <unistd.h> #include "Log.h" using namespace std; /**
* Base class to build specific middleware access drivers (MAD).
* This class provides generic MAD functionality.
*/
class Mad
{
protected:
/**
* The constructor initialize the class members but DOES NOT start the
* driver. A subsequent call to the start() method is needed.
* @param userid user running this MAD
* @param attrs configuration attributes for the driver
* @param sudo the driver is started through sudo if true
*/
Mad(
int userid,
const map<string,string> &attrs,
bool sudo):
uid(userid),
attributes(attrs),
sudo_execution(sudo),
pid(-1)
{}; /**
* The destructor of the class finalizes the driver process, and all its
* associated resources (i.e. pipes)
*/
virtual ~Mad(); /**
* Send a command to the driver
* @param os an output string stream with the message, it must be
* terminated with the end of line character.
*/
void write(
ostringstream& os) const
{
string str;
const char * cstr; str = os.str();
cstr = str.c_str(); ::write(nebula_mad_pipe, cstr, str.size());
}; /**
* Send a DRIVER_CANCEL command to the driver
* @param oid identifies the action (that associated with oid)
*/
void driver_cancel (const int oid) const
{
ostringstream os; os << "DRIVER_CANCEL " << oid << endl; write(os);
}; /**
* Sets the log message type as specify by the driver.
* @param first character of the type string
* @return the message type
*/
Log::MessageType log_type(const char r) const
{
Log::MessageType lt; switch (r)
{
case 'E':
lt = Log::ERROR;
break;
case 'I':
lt = Log::INFO;
break;
case 'D':
lt = Log::DEBUG;
break;
default:
lt = Log::INFO;
} return lt;
} private:
friend class MadManager; /**
* Communication pipe file descriptor. Represents the MAD to nebula
* communication stream (nebula<-mad)
*/
int mad_nebula_pipe; /**
* Communication pipe file descriptor. Represents the nebula to MAD
* communication stream (nebula->mad)
*/
int nebula_mad_pipe; /**
* User running this MAD as defined in the upool DB
*/
int uid; /**
* Mad configuration attributes (e.g. executable, attributes...). Attribute
* names MUST be lowecase.
*/
map<string,string> attributes; /**
* True if the mad is to be executed through sudo, with the identity of the
* Mad owner (uid).
*/
bool sudo_execution; /**
* Process ID of the running MAD.
*/
pid_t pid; /**
* Starts the MAD. This function creates a new process, sets up the
* communication pipes and sends the initialization command to the driver.
* @return 0 on success
*/
int start(); /**
* Reloads the driver: sends the finalize command, "waits" for the
* driver process and closes the communication pipes. Then the driver is
* started again by calling the start() function
* @return 0 on success
*/
int reload(); /**
* Implements the driver specific protocol, this function should trigger
* actions on the associated manager.
* @param message the string read from the driver
*/
virtual void protocol(const string& message) const = 0; /**
* This function is called whenever the driver crashes. This function
* should perform the actions needed to recover the VMs.
*/
virtual void recover() = 0;
}; #endif /*MAD_H_*/
上面这个类是OpenNebula 中间件訪问驱动的接口.
[OpenNebula]中间件訪问驱动程序的更多相关文章
- 实战DeviceIoControl 之中的一个:通过API訪问设备驱动程序
P.bhw98 { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 9pt; PADDING-BOTTOM: 0px; MARGIN: 10px 0 ...
- Linux 下IOport编程訪问
曾经写的一篇笔记.偶尔翻出来了,放在这里做个纪念 Linux 下IOport编程訪问 这里记录的方法是在用户态訪问IOport,不涉及驱动程序的编写. 首先要包括头文件 /usr/include/as ...
- 数据库訪问技术之JDBC
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhuojiajin/article/details/32150883 在了解JDBC之前呢, ...
- Windows server2008 搭建ASP接口訪问连接oracle数据库全过程记录
真的是太不easy了,曾经的时候在window server 2003上面搭建了一套asp+oracle的接口系统.就费了好大的劲儿,事实上那会迷迷瞪瞪的也不知道怎么的就弄好了,也懒得管了.OK,从昨 ...
- https双向认证訪问管理后台,採用USBKEY进行系统訪问的身份鉴别,KEY的证书长度大于128位,使用USBKEY登录
近期项目需求,须要实现用USBKEY识别用户登录,採用https双向认证訪问管理后台管理界面,期间碰到过一些小问题,写出来给大家參考下. 1:前期准备工作 USBKEY 硬件:我买的是飞天诚信 epa ...
- juniper 550M訪问自身公网IP回流内部IP
拓扑图示意: 网关设备juniper 550M, untrust 区: 公网地址段22.22.22.22/29 trust区: 内部员工PC地址:172.16.4.x /24 trust区: ...
- MySQL数据库能够用随意ip连接訪问的方法
通过CMD命令行改动数据库表的一个字段的值.实现连接,訪问. 第一步.找到MYSQL软件安装所在的bin文件夹. (1)cd\当前文件夹 (2)指定MYSQL安装的bin文件夹 (3)输入 -h lo ...
- ios 7.1 7.1.1 半完美越狱后 电脑訪问手机越狱文件夹的方法
7.1和7.1.1因为越狱不成熟,半完美越狱后电脑上无法訪问系统越狱文件夹,如var usr 等等. 今天有些意外地发现,能够在电脑上使用手机的越狱文件夹我手机 i4 7.1.1 联通 半完美越狱,没 ...
- jQuery訪问属性,绝对定位
一. jQuery訪问属性 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
随机推荐
- 使用GitBook编写文档
GitBook 简介 GitBook 是一个通过 Git 和 Markdown 来撰写书籍的工具,最终可以生成 3 种格式: 静态站点:包含了交互功能(例如搜索.书签)的站点 PDF:PDF 格式的文 ...
- 利用js加载本地图片预览功能
直接上代码: 经测试,除safari6包括6以下不支持,其他均可正常显示. 原因:safari6不支持filereader,同时不能使用IE滤镜导致失效. fix: 可以利用canvas,解决safa ...
- android布局1
第二类:属性值必须为id的引用名“@id/id-name” 仅RelativeLayout中有效 android:layout_below 在某元素的下方 android:la ...
- underscorejs-reject学习
2.9 reject 2.9.1 语法: _.reject(list, predicate, [context]) 2.9.2 说明: 前边我们已经学习了filter方法,那么我们在学习reject之 ...
- js学习笔记之:时间(三)
今天来学习一个简单的时间应用:时间的倒影,如图所示: 主要知识点: 1 获取系统的时间值:2 建立一个div的倒影 div的倒影主要利用css来控制,函数值为:filter:flipv() 步骤 ...
- python中的几种遍历列表的方法比较
python的内容非常丰富,给我们带来的便利很多,很多事情的表达方法有很大的多样性,比如我经常需要遍历一个列表,取它的下标和值,这个时候就有很多方法需要取舍一下才行. for循环遍历 l = [1,2 ...
- SQL语句宝典
1.前述: 将数据灵活运用于手掌心! link:1.经典SQL语句大全(cnblogs) 2.SQL教程(W3C)
- 过多if-else分支的优化
http://www.udpwork.com/item/9294.html 我想谈一谈这个话题是因为我的上一篇博客在ITEye上有一些朋友回复,说if-else过多的分支可以使用switch或者责任链 ...
- Preventing Web Attacks with Apache
http://www.boyunjian.com/do/article/snapshot.do?uid=net.csdn.blog/wurangy050/article/details/5287235
- FLASK初步实践
感觉经过DJANGO,CI,RAILS之类的WEB框架之后,FLASK的思路就比较顺畅了... FLASKR.PY import sqlite3 from flask import Flask, re ...