Annotation of embedaddon/strongswan/src/libimcv/swima/swima_event.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2017 Andreas Steffen
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include "swima_event.h"
! 17: #include "swima_data_model.h"
! 18:
! 19: typedef struct private_swima_event_t private_swima_event_t;
! 20:
! 21: /**
! 22: * Private data of a swima_event_t object.
! 23: *
! 24: */
! 25: struct private_swima_event_t {
! 26:
! 27: /**
! 28: * Public swima_event_t interface.
! 29: */
! 30: swima_event_t public;
! 31:
! 32: /**
! 33: * Event ID
! 34: */
! 35: uint32_t eid;
! 36:
! 37: /**
! 38: * Timestamp
! 39: */
! 40: chunk_t timestamp;
! 41:
! 42: /**
! 43: * Action
! 44: */
! 45: uint8_t action;
! 46:
! 47: /**
! 48: * Software [Identifier] record
! 49: */
! 50: swima_record_t *sw_record;
! 51:
! 52: /**
! 53: * Reference count
! 54: */
! 55: refcount_t ref;
! 56: };
! 57:
! 58: METHOD(swima_event_t, get_eid, uint32_t,
! 59: private_swima_event_t *this, chunk_t *timestamp)
! 60: {
! 61: if (timestamp)
! 62: {
! 63: *timestamp = this->timestamp;
! 64: }
! 65: return this->eid;
! 66: }
! 67:
! 68: METHOD(swima_event_t, get_action, uint8_t,
! 69: private_swima_event_t *this)
! 70: {
! 71: return this->action;
! 72: }
! 73:
! 74: METHOD(swima_event_t, get_sw_record, swima_record_t*,
! 75: private_swima_event_t *this)
! 76: {
! 77: return this->sw_record;
! 78: }
! 79:
! 80:
! 81: METHOD(swima_event_t, get_ref, swima_event_t*,
! 82: private_swima_event_t *this)
! 83: {
! 84: ref_get(&this->ref);
! 85: return &this->public;
! 86: }
! 87:
! 88: METHOD(swima_event_t, destroy, void,
! 89: private_swima_event_t *this)
! 90: {
! 91: if (ref_put(&this->ref))
! 92: {
! 93: this->sw_record->destroy(this->sw_record);
! 94: free(this->timestamp.ptr);
! 95: free(this);
! 96: }
! 97: }
! 98:
! 99: /**
! 100: * See header
! 101: */
! 102: swima_event_t *swima_event_create(uint32_t eid, chunk_t timestamp,
! 103: uint8_t action, swima_record_t *sw_record)
! 104: {
! 105: private_swima_event_t *this;
! 106:
! 107: INIT(this,
! 108: .public = {
! 109: .get_eid = _get_eid,
! 110: .get_action = _get_action,
! 111: .get_sw_record = _get_sw_record,
! 112: .get_ref = _get_ref,
! 113: .destroy = _destroy,
! 114: },
! 115: .eid = eid,
! 116: .timestamp = chunk_clone(timestamp),
! 117: .action = action,
! 118: .sw_record = sw_record,
! 119: .ref = 1,
! 120: );
! 121:
! 122: return &this->public;
! 123: }
! 124:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>