Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions native/remoting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ if (WIN32)
# shared memory server
add_executable(server_sm
communication.c communication.h
process.c process.h
process.c process.h
remote.c remote.h
server.c server.h
${CMAKE_CURRENT_BINARY_DIR}/config.h
Expand All @@ -163,7 +163,7 @@ if (WIN32)
add_library(client_sm SHARED
client.c client.h
communication.c communication.h
process.c process.h
process.c process.h
remote.c remote.h
${CMAKE_CURRENT_BINARY_DIR}/config.h
)
Expand Down
16 changes: 8 additions & 8 deletions native/remoting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ Considering win64 FMU, only the `binaries/win64` folder is populated. It contain
#### Add remoting win32: simulate 64bits FMU 32 bits OS
1. Copy `client_sm.dll` (32 bits) as `model.dll` in `binaries/win32`
2. Copy `server_sm.exe` (64 bits) in `binaries/win64`

When Simulation Enviroment will use the FMU on 32 bits OS:
1. it will load `win32/model.dll` (which is a copy of `client_sm.dll`)
2. which will communicate with `win64/server_exe`.
3. which will load `win64/model.dll`
3. which will load `win64/model.dll`

#### Add remoting win64: simulate 32 bits FMU 64 bits OS
1. Copy `client_sm.dll` (64 bits) as `model.dll` in `binaries/win64`
3. Copy `server_sm.exe` (32 bits) in `binaries/win32`

When Simulation Enviroment will use the FMU on 64bits kernel:
1. it will load `win64/model.dll` (which is a copy of `client_sm.dll`)
2. which will communicate with `win32/server_exe`.
3. which will load `win32/model.dll`
3. which will load `win32/model.dll`


## TODO List
Expand All @@ -79,15 +79,15 @@ provided that the following conditions are met:
and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with
and the following disclaimer in the documentation and/or other materials provided with
the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
8 changes: 4 additions & 4 deletions native/remoting/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


/*----------------------------------------------------------------------------
L O G G E R
L O G G E R
----------------------------------------------------------------------------*/

#define _LOG(client, level, ...) client_logger(client, level, ##__VA_ARGS__)
Expand Down Expand Up @@ -89,7 +89,7 @@ static fmi2Status make_rpc(client_t* client, remote_function_t function) {
remote_data_t *remote_data = client->communication->data;

fmi2Status status = (fmi2Status)-1;

/* Flush message log */
remote_data->message[0] = '\0';

Expand All @@ -106,7 +106,7 @@ static fmi2Status make_rpc(client_t* client, remote_function_t function) {
LOG_DEBUG(client, "Waiting for server...");
}

status = remote_data->status;
status = remote_data->status;
CLIENT_LOG("RPC: %s | reply = %d\n", remote_function_name(function), status);

if (remote_data->message[0]) {
Expand Down Expand Up @@ -134,7 +134,7 @@ static char* dirname(char* path) {
}
return path;
}


static int get_server_bitness(void) {
/* current process (calling this dll) is 64bits, the server is 32 bits */
Expand Down
24 changes: 12 additions & 12 deletions native/remoting/client_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static string wslpath(const string &path) {

transform(driveLetter.begin(), driveLetter.end(), driveLetter.begin(), [](unsigned char c) { return tolower(c); });

string p = path.substr(colon + 1, path.length());
string p = path.substr(colon + 1, path.length());

replace(p.begin(), p.end(), '\\', '/');

Expand All @@ -99,7 +99,7 @@ static string wslpath(const string &path) {

/* Creation and destruction of FMU instances and setting debug status */
fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuResourceLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) {

if (!functions || !functions->logger) {
return NULL;
}
Expand Down Expand Up @@ -134,11 +134,11 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
if (!modelIdentifier.compare("client_tcp")) {

s_logger(s_componentEnvironment, instanceName, fmi2OK, "info", "Remoting server started externally.");

} else {

// linux64 on Windows via WSL

char tempPath[MAX_PATH] = "";
char lockFile[MAX_PATH] = "";

Expand Down Expand Up @@ -178,7 +178,7 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
FALSE, // set handle inheritance to FALSE
0, // CREATE_NO_WINDOW, // creation flags
NULL, // use parent's environment block
NULL, // use parent's starting directory
NULL, // use parent's starting directory
&si, // pointer to STARTUPINFO structure
&s_proccessInfo // pointer to PROCESS_INFORMATION structure
);
Expand All @@ -200,15 +200,15 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
const string filename(info.dli_fname);

const string linux64Path = filename.substr(0, filename.find_last_of('/'));

const string modelIdentifier = filename.substr(filename.find_last_of('/') + 1, filename.find_last_of('.') - filename.find_last_of('/') - 1);

const string binariesPath = linux64Path.substr(0, linux64Path.find_last_of('/'));

if (!modelIdentifier.compare("client_tcp")) {

s_logger(s_componentEnvironment, instanceName, fmi2OK, "info", "Remoting server started externally.");

} else {

// create lock file
Expand All @@ -232,7 +232,7 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
// lock entire file
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;
fl.l_len = 0;
fl.l_pid = 0;

if (fcntl(lockFile, F_SETLKW, &fl) == -1) {
Expand Down Expand Up @@ -288,7 +288,7 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
try {
s_logger(s_componentEnvironment, instanceName, fmi2OK, "info", "Trying to connect...");
client = new rpc::client("localhost", rpc::constants::DEFAULT_PORT);
r = client->call("fmi2Instantiate", instanceName, (int)fmuType, fmuGUID ? fmuGUID : "",
r = client->call("fmi2Instantiate", instanceName, (int)fmuType, fmuGUID ? fmuGUID : "",
fmuResourceLocation ? fmuResourceLocation : "", visible, loggingOn).as<ReturnValue>();
break;
} catch (exception e) {
Expand All @@ -302,7 +302,7 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
}
}
}

s_logger(s_componentEnvironment, instanceName, fmi2OK, "info", "Connected.");

forwardLogMessages(r.logMessages);
Expand All @@ -325,7 +325,7 @@ void fmi2FreeInstance(fmi2Component c) {
killpg(s_pid, SIGKILL);

int status;

while (wait(&status) > 0) {
s_logger(s_componentEnvironment, s_instanceName, fmi2OK, "info", "Waiting for child processes to terminate.");
}
Expand Down
10 changes: 5 additions & 5 deletions native/remoting/client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template<typename T> T *get(void *libraryHandle, const char *functionName) {
# endif

void logger(fmi2ComponentEnvironment componentEnvironment, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...) {

printf("[%d][%s] ", status, instanceName);

va_list args;
Expand All @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) {
}

const char *libraryPath = argv[1];

// load the shared library
# ifdef _WIN32
auto l = LoadLibraryA(libraryPath);
Expand Down Expand Up @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) {
cout << "Types Platform: " << typesPlatform << endl;

auto version = getVersion();

cout << "FMI Version: " << version << endl;

fmi2CallbackFunctions functions = { logger, nullptr, nullptr, nullptr, nullptr };
Expand Down Expand Up @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) {
}

CALL(terminate(c));

freeInstance(c);

out:
Expand All @@ -128,4 +128,4 @@ int main(int argc, char *argv[]) {
#endif

return status;
}
}
14 changes: 7 additions & 7 deletions native/remoting/communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static sem_handle_t communication_sem_create(const char *name) {
#else
SHM_LOG("Create SEM %s\n", name);
FILE *sem_file = fopen(name, "w");
if (!sem_file)
if (!sem_file)
return SEM_INVALID;
fclose(sem_file);
sem = semget(ftok(name, 0), 1, IPC_CREAT | IPC_EXCL | 0600);
Expand Down Expand Up @@ -87,7 +87,7 @@ static void communication_sem_free(sem_handle_t sem, const char *sem_name) {
#endif

return;
}
}


static void communication_shm_free(shm_handle_t map_file, const char *shm_name) {
Expand All @@ -109,7 +109,7 @@ static shm_handle_t communication_shm_create(const char *shm_name, size_t memory
0, // maximum object size (high-order DWORD)
memory_size, // maximum object size (low-order DWORD)
shm_name); // name of mapping object

#else
map_file = shm_open(
shm_name,
Expand All @@ -118,7 +118,7 @@ static shm_handle_t communication_shm_create(const char *shm_name, size_t memory
ftruncate(map_file, memory_size);
#endif
SHM_LOG("SHM `%s' create. Notify server.\n", shm_name);

return map_file;
}

Expand Down Expand Up @@ -255,7 +255,7 @@ communication_t *communication_new(const char *prefix, size_t memory_size, commu
status = communication_new_client(communication);
else
status = communication_new_server(communication);

if (status) {
communication_free(communication);
return NULL;
Expand Down Expand Up @@ -350,7 +350,7 @@ int communication_timedwaitfor_server(const communication_t* communication, int
setitimer(ITIMER_REAL, &old_value, NULL);
if (status < 0)
return errno == EINTR;

return 0;
# endif
#endif
Expand Down Expand Up @@ -403,7 +403,7 @@ int communication_timedwaitfor_client(const communication_t* communication, int
setitimer(ITIMER_REAL, &old_value, NULL);
if (status < 0)
return errno == EINTR;

return 0;
# endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion native/remoting/gen_sizeof.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generate test_sizeof.c for basic sanity checks.

import sys
import os

Expand Down
8 changes: 4 additions & 4 deletions native/remoting/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# include <windows.h>
#else
# include <dlfcn.h>
# include <stdlib.h>
# include <stdlib.h>
# include <signal.h>
# include <string.h>
# include <errno.h>
Expand Down Expand Up @@ -51,7 +51,7 @@ process_handle_t process_spawn(char *const argv[]) {
FALSE, // set handle inheritance to FALSE
0, // creation flags
NULL, // use parent's environment block
NULL, // use parent's starting directory
NULL, // use parent's starting directory
&si, // pointer to STARTUPINFO structure
&pi // pointer to PROCESS_INFORMATION structure
)) {
Expand All @@ -62,7 +62,7 @@ process_handle_t process_spawn(char *const argv[]) {
switch(handle = fork()) {
case -1:
return -1;

case 0:
/* CHILD (server) */
execv(argv[0], argv);
Expand Down Expand Up @@ -99,7 +99,7 @@ void process_waitfor(process_handle_t handle) {
#ifdef WIN32
WaitForSingleObject(handle, INFINITE);
#else
int reason;
int reason;
waitpid(handle, &reason, WNOHANG);
#endif
}
2 changes: 1 addition & 1 deletion native/remoting/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef unsigned long portable_size_t;
#define REMOTE_ENCODE_PTR(_data, _n, _ptr, _len) memcpy(_data + _n*REMOTE_ARG_SIZE, _ptr, sizeof(*_ptr)*_len)
#define REMOTE_ENCODE_STR(_data, _n, _ptr) strncpy(_data + _n*REMOTE_ARG_SIZE, _ptr, REMOTE_ARG_SIZE)

#define REMOTE_DECODE_VAR(_data, _n, _type) (*((_type *)(_data + _n*REMOTE_ARG_SIZE)))
#define REMOTE_DECODE_VAR(_data, _n, _type) (*((_type *)(_data + _n*REMOTE_ARG_SIZE)))
#define REMOTE_DECODE_PTR(_data, _n, _type) ((_type)(_data + _n*REMOTE_ARG_SIZE))
#define REMOTE_DECODE_STR(_data, _n) REMOTE_DECODE_PTR(_data, _n, fmi2String)

Expand Down
2 changes: 1 addition & 1 deletion native/remoting/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void server_logger(fmi2ComponentEnvironment componentEnvironment,
if (server) {
remote_data_t* remote_data = server->communication->data;
const size_t offset = strlen(remote_data->message);


va_start(params, message);
vsnprintf(remote_data->message + offset, REMOTE_MESSAGE_SIZE - offset, message, params);
Expand Down
Loading