Roger Meier | 2be7f24 | 2012-05-10 09:01:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | #ifndef _THRIFT_TEST_EVENTLOG_H_ |
| 20 | #define _THRIFT_TEST_EVENTLOG_H_ 1 |
| 21 | |
Roger Meier | 2b1a528 | 2012-05-11 10:12:39 +0000 | [diff] [blame] | 22 | #include <thrift/concurrency/Monitor.h> |
Roger Meier | 2be7f24 | 2012-05-10 09:01:45 +0000 | [diff] [blame] | 23 | |
| 24 | namespace apache { namespace thrift { namespace test { |
| 25 | |
| 26 | // Initially I made EventType an enum, but using char* results |
| 27 | // in much more readable error messages when there is a mismatch. |
| 28 | // It also lets users of EventLog easily define their own new types. |
| 29 | // Comparing the literal pointer values should be safe, barring any strange |
| 30 | // linking setup that results in duplicate symbols. |
| 31 | typedef const char* EventType; |
| 32 | |
| 33 | struct Event { |
| 34 | Event(EventType type, uint32_t connectionId, uint32_t callId, |
| 35 | const std::string& message) : |
| 36 | type(type), |
| 37 | connectionId(connectionId), |
| 38 | callId(callId), |
| 39 | message(message) {} |
| 40 | |
| 41 | EventType type; |
| 42 | uint32_t connectionId; |
| 43 | uint32_t callId; |
| 44 | std::string message; |
| 45 | }; |
| 46 | |
| 47 | class EventLog { |
| 48 | public: |
| 49 | static EventType ET_LOG_END; |
| 50 | static EventType ET_CONN_CREATED; |
| 51 | static EventType ET_CONN_DESTROYED; |
| 52 | static EventType ET_CALL_STARTED; |
| 53 | static EventType ET_CALL_FINISHED; |
| 54 | static EventType ET_PROCESS; |
| 55 | static EventType ET_PRE_READ; |
| 56 | static EventType ET_POST_READ; |
| 57 | static EventType ET_PRE_WRITE; |
| 58 | static EventType ET_POST_WRITE; |
| 59 | static EventType ET_ASYNC_COMPLETE; |
| 60 | static EventType ET_HANDLER_ERROR; |
| 61 | |
| 62 | static EventType ET_CALL_INCREMENT_GENERATION; |
| 63 | static EventType ET_CALL_GET_GENERATION; |
| 64 | static EventType ET_CALL_ADD_STRING; |
| 65 | static EventType ET_CALL_GET_STRINGS; |
| 66 | static EventType ET_CALL_GET_DATA_WAIT; |
| 67 | static EventType ET_CALL_ONEWAY_WAIT; |
| 68 | static EventType ET_CALL_UNEXPECTED_EXCEPTION_WAIT; |
| 69 | static EventType ET_CALL_EXCEPTION_WAIT; |
| 70 | static EventType ET_WAIT_RETURN; |
| 71 | static EventType ET_CALL_SET_VALUE; |
| 72 | static EventType ET_CALL_GET_VALUE; |
| 73 | |
| 74 | EventLog(); |
| 75 | |
| 76 | void append(EventType type, uint32_t connectionId, uint32_t callId, |
| 77 | const std::string& message = ""); |
| 78 | |
| 79 | Event waitForEvent(int64_t timeout = 500); |
| 80 | Event waitForConnEvent(uint32_t connId, int64_t timeout = 500); |
| 81 | |
| 82 | protected: |
| 83 | typedef std::list<Event> EventList; |
| 84 | |
| 85 | concurrency::Monitor monitor_; |
| 86 | EventList events_; |
| 87 | uint32_t id_; |
| 88 | |
| 89 | static uint32_t nextId_; |
| 90 | }; |
| 91 | |
| 92 | }}} // apache::thrift::test |
| 93 | |
| 94 | #endif // _THRIFT_TEST_EVENTLOG_H_ |