예제 #1
0
파일: Utils.cpp 프로젝트: alinbalutoiu/PyMI
PyObject* MI2Py(const MI_Value& value, MI_Type valueType, MI_Uint32 flags)
{
    if (flags & MI_FLAG_NULL)
        Py_RETURN_NONE;

    if (valueType & MI_ARRAY)
    {
        return MIArray2PyTuple(value, (MI_Type)(valueType ^ MI_ARRAY));
    }

    switch (valueType)
    {
    case MI_BOOLEAN:
        return PyBool_FromLong(value.boolean);
    case MI_SINT8:
        return PyLong_FromLong(value.sint8);
    case MI_UINT8:
        return PyLong_FromUnsignedLong(value.uint8);
    case MI_SINT16:
        return PyLong_FromLong(value.sint16);
    case MI_UINT16:
        return PyLong_FromUnsignedLong(value.uint16);
    case MI_SINT32:
        return PyLong_FromLong(value.sint32);
    case MI_UINT32:
        return PyLong_FromUnsignedLong(value.uint32);
    case MI_SINT64:
        return PyLong_FromLongLong(value.sint64);
    case MI_UINT64:
        return PyLong_FromUnsignedLongLong(value.uint64);
    case MI_REAL32:
        return PyFloat_FromDouble(value.real32);
    case MI_REAL64:
        return PyFloat_FromDouble(value.real64);
    case MI_CHAR16:
        return PyLong_FromLong(value.char16);
    case MI_DATETIME:
        // TODO: understand where this import needs to be called
        PyDateTime_IMPORT;
        if (value.datetime.isTimestamp)
        {
            const MI_Timestamp& ts = value.datetime.u.timestamp;
            // TODO: Add timezone support!
            return PyDateTime_FromDateAndTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.microseconds);
        }
        else
        {
            return PyDeltaFromMIInterval(value.datetime.u.interval);
        }
        break;
    case MI_STRING:
        return PyUnicode_FromWideChar(value.string, wcslen(value.string));
    case MI_INSTANCE:
        return (PyObject*)Instance_New(std::make_shared<MI::Instance>(value.instance, false));
    case MI_REFERENCE:
        return (PyObject*)Instance_New(std::make_shared<MI::Instance>(value.reference, false));
    default:
        throw MI::TypeConversionException();
    }
}
static MI_Result NewParameters(_In_ MI_Context* context, _In_ const MI_MethodDecl* methodDecl, MI_Instance** instance)
{
    #if defined(_MSC_VER)
    return Instance_New((MI_ClassDecl*)methodDecl, instance);
    #else
    return Instance_New(instance, (MI_ClassDecl*)methodDecl, NULL);
    #endif
}
static MI_Result NewInstance(_In_ MI_Context* context, _In_ const MI_ClassDecl* classDecl, MI_Instance** instance)
{
    #if defined(_MSC_VER)
    return Instance_New(classDecl, instance);
    #else
    return Instance_New(instance, classDecl, NULL);
    #endif
}
예제 #4
0
파일: Application.cpp 프로젝트: bclau/PyMI
static PyObject* Application_NewMethodInboundParameters(Application *self, PyObject *args, PyObject *kwds)
{
    PyObject* pyClass = NULL;
    wchar_t* methodName = NULL;

    static char *kwlist[] = { "mi_class", "method_name", NULL };
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ou", kwlist, &pyClass, &methodName))
        return NULL;

    try
    {
        if (!PyObject_IsInstance(pyClass, reinterpret_cast<PyObject*>(&ClassType)))
            throw MI::TypeConversionException(L"\"mi_class\" must have type Class");

        std::shared_ptr<MI::Instance> instance;
        AllowThreads(&self->cs, [&]() {
            instance = self->app->NewMethodParamsInstance(*((Class*)pyClass)->miClass, methodName);
        });
        return (PyObject*)Instance_New(instance);
    }
    catch (std::exception& ex)
    {
        SetPyException(ex);
        return NULL;
    }
}
예제 #5
0
파일: Application.cpp 프로젝트: bclau/PyMI
static PyObject* Application_NewInstanceFromClass(Application *self, PyObject *args, PyObject *kwds)
{
    wchar_t* className = NULL;
    PyObject* miClass = NULL;
    static char *kwlist[] = { "class_name", "mi_class", NULL };
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "uO", kwlist, &className, &miClass))
        return NULL;

    try
    {
        if (!PyObject_IsInstance(miClass, reinterpret_cast<PyObject*>(&ClassType)))
            throw MI::TypeConversionException(L"\"mi_class\" must have type Class");

        std::shared_ptr<MI::Instance> instance;
        AllowThreads(&self->cs, [&]() {
            instance = self->app->NewInstanceFromClass(className, *((Class*)miClass)->miClass);
        });
        return (PyObject*)Instance_New(instance);
    }
    catch (std::exception& ex)
    {
        SetPyException(ex);
        return NULL;
    }
}
_Use_decl_annotations_
MI_Result MI_CALL Mof_Instance_New(
    const MI_ClassDecl* classDecl,
    MI_Instance **instance)
{
    return Instance_New(classDecl, instance);
}
예제 #7
0
파일: Operation.cpp 프로젝트: bclau/PyMI
static PyObject* Operation_GetNextIndication(Operation* self, PyObject*)
{
    try
    {
        std::shared_ptr<MI::Instance> instance;
        AllowThreads(&self->cs, [&]() {
            instance = self->operation->GetNextIndication();
        });
        if (instance)
        {
            return (PyObject*)Instance_New(instance);
        }
        Py_RETURN_NONE;
    }
    catch (std::exception& ex)
    {
        SetPyException(ex);
        return NULL;
    }
}
예제 #8
0
파일: Application.cpp 프로젝트: bclau/PyMI
static PyObject* Application_NewInstance(Application *self, PyObject *args, PyObject *kwds)
{
    wchar_t* className = NULL;
    static char *kwlist[] = { "class_name", NULL };
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "u", kwlist, &className))
        return NULL;

    try
    {
        std::shared_ptr<MI::Instance> instance;
        AllowThreads(&self->cs, [&]() {
            instance = self->app->NewInstance(className);
        });
        return (PyObject*)Instance_New(instance);
    }
    catch (std::exception& ex)
    {
        SetPyException(ex);
        return NULL;
    }
}