Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4bc54e6e8f5fc5e99a7cfeafb3d5935d5e229492 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
 * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * CONTRIBUTORS:
 * 		Thomas Schuetz (initial contribution)
 *
 *******************************************************************************/


#include "runtime/etRuntime.h"


static etSema terminateSemaphore;
static etMessageService* head = NULL;

etSema* etRuntime_getTerminateSemaphore() {
	static etBool initialized = ET_FALSE;

	if (!initialized) {
		initialized = ET_TRUE;
		etSema_construct(&terminateSemaphore);
	}

	return &terminateSemaphore;
}

int etRuntime_getMessageServiceCount() {
	etMessageService* p = head;

	int count = 0;
	while (p!=null) {
		++count;
		p = p->next;
	}
	return count;
}

int etRuntime_getMessageServiceByName(const char* name) {
	etMessageService* p = head;

	int idx = 0;
	while (p!=null) {
		if (strcmp(p->name, name)==0) {
			return idx;
		}
		++idx;
		p = p->next;
	}

	return -1;
}

const etMessageServiceStatistics* etRuntime_getMessageServiceStatistics(unsigned int i) {
	etMessageService* p = head;

	int count = 0;
	while (p!=null) {
		if (count==i) {
			return &p->statistics;
		}
		++count;
		p = p->next;
	}

	return NULL;
}

void etRuntime_resetAllMessageServiceStatistics() {
	etMessageService* p = head;

	while (p!=null) {
		p->resetStatistics = ET_TRUE;
		p = p->next;
	}
}

void etRuntime_registerMessageService(etMessageService* msgService) {
	msgService->next = head;
	head = msgService;

	if (msgService->name==NULL) {
		void* p = malloc(16);
		sprintf(p, "MsgSvc_%d", etRuntime_getMessageServiceCount());
		msgService->name = (const char*) p;
	}
}

void etRuntime_unregisterMessageService(etMessageService* msgService) {
	etMessageService* p = head;
	etMessageService* last = NULL;

	while (p!=null) {
		if (p==msgService) {
			if (last==NULL) {
				/* remove the first one */
				head = p->next;
			}
			else {
				last->next = p->next;
			}
			break;
		}
		last = p;
		p = p->next;
	}
}

Back to the top