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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
// Autogenerated by Thrift Compiler (0.12.0)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING

#![allow(unused_imports)]
#![allow(unused_extern_crates)]
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, type_complexity))]
#![cfg_attr(rustfmt, rustfmt_skip)]

extern crate ordered_float;
extern crate thrift;
extern crate try_from;

use ordered_float::OrderedFloat;
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
use std::convert::From;
use std::default::Default;
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::rc::Rc;
use try_from::TryFrom;

use thrift::{ApplicationError, ApplicationErrorKind, ProtocolError, ProtocolErrorKind, TThriftClient};
use thrift::protocol::{TFieldIdentifier, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TInputProtocol, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType};
use thrift::protocol::field_id;
use thrift::protocol::verify_expected_message_type;
use thrift::protocol::verify_expected_sequence_number;
use thrift::protocol::verify_expected_service_call;
use thrift::protocol::verify_required_field_exists;
use thrift::server::TProcessor;

/// The event type about service start/stop.
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum ServiceLaunchEventType {
  /// All lower power services started.
  LowPowerStartOver = 0,
  /// All high power services started.
  HighPowerStartOver = 1,
  /// Back to low power from high power mode over.
  BackToLowerPowerOver = 2,
  /// High power recovered, happens when layer1 restart.
  HighPowerRecoverOver = 3,
  /// A Service connected to the broker, it's ready to process messages.
  SingleServiceStarted = 4,
  /// A Service been removed from the broker.
  SingleServiceStopped = 5,
  /// Only used for Layer1Service to tell layer0 to reset all layer1 services state
  ResetLayer1Services = 6,
  /// Only used for layer0 to tell Layer1Service that all layer1 services state reset over
  Layer1ServicesResetOver = 7,
}

impl ServiceLaunchEventType {
  pub fn write_to_out_protocol(&self, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    o_prot.write_i32(*self as i32)
  }
  pub fn read_from_in_protocol(i_prot: &mut TInputProtocol) -> thrift::Result<ServiceLaunchEventType> {
    let enum_value = i_prot.read_i32()?;
    ServiceLaunchEventType::try_from(enum_value)  }
}

impl TryFrom<i32> for ServiceLaunchEventType {
  type Err = thrift::Error;  fn try_from(i: i32) -> Result<Self, Self::Err> {
    match i {
      0 => Ok(ServiceLaunchEventType::LowPowerStartOver),
      1 => Ok(ServiceLaunchEventType::HighPowerStartOver),
      2 => Ok(ServiceLaunchEventType::BackToLowerPowerOver),
      3 => Ok(ServiceLaunchEventType::HighPowerRecoverOver),
      4 => Ok(ServiceLaunchEventType::SingleServiceStarted),
      5 => Ok(ServiceLaunchEventType::SingleServiceStopped),
      6 => Ok(ServiceLaunchEventType::ResetLayer1Services),
      7 => Ok(ServiceLaunchEventType::Layer1ServicesResetOver),
      _ => {
        Err(
          thrift::Error::Protocol(
            ProtocolError::new(
              ProtocolErrorKind::InvalidData,
              format!("cannot convert enum constant {} to ServiceLaunchEventType", i)
            )
          )
        )
      },
    }
  }
}

/// @UserShellEventType_desc
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum UserShellEventType {
  Login = 0,
  Logout = 1,
}

impl UserShellEventType {
  pub fn write_to_out_protocol(&self, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    o_prot.write_i32(*self as i32)
  }
  pub fn read_from_in_protocol(i_prot: &mut TInputProtocol) -> thrift::Result<UserShellEventType> {
    let enum_value = i_prot.read_i32()?;
    UserShellEventType::try_from(enum_value)  }
}

impl TryFrom<i32> for UserShellEventType {
  type Err = thrift::Error;  fn try_from(i: i32) -> Result<Self, Self::Err> {
    match i {
      0 => Ok(UserShellEventType::Login),
      1 => Ok(UserShellEventType::Logout),
      _ => {
        Err(
          thrift::Error::Protocol(
            ProtocolError::new(
              ProtocolErrorKind::InvalidData,
              format!("cannot convert enum constant {} to UserShellEventType", i)
            )
          )
        )
      },
    }
  }
}

//
// ServiceLaunchEvent
//

/// The event will be fired when service state changed.
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ServiceLaunchEvent {
  /// The event type.
  pub event_type: Option<i32>,
  /// The last service that cause the state change.
  pub last_service_i_d: Option<String>,
}

