File: logtop.i

package info (click to toggle)
logtop 0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 200 kB
  • sloc: ansic: 1,426; python: 71; makefile: 54
file content (50 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download
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
%module logtop

%{
#include "src/logtop.h"
%}

%typemap(out) struct logtop_state *
{
    int i;
    PyObject *log_line;
    PyObject *lines;
    PyObject *tmp;

    $result = PyDict_New();
    lines = PyList_New(0);
    while (result->lines[i] != NULL)
    {
        log_line = PyTuple_New(3);
        PyTuple_SetItem(log_line, 0, PyInt_FromLong(result->lines[i]->count));
        PyTuple_SetItem(log_line, 1, PyFloat_FromDouble(result->lines[i]->frequency));
        PyTuple_SetItem(log_line, 2, PyString_FromString(result->lines[i]->string));
        PyList_Append(lines, log_line);
        Py_DECREF(log_line);
        i++;
    }
    PyDict_SetItemString($result, "lines", lines);
    Py_DECREF(lines);
    tmp = PyInt_FromLong(result->count);
    PyDict_SetItemString($result, "count", tmp);
    Py_DECREF(tmp);
    tmp = PyFloat_FromDouble(result->timespan);
    PyDict_SetItemString($result, "timespan", tmp);
    Py_DECREF(tmp);
    tmp = PyFloat_FromDouble(result->frequency);
    PyDict_SetItemString($result, "frequency", tmp);
    Py_DECREF(tmp);
    delete_logtop_state(result);
}

struct logtop
{
    %extend {
        logtop(size_t history_size);
        ~logtop();
        void feed(char *line);
        struct logtop_state *get(size_t qte);
        double timespan();
        unsigned int qte_of_elements();
    }
};