File: WFUT.i

package info (click to toggle)
libwfut 0.2.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,556 kB
  • ctags: 1,880
  • sloc: cpp: 18,319; sh: 9,156; python: 493; makefile: 73
file content (105 lines) | stat: -rw-r--r-- 2,813 bytes parent folder | download | duplicates (2)
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
%module WFUT

## TODO: Need to implement the callback functiosn somehow

## TODO: Need to check destructors, e.g. no FileMap destructor
##       Possibly a const related problem

## TODO: Need to auto de-init wfutclient objects

%{
#include <libwfut/types.h>
#include <libwfut/crc32.h>
#include <libwfut/ChannelFileList.h>
#include <libwfut/ChannelIO.h>
#include <libwfut/Encoder.h>
#include <libwfut/FileIO.h>
#include <libwfut/IO.h>
#include <libwfut/WFUT.h>
#include <sigc++/bind.h>
#include <sigc++/object_slot.h>
%}

%import "std_string.i"
%import "std_map.i"
%import "std_list.i"
%import "std_vector.i"

%{
  void cb_download_complete(const std::string &s1, const std::string &s2, PyObject *f) {
    PyObject *args = Py_BuildValue("(ss)", s1.c_str(), s2.c_str());
    assert(args != 0);

    PyObject *r = PyObject_CallObject(f, args);
    if (r != 0) {
      Py_XDECREF(r);
    } else {
      // Failed -- Dont care
      // Maybe we should re-throw the exception?
    }

    Py_XDECREF(args);
  }

  void cb_download_failed(const std::string &s1, const std::string &s2, const std::string &s3, PyObject *f) {
    PyObject *args = Py_BuildValue("(sss)", s1.c_str(), s2.c_str(), s3.c_str());
    assert(args != 0);

    PyObject *r = PyObject_CallObject(f, args);
    if (r != 0) {
      Py_XDECREF(r);
    } else {
      // Failed -- Dont care
      // Maybe we should re-throw the exception?
    }

    Py_XDECREF(args);
  }

  void cb_update_reason(const std::string &s1, const WFUT::WFUTUpdateReason wu, PyObject *f) {
    PyObject *args = Py_BuildValue("(si)", s1.c_str(), wu);
    assert(args != 0);

    PyObject *r = PyObject_CallObject(f, args);
    if (r != 0) {
      Py_XDECREF(r);
    } else {
      // Failed -- Dont care
      // Maybe we should re-throw the exception?
    }

    Py_XDECREF(args);
  }

%}

%template(MirrorList) std::vector<WFUT::MirrorObject>;
%template(FileList) std::vector<WFUT::FileObject>;
%template(ChannelList) std::vector<WFUT::ChannelObject>;
%template(FileMap) std::map<std::string, WFUT::FileObject>;


## Need to map uLong to a python type
%typedef unsigned int uLong;

%include <libwfut/types.h>
%include <libwfut/crc32.h>
%include <libwfut/ChannelFileList.h>
%include <libwfut/ChannelIO.h>
%include <libwfut/Encoder.h>
%include <libwfut/FileIO.h>
%include <libwfut/IO.h>
%include <libwfut/WFUT.h>

%extend WFUT::WFUTClient {
  void WFUT::WFUTClient::DownloadCompleteCB(PyObject *f) {
    self->DownloadComplete.connect(sigc::bind(sigc::ptr_fun(cb_download_complete),f));
  }
  void WFUT::WFUTClient::DownloadFailedCB(PyObject *f) {
    self->DownloadFailed.connect(sigc::bind(sigc::ptr_fun(cb_download_failed),f));
  }
  void WFUT::WFUTClient::UpdateReasonCB(PyObject *f) {
    self->UpdateReason.connect(sigc::bind(sigc::ptr_fun(cb_update_reason),f));
  }
}