From ec688b4723a041044226358bcd4dd6e2da39da49 Mon Sep 17 00:00:00 2001 From: Luca Muscariello Date: Thu, 23 Feb 2017 17:01:02 +0100 Subject: Initial commit: cframework. Longbow and Libparc Change-Id: I90378dbd30da6033b20fb1f829b3b822cf366c59 Signed-off-by: Luca Muscariello --- longbow/src/LongBow/longBow_Event.c | 122 ++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 longbow/src/LongBow/longBow_Event.c (limited to 'longbow/src/LongBow/longBow_Event.c') diff --git a/longbow/src/LongBow/longBow_Event.c b/longbow/src/LongBow/longBow_Event.c new file mode 100755 index 00000000..a24d45bf --- /dev/null +++ b/longbow/src/LongBow/longBow_Event.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed 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. + */ + +/** + */ +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/** @cond private */ +struct longbow_event { + const LongBowEventType *type; + const LongBowLocation *location; + const char *kind; + const char *message; + const LongBowBacktrace *backtrace; +}; +/** @endcond */ + +const char * +longBowEvent_GetName(const LongBowEvent *event) +{ + return longBowEventType_GetName(event->type); +} + +LongBowEvent * +longBowEvent_Create(const LongBowEventType *eventType, const LongBowLocation *location, const char *kind, const char *message, const LongBowBacktrace *backtrace) +{ + LongBowEvent *result = longBowMemory_Allocate(sizeof(LongBowEvent)); + if (result != NULL) { + result->type = eventType; + result->location = location; + result->kind = kind; + result->message = strndup(message, strlen(message)); + result->backtrace = backtrace; + } + + return result; +} + +void +longBowEvent_Destroy(LongBowEvent **assertionPtr) +{ + LongBowEvent *assertion = *assertionPtr; + + if (assertion->location != NULL) { + longBowLocation_Destroy((LongBowLocation **) &assertion->location); + } + if (assertion->message != NULL) { + free((void *) assertion->message); + } + + if (assertion->backtrace != NULL) { + longBowBacktrace_Destroy((LongBowBacktrace **) &assertion->backtrace); + } + longBowMemory_Deallocate((void **) assertionPtr); +} + +const LongBowLocation * +longBowEvent_GetLocation(const LongBowEvent *event) +{ + return event->location; +} + +const LongBowEventType * +longBowEvent_GetEventType(const LongBowEvent *event) +{ + return event->type; +} + +const char * +longBowEvent_GetKind(const LongBowEvent *event) +{ + return event->kind; +} + +const char * +longBowEvent_GetMessage(const LongBowEvent *event) +{ + return event->message; +} + +const LongBowBacktrace * +longBowEvent_GetBacktrace(const LongBowEvent *event) +{ + return event->backtrace; +} + +char ** +longBowEvent_CreateSymbolicCallstack(const LongBowEvent *event) +{ + char **result = longBowBacktrace_Symbols(event->backtrace); + + return result; +} + +size_t +longBowEvent_GetCallStackLength(const LongBowEvent *event) +{ + return longBowBacktrace_GetFrameCount(event->backtrace); +} -- cgit 1.2.3-korg