impl ServiceLaunchEvent {
  pub fn new<F1, F2>(event_type: F1, last_service_i_d: F2) -> ServiceLaunchEvent where F1: Into<Option<i32>>, F2: Into<Option<String>> {
    ServiceLaunchEvent {
      event_type: event_type.into(),
      last_service_i_d: last_service_i_d.into(),
    }
  }
  pub fn read_from_in_protocol(i_prot: &mut TInputProtocol) -> thrift::Result<ServiceLaunchEvent> {
    i_prot.read_struct_begin()?;
    let mut f_1: Option<i32> = Some(0);
    let mut f_2: Option<String> = Some("".to_owned());
    loop {
      let field_ident = i_prot.read_field_begin()?;
      if field_ident.field_type == TType::Stop {
        break;
      }
      let field_id = field_id(&field_ident)?;
      match field_id {
        1 => {
          let val = i_prot.read_i32()?;
          f_1 = Some(val);
        },
        2 => {
          let val = i_prot.read_string()?;
          f_2 = Some(val);
        },
        _ => {
          i_prot.skip(field_ident.field_type)?;
        },
      };
      i_prot.read_field_end()?;
    }
    i_prot.read_struct_end()?;
    let ret = ServiceLaunchEvent {
      event_type: f_1,
      last_service_i_d: f_2,
    };
    Ok(ret)
  }
  pub fn write_to_out_protocol(&self, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    let struct_ident = TStructIdentifier::new("ServiceLaunchEvent");
    o_prot.write_struct_begin(&struct_ident)?;
    if let Some(fld_var) = self.event_type {
      o_prot.write_field_begin(&TFieldIdentifier::new("EventType", TType::I32, 1))?;
      o_prot.write_i32(fld_var)?;
      o_prot.write_field_end()?;
      ()
    } else {
      ()
    }
    if let Some(ref fld_var) = self.last_service_i_d {
      o_prot.write_field_begin(&TFieldIdentifier::new("LastServiceID", TType::String, 2))?;
      o_prot.write_string(fld_var)?;
      o_prot.write_field_end()?;
      ()
    } else {
      ()
    }
    o_prot.write_field_stop()?;
    o_prot.write_struct_end()
  }
}

impl Default for ServiceLaunchEvent {
  fn default() -> Self {
    ServiceLaunchEvent{
      event_type: Some(0),
      last_service_i_d: Some("".to_owned()),
    }
  }
}

//
// UserShellEvent
//

/// @UserShellEvent_desc
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct UserShellEvent {
  /// @UserShellEvent_EventType_desc
  pub event_type: Option<UserShellEventType>,
}

impl UserShellEvent {
  pub fn new<F1>(event_type: F1) -> UserShellEvent where F1: Into<Option<UserShellEventType>> {
    UserShellEvent {
      event_type: event_type.into(),
    }
  }
  pub fn read_from_in_protocol(i_prot: &mut TInputProtocol) -> thrift::Result<UserShellEvent> {
    i_prot.read_struct_begin()?;
    let mut f_1: Option<UserShellEventType> = None;
    loop {
      let field_ident = i_prot.read_field_begin()?;
      if field_ident.field_type == TType::Stop {
        break;
      }
      let field_id = field_id(&field_ident)?;
      match field_id {
        1 => {
          let val = UserShellEventType::read_from_in_protocol(i_prot)?;
          f_1 = Some(val);
        },
        _ => {
          i_prot.skip(field_ident.field_type)?;
        },
      };
      i_prot.read_field_end()?;
    }
    i_prot.read_struct_end()?;
    let ret = UserShellEvent {
      event_type: f_1,
    };
    Ok(ret)
  }
  pub fn write_to_out_protocol(&self, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    let struct_ident = TStructIdentifier::new("UserShellEvent");
    o_prot.write_struct_begin(&struct_ident)?;
    if let Some(ref fld_var) = self.event_type {
      o_prot.write_field_begin(&TFieldIdentifier::new("EventType", TType::I32, 1))?;
      fld_var.write_to_out_protocol(o_prot)?;
      o_prot.write_field_end()?;
      ()
    } else {
      ()
    }
    o_prot.write_field_stop()?;
    o_prot.write_struct_end()
  }
}

impl Default for UserShellEvent {
  fn default() -> Self {
    UserShellEvent{
      event_type: None,
    }
  }
}

//
// PubHeader
//

/// @PubHeader_desc
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct PubHeader {
  /// @PubHeader_PayloadType_desc
  pub payload_type: Option<String>,
}

impl PubHeader {
  pub fn new<F1>(payload_type: F1) -> PubHeader where F1: Into<Option<String>> {
    PubHeader {
      payload_type: payload_type.into(),
    }
  }
  pub fn read_from_in_protocol(i_prot: &mut TInputProtocol) -> thrift::Result<PubHeader> {
    i_prot.read_struct_begin()?;
    let mut f_1: Option<String> = Some("".to_owned());
    loop {
      let field_ident = i_prot.read_field_begin()?;
      if field_ident.field_type == TType::Stop {
        break;
      }
      let field_id = field_id(&field_ident)?;
      match field_id {
        1 => {
          let val = i_prot.read_string()?;
          f_1 = Some(val);
        },
        _ => {
          i_prot.skip(field_ident.field_type)?;
        },
      };
      i_prot.read_field_end()?;
    }
    i_prot.read_struct_end()?;
    let ret = PubHeader {
      payload_type: f_1,
    };
    Ok(ret)
  }
  pub fn write_to_out_protocol(&self, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    let struct_ident = TStructIdentifier::new("PubHeader");
    o_prot.write_struct_begin(&struct_ident)?;
    if let Some(ref fld_var) = self.payload_type {
      o_prot.write_field_begin(&TFieldIdentifier::new("PayloadType", TType::String, 1))?;
      o_prot.write_string(fld_var)?;
      o_prot.write_field_end()?;
      ()
    } else {
      ()
    }
    o_prot.write_field_stop()?;
    o_prot.write_struct_end()
  }
}

impl Default for PubHeader {
  fn default() -> Self {
    PubHeader{
      payload_type: Some("".to_owned()),
    }
  }
}

pub const LAYER0_SERVICE_CHANNEL: &str = "layer0/service";

pub const SERVICE_INPUT_CHANNEL: &str = "service/input";