LCOV - code coverage report
Current view: top level - var/local/git/grpc/include/grpc++/support - time.h (source / functions) Hit Total Coverage
Test: tmp.CaZ6RjdVn2 Lines: 6 6 100.0 %
Date: 2015-12-10 22:15:08 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions are
       8             :  * met:
       9             :  *
      10             :  *     * Redistributions of source code must retain the above copyright
      11             :  * notice, this list of conditions and the following disclaimer.
      12             :  *     * Redistributions in binary form must reproduce the above
      13             :  * copyright notice, this list of conditions and the following disclaimer
      14             :  * in the documentation and/or other materials provided with the
      15             :  * distribution.
      16             :  *     * Neither the name of Google Inc. nor the names of its
      17             :  * contributors may be used to endorse or promote products derived from
      18             :  * this software without specific prior written permission.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      21             :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      22             :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      23             :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      24             :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      25             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      26             :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      27             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      28             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      29             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      30             :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      31             :  *
      32             :  */
      33             : 
      34             : #ifndef GRPCXX_SUPPORT_TIME_H
      35             : #define GRPCXX_SUPPORT_TIME_H
      36             : 
      37             : #include <grpc++/support/config.h>
      38             : #include <grpc/support/time.h>
      39             : 
      40             : namespace grpc {
      41             : 
      42             : /* If you are trying to use CompletionQueue::AsyncNext with a time class that
      43             :    isn't either gpr_timespec or std::chrono::system_clock::time_point, you
      44             :    will most likely be looking at this comment as your compiler will have
      45             :    fired an error below. In order to fix this issue, you have two potential
      46             :    solutions:
      47             : 
      48             :      1. Use gpr_timespec or std::chrono::system_clock::time_point instead
      49             :      2. Specialize the TimePoint class with whichever time class that you
      50             :         want to use here. See below for two examples of how to do this.
      51             :  */
      52             : 
      53             : template <typename T>
      54             : class TimePoint {
      55             :  public:
      56             :   TimePoint(const T& time) { you_need_a_specialization_of_TimePoint(); }
      57             :   gpr_timespec raw_time() {
      58             :     gpr_timespec t;
      59             :     return t;
      60             :   }
      61             : 
      62             :  private:
      63             :   void you_need_a_specialization_of_TimePoint();
      64             : };
      65             : 
      66             : template <>
      67             : class TimePoint<gpr_timespec> {
      68             :  public:
      69       96862 :   TimePoint(const gpr_timespec& time) : time_(time) {}
      70       96862 :   gpr_timespec raw_time() { return time_; }
      71             : 
      72             :  private:
      73             :   gpr_timespec time_;
      74             : };
      75             : 
      76             : }  // namespace grpc
      77             : 
      78             : #ifndef GRPC_CXX0X_NO_CHRONO
      79             : 
      80             : #include <chrono>
      81             : 
      82             : #include <grpc/support/time.h>
      83             : 
      84             : namespace grpc {
      85             : 
      86             : // from and to should be absolute time.
      87             : void Timepoint2Timespec(const std::chrono::system_clock::time_point& from,
      88             :                         gpr_timespec* to);
      89             : void TimepointHR2Timespec(
      90             :     const std::chrono::high_resolution_clock::time_point& from,
      91             :     gpr_timespec* to);
      92             : 
      93             : std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t);
      94             : 
      95             : template <>
      96             : class TimePoint<std::chrono::system_clock::time_point> {
      97             :  public:
      98     1677698 :   TimePoint(const std::chrono::system_clock::time_point& time) {
      99     1677698 :     Timepoint2Timespec(time, &time_);
     100     1678371 :   }
     101     1679347 :   gpr_timespec raw_time() const { return time_; }
     102             : 
     103             :  private:
     104             :   gpr_timespec time_;
     105             : };
     106             : 
     107             : }  // namespace grpc
     108             : 
     109             : #endif  // !GRPC_CXX0X_NO_CHRONO
     110             : 
     111             : #endif  // GRPCXX_SUPPORT_TIME_H

Generated by: LCOV version 1.11