File: Refcount.py

package info (click to toggle)
ngs-sdk 2.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,216 kB
  • sloc: cpp: 20,310; java: 5,060; perl: 3,895; python: 1,452; makefile: 691; xml: 233; sh: 70
file content (70 lines) | stat: -rw-r--r-- 1,942 bytes parent folder | download | duplicates (7)
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
from ctypes import byref, c_void_p

from . import NGS
from .String import NGS_RawString

def RefcountRelease(ref):
    """Releases NGS-object imported from ngs-sdk
    
    :param ref: reference to refcounted NGS-object to be released. It's expected to be of type c_void_p
    :returns: None
    :throws: ErrorMsg
    """
    ngs_str_err = NGS_RawString()
    try:
        res = NGS.lib_manager.PY_NGS_RefcountRelease(ref, byref(ngs_str_err.ref))
    finally:
        ngs_str_err.close()

# def RefcountEngineRelease(ref):
    # """Releases NGS-object imported from ngs engine
    
    # :param ref: reference to refcounted NGS-object to be released. It's expected to be of type c_void_p
    # :returns: None
    # :throws: ErrorMsg
    # """

    # ERROR_BUFFER_SIZE = 4096
    # str_err = create_string_buffer(ERROR_BUFFER_SIZE)
    # from . import PY_RES_OK
    # res = NGS.lib_manager.PY_NGS_Engine_RefcountRelease(ref, str_err, len(str_err))
    # if res != PY_RES_OK:
        # raise ErrorMsg(str_err.value)


def RefcountRawStringRelease(ref):
    """Releases raw string imported from ngs-sdk
    
    :param ref: reference to raw char string. It's expected to be of type c_char_p
    :returns: None
    :throws: ErrorMsg
    """
    ngs_str_err = NGS_RawString()
    try:
        res = NGS.lib_manager.PY_NGS_RawStringRelease(ref, byref(ngs_str_err.ref))
    finally:
        ngs_str_err.close()


class Refcount:
    """ Base class for all refcounted objects imported from ngs-sdk
    """
    def __init__(self):
        self.init_members_with_null()
    
    def __del__(self):
        self.close()
            
    def __enter__(self):
        return self
    
    def __exit__(self, t, value, traceback):
        self.close()

    def close(self):
        if self.ref:
            RefcountRelease(self.ref)
            self.init_members_with_null()
            
    def init_members_with_null(self):
        self.ref = c_void_p()