From: Chuck Hagenbuch Date: Sun, 30 May 2010 16:12:53 +0000 (-0400) Subject: Initial Horde scribe wrapper using Horde_Thrift X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=477143f345fb5e2aab3b6e857e0e1dac2b8f3147;p=horde.git Initial Horde scribe wrapper using Horde_Thrift --- diff --git a/framework/Scribe/lib/Horde/Scribe.php b/framework/Scribe/lib/Horde/Scribe.php new file mode 100644 index 000000000..1638826ea --- /dev/null +++ b/framework/Scribe/lib/Horde/Scribe.php @@ -0,0 +1,9 @@ + 0, + 'TRY_LATER' => 1, +); + +final class ResultCode { + const OK = 0; + const TRY_LATER = 1; + static public $__names = array( + 0 => 'OK', + 1 => 'TRY_LATER', + ); +} + +class LogEntry { + static $_TSPEC; + + public $category = null; + public $message = null; + + public function __construct($vals=null) { + if (!isset(self::$_TSPEC)) { + self::$_TSPEC = array( + 1 => array( + 'var' => 'category', + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'message', + 'type' => TType::STRING, + ), + ); + } + if (is_array($vals)) { + if (isset($vals['category'])) { + $this->category = $vals['category']; + } + if (isset($vals['message'])) { + $this->message = $vals['message']; + } + } + } + + public function getName() { + return 'LogEntry'; + } + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->category); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->message); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('LogEntry'); + if ($this->category !== null) { + $xfer += $output->writeFieldBegin('category', TType::STRING, 1); + $xfer += $output->writeString($this->category); + $xfer += $output->writeFieldEnd(); + } + if ($this->message !== null) { + $xfer += $output->writeFieldBegin('message', TType::STRING, 2); + $xfer += $output->writeString($this->message); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + +?> diff --git a/framework/Scribe/lib/Horde/Thrift/scribe.php b/framework/Scribe/lib/Horde/Thrift/scribe.php new file mode 100644 index 000000000..f66003e3d --- /dev/null +++ b/framework/Scribe/lib/Horde/Thrift/scribe.php @@ -0,0 +1,285 @@ +send_Log($messages); + return $this->recv_Log(); + } + + public function send_Log($messages) + { + $args = new scribe_Log_args(); + $args->messages = $messages; + $bin_accel = ($this->output_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) + { + thrift_protocol_write_binary($this->output_, 'Log', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite()); + } + else + { + $this->output_->writeMessageBegin('Log', TMessageType::CALL, $this->seqid_); + $args->write($this->output_); + $this->output_->writeMessageEnd(); + $this->output_->getTransport()->flush(); + } + } + + public function recv_Log() + { + $bin_accel = ($this->input_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_read_binary'); + if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, 'scribe_Log_result', $this->input_->isStrictRead()); + else + { + $rseqid = 0; + $fname = null; + $mtype = 0; + + $this->input_->readMessageBegin($fname, $mtype, $rseqid); + if ($mtype == TMessageType::EXCEPTION) { + $x = new TApplicationException(); + $x->read($this->input_); + $this->input_->readMessageEnd(); + throw $x; + } + $result = new scribe_Log_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + throw new Exception("Log failed: unknown result"); + } + +} + +// HELPER FUNCTIONS AND STRUCTURES + +class scribe_Log_args { + static $_TSPEC; + + public $messages = null; + + public function __construct($vals=null) { + if (!isset(self::$_TSPEC)) { + self::$_TSPEC = array( + 1 => array( + 'var' => 'messages', + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => 'LogEntry', + ), + ), + ); + } + if (is_array($vals)) { + if (isset($vals['messages'])) { + $this->messages = $vals['messages']; + } + } + } + + public function getName() { + return 'scribe_Log_args'; + } + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 1: + if ($ftype == TType::LST) { + $this->messages = array(); + $_size0 = 0; + $_etype3 = 0; + $xfer += $input->readListBegin($_etype3, $_size0); + for ($_i4 = 0; $_i4 < $_size0; ++$_i4) + { + $elem5 = null; + $elem5 = new LogEntry(); + $xfer += $elem5->read($input); + $this->messages []= $elem5; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('scribe_Log_args'); + if ($this->messages !== null) { + if (!is_array($this->messages)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('messages', TType::LST, 1); + { + $output->writeListBegin(TType::STRUCT, count($this->messages)); + { + foreach ($this->messages as $iter6) + { + $xfer += $iter6->write($output); + } + } + $output->writeListEnd(); + } + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + +class scribe_Log_result { + static $_TSPEC; + + public $success = null; + + public function __construct($vals=null) { + if (!isset(self::$_TSPEC)) { + self::$_TSPEC = array( + 0 => array( + 'var' => 'success', + 'type' => TType::I32, + ), + ); + } + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + } + } + + public function getName() { + return 'scribe_Log_result'; + } + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 0: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->success); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('scribe_Log_result'); + if ($this->success !== null) { + $xfer += $output->writeFieldBegin('success', TType::I32, 0); + $xfer += $output->writeI32($this->success); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + +class scribeProcessor extends FacebookServiceProcessor { + public function __construct($handler) { + parent::__construct($handler); + } + + public function process($input, $output) { + $rseqid = 0; + $fname = null; + $mtype = 0; + + $input->readMessageBegin($fname, $mtype, $rseqid); + $methodname = 'process_'.$fname; + if (!method_exists($this, $methodname)) { + $input->skip(TType::STRUCT); + $input->readMessageEnd(); + $x = new TApplicationException('Function '.$fname.' not implemented.', TApplicationException::UNKNOWN_METHOD); + $output->writeMessageBegin($fname, TMessageType::EXCEPTION, $rseqid); + $x->write($output); + $output->writeMessageEnd(); + $output->getTransport()->flush(); + return; + } + $this->$methodname($rseqid, $input, $output); + return true; + } + + protected function process_Log($seqid, $input, $output) { + $args = new scribe_Log_args(); + $args->read($input); + $input->readMessageEnd(); + $result = new scribe_Log_result(); + $result->success = $this->handler_->Log($args->messages); + $output->writeMessageBegin('Log', TMessageType::REPLY, $seqid); + $result->write($output); + $output->getTransport()->flush(); + } +} +?> diff --git a/framework/Scribe/package.xml b/framework/Scribe/package.xml new file mode 100644 index 000000000..c1c737470 --- /dev/null +++ b/framework/Scribe/package.xml @@ -0,0 +1,71 @@ + + + Scribe + pear.horde.org + Scribe + Packaged version of the PHP Scribe client + + + Chuck Hagenbuch + chuck + chuck@horde.org + yes + + + Jan Schneider + jan + jan@horde.org + yes + + 2010-04-20 + + + 0.1.0 + 0.1.0 + + + beta + beta + + Apache 2.0 + * Initial packaging of autogenerated Scribe thrift code + + + + + + + + + + + + + + + + + + + + + + 5.2 + + + 1.7.0 + + + + + + + + + + + +