/* -------------------------------------------------------------------------- */
/* 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. "SOAP WebService " 和 "RESTful WebService" 的定义分别是什么???

    一个个来,要知道区别,首先得知道各自的意义及用途web service采用Xml传输结构化的数据,轻量级跨平台而soap则是一种基于http的应用层通讯协议,同样采用xml编码,只不过soap又更进了 ...

  2. Linux特殊权限

    ************************     ACL权限       ****************************************** acl权限的出现是为了弥补用户权 ...

  3. Swift - 24 - switch语句的高级用法

    //: Playground - noun: a place where people can play import UIKit // 对区间进行判断 var score = 90 switch s ...

  4. [转]Delphi 中动态链接库(dll)的建立和使用

    动态链接库是一个能够被应用程序和其它的DLL调用的过程和函数的集合体,它里面包含的是公共代码或资源.由于DLL代码使用了内存共享技术,在某些地方windows也给了DLL一些更高的权限,因而DLL中可 ...

  5. Animator Override Controllers 学习及性能测试

    本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_AnimatorOverrideContorller.html  The ...

  6. int, NSInteger, NSUInteger, NSNumber的区别

    新手在接触iOS或者Mac开发的时候,看到int和NSInteger,一般不清楚应该用哪个比较合适.我们先来查看下NSInteger的定义 #if __LP64__ || (TARGET_OS_EMB ...

  7. 再谈CMake与RPATH

    之前写过一篇<探讨CMake中关于RPATH的使用>,只要针对的方面是在编译生成之后(不包括安装的make install)如何去除RPATH的问题.今天给大家主要介绍一下如何让CMake ...

  8. Delphi-LowerCase 函数

    函数名称 LowerCase 所在单元 System.SysUtils 函数原型 function LowerCase(const S: string): string; 函数功能 将字符串中所有的大 ...

  9. apache静态文件配置

    开发环境配置 需要下面几个步骤 1. 在app目录下创建static目录,将静态文件和相关文件夹放到此目录下,如your_app/static/img等 2. 确保settings.py中的INSTA ...

  10. UITextFiled自动补全输入,选中补全内容。NSRange和UITextRange的相互转换。-b

    有个需求就是 需要用户输入几位以后账号,可以根据本地存储的登录成功的账号,进行自动补全,并且补全内容为选中状态,不影响用户的新输入. 研究了一下,下面是完整的实现的方法. 补充个下载地址http:// ...