/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

// This autogenerated skeleton file illustrates how to build a server.
// You should copy it to another filename to avoid overwriting it.

#include "ThreadsTest.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TThreadPoolServer.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <thrift/concurrency/Monitor.h>
#include <thrift/concurrency/ThreadManager.h>
#include <thrift/concurrency/ThreadFactory.h>
#if _WIN32
   #include <thrift/windows/TWinsockSingleton.h>
#endif

using boost::shared_ptr;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace apache::thrift::server;
using namespace apache::thrift::concurrency;

int main(int argc, char **argv) {
#if _WIN32
  transport::TWinsockSingleton::create();
#endif
  int port = 9090;
  std::string host = "localhost";

  shared_ptr<TTransport> transport(new TSocket(host, port));
  shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

  transport->open();

  ThreadsTestClient client(protocol);
  int val;
  val = client.threadOne(5);
  fprintf(stderr, "%d\n", val);
  val = client.stop();
  fprintf(stderr, "%d\n", val);
  val = client.threadTwo(5);
  fprintf(stderr, "%d\n", val);

  transport->close();

  fprintf(stderr, "done.\n");

  return 0;
}

