File: rfcommif.cpp

package info (click to toggle)
pybluez 0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 524 kB
  • ctags: 776
  • sloc: ansic: 4,226; python: 2,175; cpp: 1,861; makefile: 46
file content (169 lines) | stat: -rw-r--r-- 4,693 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <windows.h>
#include <Python.h>
#include <tchar.h>

#include <BtIfDefinitions.h>
#include <BtIfClasses.h>
#include <com_error.h>

#include "util.h"

// ===================

typedef struct _WCRfCommIfPyObject WCRfCommIfPyObject;

struct _WCRfCommIfPyObject {
    PyObject_HEAD

    CRfCommIf * rfcommif;
};
PyDoc_STRVAR(wcrfcommif_doc, "CRfCommIf wrapper");

extern PyTypeObject wcrfcommif_type;

static PyObject *
assign_scn_value (PyObject *s, PyObject *args)
{
    WCRfCommIfPyObject *self = (WCRfCommIfPyObject*) s;

    char *uuid_str = NULL;
    int uuid_str_len = 0;
    UINT8 scn = 0;
    char *service_name = _T("");

    if(!PyArg_ParseTuple (args, "s#|Bs", &uuid_str, &uuid_str_len, 
                &scn, &service_name))
        return NULL;

    GUID uuid = { 0 };
    PyWidcomm::str2uuid (uuid_str, &uuid);

//    printf ("AssignScnValue\n");
    BOOL result = self->rfcommif->AssignScnValue (&uuid, scn, service_name);

    if (result) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}

static PyObject *
get_scn (PyObject *s)
{
    WCRfCommIfPyObject *self = (WCRfCommIfPyObject*) s;

    return PyInt_FromLong (self->rfcommif->GetScn ());
}

static PyObject *
set_security_level (PyObject *s, PyObject *args)
{
    char *service_name = NULL;
    UINT8 security_level = BTM_SEC_NONE;
    int is_server;

    if(!PyArg_ParseTuple (args, "sBi", &service_name, &security_level,
                &is_server))
        return NULL;

    WCRfCommIfPyObject *self = (WCRfCommIfPyObject*) s;
    BOOL result = self->rfcommif->SetSecurityLevel (service_name, 
            security_level, (BOOL) is_server);

    if (result) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}

static PyMethodDef wcrfcommif_methods[] = {
    { "assign_scn_value", (PyCFunction)assign_scn_value, METH_VARARGS, "" },
    { "get_scn", (PyCFunction)get_scn, METH_NOARGS, "" },
    { "set_security_level", (PyCFunction)set_security_level, METH_VARARGS, "" },
    { NULL, NULL }
};

static PyObject *
wcrfcommif_repr(WCRfCommIfPyObject *s)
{
    return PyString_FromString("_WCRfCommIf object");
}

static PyObject *
wcrfcommif_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    PyObject *newobj;

    newobj = type->tp_alloc(type, 0);
    if (newobj != NULL) {
        WCRfCommIfPyObject *self = (WCRfCommIfPyObject *)newobj;
        self->rfcommif = NULL;
    }
    return newobj;
}

static void
wcrfcommif_dealloc(WCRfCommIfPyObject *self)
{
    if (self->rfcommif) {
        delete self->rfcommif;
        self->rfcommif = NULL;
    }
    self->ob_type->tp_free((PyObject*)self);
}

int
wcrfcommif_initobj(PyObject *s, PyObject *args, PyObject *kwds)
{
    WCRfCommIfPyObject *self = (WCRfCommIfPyObject *)s;
    self->rfcommif = new CRfCommIf ();
    return 0;
}

/* Type object for socket objects. */
PyTypeObject wcrfcommif_type = {
    PyObject_HEAD_INIT(0)   /* Must fill in type value later */
    0,                  /* ob_size */
    "_widcomm._WCRfCommIf",            /* tp_name */
    sizeof(WCRfCommIfPyObject),     /* tp_basicsize */
    0,                  /* tp_itemsize */
    (destructor)wcrfcommif_dealloc,     /* tp_dealloc */
    0,                  /* tp_print */
    0,                  /* tp_getattr */
    0,                  /* tp_setattr */
    0,                  /* tp_compare */
    (reprfunc)wcrfcommif_repr,          /* tp_repr */
    0,                  /* tp_as_number */
    0,                  /* tp_as_sequence */
    0,                  /* tp_as_mapping */
    0,                  /* tp_hash */
    0,                  /* tp_call */
    0,                  /* tp_str */
    PyObject_GenericGetAttr,        /* tp_getattro */
    0,                  /* tp_setattro */
    0,                  /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
    wcrfcommif_doc,               /* tp_doc */
    0,                  /* tp_traverse */
    0,                  /* tp_clear */
    0,                  /* tp_richcompare */
    0,                  /* tp_weaklistoffset */
    0,                  /* tp_iter */
    0,                  /* tp_iternext */
    wcrfcommif_methods,               /* tp_methods */
    0,                  /* tp_members */
    0,                  /* tp_getset */
    0,                  /* tp_base */
    0,                  /* tp_dict */
    0,                  /* tp_descr_get */
    0,                  /* tp_descr_set */
    0,                  /* tp_dictoffset */
    wcrfcommif_initobj,             /* tp_init */
    PyType_GenericAlloc,            /* tp_alloc */
    wcrfcommif_new,             /* tp_new */
    PyObject_Del,               /* tp_free */
};