/* -------------------------------------------------------------------------- */
/* 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]中间件訪问驱动程序的更多相关文章

  1. 实战DeviceIoControl 之中的一个:通过API訪问设备驱动程序

    P.bhw98 { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 9pt; PADDING-BOTTOM: 0px; MARGIN: 10px 0 ...

  2. Linux 下IOport编程訪问

    曾经写的一篇笔记.偶尔翻出来了,放在这里做个纪念 Linux 下IOport编程訪问 这里记录的方法是在用户态訪问IOport,不涉及驱动程序的编写. 首先要包括头文件 /usr/include/as ...

  3. 数据库訪问技术之JDBC

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhuojiajin/article/details/32150883     在了解JDBC之前呢, ...

  4. Windows server2008 搭建ASP接口訪问连接oracle数据库全过程记录

    真的是太不easy了,曾经的时候在window server 2003上面搭建了一套asp+oracle的接口系统.就费了好大的劲儿,事实上那会迷迷瞪瞪的也不知道怎么的就弄好了,也懒得管了.OK,从昨 ...

  5. https双向认证訪问管理后台,採用USBKEY进行系统訪问的身份鉴别,KEY的证书长度大于128位,使用USBKEY登录

    近期项目需求,须要实现用USBKEY识别用户登录,採用https双向认证訪问管理后台管理界面,期间碰到过一些小问题,写出来给大家參考下. 1:前期准备工作 USBKEY 硬件:我买的是飞天诚信 epa ...

  6. juniper 550M訪问自身公网IP回流内部IP

    拓扑图示意: 网关设备juniper 550M, untrust 区: 公网地址段22.22.22.22/29 trust区:      内部员工PC地址:172.16.4.x /24 trust区: ...

  7. MySQL数据库能够用随意ip连接訪问的方法

    通过CMD命令行改动数据库表的一个字段的值.实现连接,訪问. 第一步.找到MYSQL软件安装所在的bin文件夹. (1)cd\当前文件夹 (2)指定MYSQL安装的bin文件夹 (3)输入 -h lo ...

  8. ios 7.1 7.1.1 半完美越狱后 电脑訪问手机越狱文件夹的方法

    7.1和7.1.1因为越狱不成熟,半完美越狱后电脑上无法訪问系统越狱文件夹,如var usr 等等. 今天有些意外地发现,能够在电脑上使用手机的越狱文件夹我手机 i4 7.1.1 联通 半完美越狱,没 ...

  9. jQuery訪问属性,绝对定位

    一. jQuery訪问属性 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

随机推荐

  1. asp.net 从客户端中检测到有潜在危险的 Request.Form 值错误解

    从客户端(ftbContent="<P><A href="http://l...")中检测到有潜在危险的 Request.Form 值. 说明: 请求验 ...

  2. Linux下登陆mysql服务器不需要输入账号密码信息

    linux下登录mysql服务器一般都是在命令行手动输入链接信息 [root@localhost ~]# mysql -hlocalhost -uroot -p11111 而在mysql 5.6之后版 ...

  3. linux c最简单的加密程序

    最初的密码程序是在Hirst First c里面看到的,大概内容如下:对待加密的字符串的每一个字符和某个数值进行一次按位异或得到密文,再进行一次按位异或得到明文. 补充知识:按位异或的结果是“同位得1 ...

  4. Android模拟器genymotion安装与eclipse 插件安装

    推荐一款Android模拟器"Genymotion",有点速度快,占用资源少,可整合eclipse.闲话少谈,看安装步骤. 1.下载地址:https://www.genymotio ...

  5. 学生选课系统数据库SQL语句考试题

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  6. JS 输出与变量

    1. JS的输出 innerHTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...

  7. 粗看C#委托

    C#的好多定义跟C艹不太相同,先来分析一下“委托”. 1. 委托的定义: 委托,可以认为是类型安全的函数指针,类型安全就是指明确定义了返回类型与参数类型,在C#代码编译时就能够确保指针传参时的安全性. ...

  8. JS学习之页面加载

    1.window.opener.location.reload();     意思是让打开的父窗口刷新.window.opener指的是本窗口的父窗口,window.opener.location.h ...

  9. Redis系列(2)之数据类型

    Redis系列(2)之数据类型 <Redis系列(1)之安装>中介绍了Redis支持以下几种数据类型,那么本节主要介绍学习下这几种数据类型的基本操作 字符串类型,string 散列类型,h ...

  10. 更改新建Asp.net WebForm的模板 的方法

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Web\2052\WebFor ...