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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/*
* ComConduit.cpp
*
* Definition of the ComConduit class
*
* Author: Erik Hellström, hellstrom@isy.liu.se, 2008-12-14
* Modified: Emil Larsson, lime@isy.liu.se, 2012-01-13
*/
#include "ComConduit.h"
#include <string.h>
//#include "mex.h"
// Constructor
ComConduit::ComConduit() {
ptrData = NULL;
}
// Destructor
ComConduit::~ComConduit() {
// Issue shutdown function
Shutdown();
}
// Detach and remove shared memory segment
bool ComConduit::Shutdown() {
if(Conduit::Shutdown()) {
ptrData = NULL;
return true;
}
else
return false;
}
// Server initialization
bool ComConduit::StartServer(KeyType* key) {
if(!Conduit::StartServer(key))
return false;
ptrData = (COMdata*)ptrShm;
ptrData->Common.Flag = NULL_FLAG;
ptrData->Common.DoShutdown = false;
ptrData->string[0] = '\0';
return true;
}
// Client initialization
bool ComConduit::StartClient(KeyType* key) {
if(!Conduit::StartClient(key))
return false;
ptrData = (COMdata*)ptrShm;
return true;
}
// Get shared data size
int ComConduit::GetDataSize() const {
return sizeof(COMdata);
}
// Get pointer to common shared data
CommonData* ComConduit::GetCommonData() const {
if(ptrData == NULL)
return(NULL);
else
return(&ptrData->Common);
}
// Get number of events
int ComConduit::GetNumEvents() const {
return COM_NEVENTS;
}
// Set the data
bool ComConduit::SetData(const wchar_t* data) {
int ii;
if(ptrData == NULL)
return false;
// Request lock
if(!RequestLock())
return false;
// Copy string
// wcscpy_s(ptrData->string,COMSTR_LEN, data);
/* Copy the wchar_t-string manual */
for (ii=0; ii<data[1]+EXTRA_LEN; ii++)
{
ptrData->string[ii] = data[ii];
// printf("\nptrData->string[%d]: %d \n", ii, ptrData->string[ii]);
}
/* Stop with a "null" char */
ptrData->string[ii] = '\0';
// Release lock
if(!ReleaseLock())
return false;
return true;
}
// Get the data
bool ComConduit::GetData(wchar_t* data) {
int ii;
if(ptrData == NULL)
return false;
// Request lock
if(!RequestLock())
return false;
// Copy string
// wcscpy_s(data,COMSTR_LEN,ptrData->string);
// strcpy((char*) data, ptrData->string);
//printf("\tComConduit:GetData: %d\n",ptrData->string[1]);
/* Copy the wchar_t-string manual */
for (ii=0; ii<ptrData->string[1]+EXTRA_LEN; ii++)
{
data[ii] = ptrData->string[ii];
//printf("\nGetData:data[%d]: %d \n", ii, data[ii]);
}
/* Stop with a "null" char */
data[ii] = (wchar_t) '\0';
//printf("\nGetData:data[%d]: %d \n", ii, data[ii]);
// Release lock
if(!ReleaseLock())
return false;
return true;
}
|