/
handle.pmc
116 lines (75 loc) · 2.01 KB
/
handle.pmc
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
/*
Copyright (C) 2008-2010, Parrot Foundation.
=head1 NAME
src/pmc/handle.pmc - IO Handle PMC
=head1 DESCRIPTION
This is the base-class for all IO-related PMCs.
=head2 Vtable Functions
=over 4
=item C<init>
=item C<init_pmc>
Handle shouldn't be directly instantiated, init and init_pmc throws
EXCEPTION_INVALID_OPERATION.
=cut
*/
#include "parrot/parrot.h"
#include "../src/io/io_private.h"
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
pmclass Handle provides Handle manual_attrs {
/* TODO: Consider encapsulating PIOHANDLE as a PMC type, for subclassing */
ATTR PIOHANDLE os_handle; /* Low level OS descriptor */
VTABLE void init() {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"Handle cannot be instantiated directly.");
}
VTABLE void init_pmc(PMC * init) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"Handle cannot be instantiated directly.");
}
/*
=back
=head2 Methods
=over 4
=item C<METHOD isatty()>
Returns a boolean value indicating whether C<SELF> is a console/tty.
This default implementation always return false. Override it in
subtypes that are or can be tty.
=cut
*/
METHOD isatty() {
RETURN(INTVAL 0);
}
/*
=item C<METHOD get_fd()>
Retrieve the integer file descriptor for the Handle (only available on
platforms that use integer file descriptors).
=cut
*/
METHOD get_fd() {
#ifndef PIO_OS_STDIO
PIOHANDLE os_handle;
INTVAL fd;
GET_ATTR_os_handle(INTERP, SELF, os_handle);
fd = (INTVAL)os_handle;
RETURN(INTVAL fd);
#endif /*PIO_OS_STDIO*/
RETURN(INTVAL -1);
}
/*
=item C<METHOD close()>
Close the handle.
=cut
*/
METHOD close() {
const INTVAL status = Parrot_io_close(INTERP, SELF);
RETURN(INTVAL status);
}
}
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/