Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
#
2
# Licensed to the Apache Software Foundation (ASF) under one
3
# or more contributor license agreements. See the NOTICE file
4
# distributed with this work for additional information
5
# regarding copyright ownership. The ASF licenses this file
6
# to you under the Apache License, Version 2.0 (the
7
# "License"); you may not use this file except in compliance
8
# with the License. You may obtain a copy of the License at
9
#
10
#   http://www.apache.org/licenses/LICENSE-2.0
11
#
12
# Unless required by applicable law or agreed to in writing,
13
# software distributed under the License is distributed on an
14
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
# KIND, either express or implied. See the License for the
16
# specific language governing permissions and limitations
17
# under the License.
18
#
19
 
20
require 5.6.0;
21
use strict;
22
use warnings;
23
 
24
use Thrift;
25
 
26
#
27
# Transport exceptions
28
#
29
package TTransportException;
30
use base('Thrift::TException');
31
 
32
use constant UNKNOWN      => 0;
33
use constant NOT_OPEN     => 1;
34
use constant ALREADY_OPEN => 2;
35
use constant TIMED_OUT    => 3;
36
use constant END_OF_FILE  => 4;
37
 
38
sub new{
39
    my $classname = shift;
40
    my $self      = $classname->SUPER::new(@_);
41
 
42
    return bless($self,$classname);
43
}
44
 
45
package Thrift::Transport;
46
 
47
#
48
# Whether this transport is open.
49
#
50
# @return boolean true if open
51
#
52
sub isOpen
53
{
54
    die "abstract";
55
}
56
 
57
#
58
# Open the transport for reading/writing
59
#
60
# @throws TTransportException if cannot open
61
#
62
sub open
63
{
64
    die "abstract";
65
}
66
 
67
#
68
# Close the transport.
69
#
70
sub close
71
{
72
    die "abstract";
73
}
74
 
75
#
76
# Read some data into the array.
77
#
78
# @param int    $len How much to read
79
# @return string The data that has been read
80
# @throws TTransportException if cannot read any more data
81
#
82
sub read
83
{
84
    my ($len);
85
    die("abstract");
86
}
87
 
88
#
89
# Guarantees that the full amount of data is read.
90
#
91
# @return string The data, of exact length
92
# @throws TTransportException if cannot read data
93
#
94
sub readAll
95
{
96
    my $self = shift;
97
    my $len  = shift;
98
 
99
    my $data = '';
100
    my $got = 0;
101
 
102
    while (($got = length($data)) < $len) {
103
        $data .= $self->read($len - $got);
104
    }
105
 
106
    return $data;
107
}
108
 
109
#
110
# Writes the given data out.
111
#
112
# @param string $buf  The data to write
113
# @throws TTransportException if writing fails
114
#
115
sub write
116
{
117
    my ($buf);
118
    die "abstract";
119
}
120
 
121
#
122
# Flushes any pending data out of a buffer
123
#
124
# @throws TTransportException if a writing error occurs
125
#
126
sub flush {}
127
 
128
 
129
#
130
# TransportFactory creates transport objects from transports
131
#
132
package Thrift::TransportFactory;
133
 
134
sub new {
135
    my $classname = shift;
136
    my $self      = {};
137
 
138
    return bless($self,$classname);
139
}
140
 
141
#
142
# Build a transport from the base transport
143
#
144
# @return Thrift::Transport transport
145
#
146
sub getTransport
147
{
148
    my $self  = shift;
149
    my $trans = shift;
150
 
151
    return $trans;
152
}
153
 
154
 
155
#
156
#  ServerTransport base class module
157
#
158
package Thrift::ServerTransport;
159
 
160
sub listen
161
{
162
    die "abstract";
163
}
164
 
165
sub accept
166
{
167
    die "abstract";
168
}
169
 
170
sub close
171
{
172
    die "abstract";
173
}
174
 
175
 
176
1;
177