Wisp 1.3.1 C++ Unit Test Coverage
Current view: top level - examples/echo - echo_service.h (source / functions) Hit Total Coverage
Test: Wisp 1.3.1 C++ Unit Tests Lines: 20 20 100.0 %
Date: 2017-01-16 Functions: 5 6 83.3 %
Branches: 5 8 62.5 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2006-2008 Savarese Software Research Corporation
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at
       7                 :            :  *
       8                 :            :  *     http://www.savarese.com/software/ApacheLicense-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #ifndef __WISP_EXAMPLE_ECHO_SERVICE_H
      18                 :            : #define __WISP_EXAMPLE_ECHO_SERVICE_H
      19                 :            : 
      20                 :            : #include "echo_protocol.h"
      21                 :            : #include <ssrc/wisp/service.h>
      22                 :            : 
      23                 :            : using ssrc::spread::Message;
      24                 :            : using ssrc::wisp::protocol::MessageInfo;
      25                 :            : using ssrc::wisp::service::ServiceProtocolProcessor;
      26                 :            : 
      27                 :            : class EchoService 
      28                 :            :   : public ServiceProtocolProcessor<EchoProtocol::packing_traits>
      29                 :            : {
      30                 :            :   friend class ServiceProtocolProcessor<EchoProtocol::packing_traits>;
      31                 :            :   typedef ServiceProtocolProcessor<EchoProtocol::packing_traits> super;
      32                 :            : 
      33                 :            :   WISP_IMPORT(EchoProtocol, MessageStop);
      34                 :            :   WISP_IMPORT(EchoProtocol, MessageEchoRequest);
      35                 :            :   WISP_IMPORT(EchoProtocol, CallEchoReply);
      36                 :            : 
      37                 :          6 :   virtual void transition(State state) {
      38         [ +  + ]:          6 :     if(state == Stopping)
      39                 :          3 :       state = Stopped;
      40         [ +  - ]:          3 :     else if(state == Starting)
      41                 :          3 :       state = Started;
      42                 :          6 :     super::transition(state);
      43                 :          6 :   }
      44                 :            : 
      45                 :            : public:
      46                 :            : 
      47                 :          3 :   EchoService(super::caller_type & caller) : super(caller) {
      48         [ +  - ]:          3 :     WISP_SERVICE_REQUEST(MessageStop);
      49         [ +  - ]:          3 :     WISP_SERVICE_REQUEST(MessageEchoRequest);
      50                 :          3 :   }
      51                 :            : 
      52                 :          3 :   virtual ~EchoService() = default;
      53                 :            : 
      54                 :          3 :   void process_request(const MessageStop & msg, const MessageInfo &) {
      55                 :          3 :     stop();
      56                 :          3 :   }
      57                 :            : 
      58                 :          3 :   void process_request(const MessageEchoRequest & msg,
      59                 :            :                        const MessageInfo & msginfo)
      60                 :            :   {
      61                 :          3 :     _caller.
      62                 :          6 :       reply<CallEchoReply>(Message::FIFO, msginfo.sender(), msginfo.token(),
      63                 :          3 :                            msg.payload);
      64                 :          3 :   }
      65                 :            : };
      66                 :            : 
      67                 :            : #endif