-
Notifications
You must be signed in to change notification settings - Fork 149
/
ClientType.hh
176 lines (148 loc) · 6.37 KB
/
ClientType.hh
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
170
171
172
173
174
175
176
//------------------------------------------------------------------------------
// Copyright (c) 2012-2013 by European Organization for Nuclear Research (CERN)
// Author: Justin Salmon <jsalmon@cern.ch>
//------------------------------------------------------------------------------
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------
#ifndef XRDCLBIND_HH_
#define XRDCLBIND_HH_
#include <Python.h>
#include <iostream>
#include "structmember.h"
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClXRootDResponses.hh"
#include "XRootDStatusType.hh"
#include "URLType.hh"
namespace XrdClBind
{
typedef struct {
PyObject_HEAD
/* Type-specific fields */
URL* url;
} Client;
static void
Client_dealloc(Client* self)
{
Py_XDECREF(self->url);
self->ob_type->tp_free((PyObject*) self);
}
static int
Client_init(Client *self, PyObject *args, PyObject *kwds)
{
const char *urlstr;
static char *kwlist[] = {"url", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &urlstr))
return -1;
PyObject *bind_args = Py_BuildValue("(s)", urlstr);
if (!bind_args) {
return NULL;
}
self->url = (URL *) PyObject_CallObject((PyObject *)
&URLType, bind_args);
Py_DECREF(bind_args);
if (!self->url) {
return NULL;
}
return 0;
}
static PyObject*
Stat(Client* self, PyObject* args)
{
const char* path;
if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
XrdCl::FileSystem fs(*self->url->url);
XrdCl::XRootDStatus status;
XrdCl::StatInfo *statinfo = 0;
status = fs.Stat(path, statinfo, 5);
//std::cout << "modtime: " << statinfo->GetModTime() << std::endl;
// Build XRootDStatus mapping object
std::cout << "errmsg: " << status.GetErrorMessage() << std::endl;
PyObject* status_args = Py_BuildValue("(iiis)", status.status,
status.code, status.errNo, status.GetErrorMessage().c_str());
if (!status_args) {
return NULL;
}
PyObject* status_bind = PyObject_CallObject((PyObject *)
&XRootDStatusType, status_args);
if (!status_bind) {
return NULL;
}
Py_DECREF(status_args);
// Build StatInfo mapping object
// PyObject* statinfo_args = Py_BuildValue("(iii)", status.status, status.code,
// status.errNo);
// if (!statinfo_args) {
// return NULL;
// }
//
// PyObject* statinfo_bind = PyObject_CallObject((PyObject *)
// &XRootDStatusType, statinfo_args);
// if (!statinfo_bind) {
// return NULL;
// }
// Py_DECREF(statinfo_args);
return Py_BuildValue("O", status_bind);
}
static PyMemberDef ClientMembers[] = {
{"url", T_OBJECT_EX, offsetof(Client, url), 0,
"Server URL"},
{NULL} /* Sentinel */
};
static PyMethodDef ClientMethods[] = {
{"stat", (PyCFunction) Stat, METH_VARARGS,
"Stat a path"},
{NULL} /* Sentinel */
};
static PyTypeObject ClientType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"client.Client", /* tp_name */
sizeof(Client), /* tp_basicsize */
0, /* tp_itemsize */
(destructor) Client_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"Client object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ClientMethods, /* tp_methods */
ClientMembers, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc) Client_init, /* tp_init */
};
}
#endif /* XRDCLBIND_HH_ */