[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]中间件访问驱动程序

时间: 2024-08-05 04:20:32

[OpenNebula]中间件访问驱动程序的相关文章

[OpenNebula]中间件訪问驱动程序

/* -------------------------------------------------------------------------- */ /* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); you may */ /* not

基于中间件访问频率限制 每分钟时间间隔最多访问3次

同一个IP 1分钟时间间隔只能访问三次 1. 拿到用户请求的IP 2. 当前请求的时间 3. 记录访问的历史 VISIT_RECORD ={ 'ip':[] } class Throttle(MiddlewareMixin): def process_request(self,request): # print(request.META)通过这个可以拿到ip ip = request.META.get('REMOTE_ADDR') now = time.time() if ip not in V

驱动原理(应用程序访问驱动程序)

以read为例: read是一个系统调用,系统调用之前在应用程序当中(或者叫用户空间当中),read的实现代码在内核中,read是如何找到内核的实现代码呢? /********************************************* *filename:read_mem.c ********************************************/ #include <stdio.h> #include <sys/types.h> #include

【Linux 驱动】设备驱动程序再理解

学习设备驱动编程也有一段时间了,也写过了几个驱动程序,因此有对设备驱动程序有了一些新的理解和认识,总结一下.学习设备驱动编程也有一段时间了,也写过了几个驱动程序,因此有对设备驱动程序有了一些新的理解和认识,总结一下. ★什么是驱动程序 刚开始学习设备驱动程序的时候,产生了许多的问题.什么是驱动程序?驱动程序是干嘛的?它是如何工作的?它又是如何跟操作系统联系起来的?一系列的问题,现在有些地方还是不一定清楚,但是相比起刚开始的那个阶段,感觉自己还是清楚了很多. 设备驱动程序说白了(实质)就是为应用程

第1课第4.4节_Android硬件访问服务编写HAL代码

4 编写HAL代码 源码下载方法 第一次: git clone https://github.com/weidongshan/SYS_0001_LEDDemo.git 更新: git pull origin 取出指定版本: git checkout v1 // 有JNI没有HAL git checkout v2 // 有JNI,HAL git checkout v3 // add MODULE TAG, DEVICE TAG JNI 向上提供本地函数, 向下加载HAL文件并调用HAL的函数HAL

16、驱动访问大揭秘

应用程序主要是通过系统调用来访问驱动程序图. 接下来我们以read.c应用程序来分析: 我们知道read.c是个系统调用,系统调用之前,他是在我们的应用程序当中.实现是在内核当中,但是read.c是怎么找到内核的实现代码的呢?接下来就是这内容: 这是read.c的代码: 我们现在静态编译和反汇编: 然后打开dump:搜索:main函数:/main 我们主要是看read方法是如何实现的: 这个代码主要做了两件工作: 第一件是把我们read的三个参数传到我们的r0-r2里面去,保存起来.我们都知道在

Linux驱动程序工作原理简介

转自:http://blog.sina.com.cn/s/blog_55465b470100ri1e.html 一.linux驱动程序的数据结构      二.设备节点如何产生?      三.应用程序是如何访问设备驱动程序的?      四.为什么要有设备文件系统?      五.设备文件系统如何实现?      六.如何使用设备文件系统?      七.具体设备驱动程序分析      1.      驱动程序初始化时,要注册设备节点,创建子设备文件      2.      驱动程序卸载时要

数据库相关中间件介绍

数据库相关中间件介绍 详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt412 这里主要介绍互联网行业内有关数据库的相关中间件.数据库相关平台主要解决以下三个方面的问题: 为海量前台数据提供高性能.大容量.高可用性的访问 为数据变更的消费提供准实时的保障 高效的异地数据同步 应用层通过分表分库中间件访问数据库,包括读操作(Select)和写操作(update, insert和delete等,DDL, DCL).写操作会在数据

linux 驱动学习(一)简单的字符设备驱动程序

linux 系统将设备分为三种类型:字符设备.块设备和网络接口设备. 文章将先给出字符设备驱动程序,参照程序记录知识点,可能会不全,以后会慢慢加 .知识点记录完成后,会贴出字符设备驱动程序的测试程序并记录测试过程. 注释版 1 #include "linux/kernel.h" //内核头文件,含有一些内核常用函数的原形定义 2 #include "linux/module.h" //包含大量加载模块需要的函数和符号的定义 3 #include "linu