Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added corba implementation to modeq. Accessed with +d=interactiveCorba.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1061 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Peter Aronsson
committed
Jan 7, 2004
1 parent
d220b8b
commit 6a61bc5
Showing
8 changed files
with
277 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include "modeq_communication.h" | ||
#include "modeq_communication_impl.h" | ||
|
||
|
||
|
||
extern "C" { | ||
#include "rml.h" | ||
#include "../values.h" | ||
#include <stdio.h> | ||
#include "../absyn_builder/yacclib.h" | ||
#include <pthread.h> | ||
} | ||
|
||
#include <cstdlib> | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
pthread_mutex_t lock; | ||
|
||
// Condition variable for keeping modeq waiting for client requests | ||
pthread_cond_t modeq_waitformsg; | ||
pthread_mutex_t modeq_waitlock; | ||
bool modeq_waiting=false; | ||
|
||
// Condition variable for keeping corba waiting for returnvalue from modeq | ||
pthread_cond_t corba_waitformsg; | ||
pthread_mutex_t corba_waitlock; | ||
bool corba_waiting=false; | ||
|
||
char * modeq_message; | ||
|
||
|
||
CORBA::ORB_var orb; | ||
CORBA::BOA_var boa; | ||
|
||
ModeqCommunication_impl * server; | ||
|
||
extern "C" { | ||
void writeServerId(CORBA::ORB_var orb); | ||
void* runOrb(void*arg); | ||
|
||
void Corba_5finit(void) | ||
{ | ||
|
||
} | ||
|
||
RML_BEGIN_LABEL(Corba__initialize) | ||
{ | ||
char *dummyArgv="modeq"; | ||
int zero=0; | ||
pthread_cond_init(&modeq_waitformsg,NULL); | ||
pthread_cond_init(&corba_waitformsg,NULL); | ||
pthread_mutex_init(&corba_waitlock,NULL); | ||
pthread_mutex_init(&modeq_waitlock,NULL); | ||
|
||
orb = CORBA::ORB_init(zero, 0,"mico-local-orb"); | ||
boa = orb->BOA_init(zero,0,"mico-local-boa"); | ||
|
||
server = new ModeqCommunication_impl(); | ||
|
||
writeServerId(orb); | ||
boa->impl_is_ready(CORBA::ImplementationDef::_nil()); | ||
|
||
// Start thread that listens on incomming messages. | ||
pthread_t orb_thr_id; | ||
if( pthread_create(&orb_thr_id,NULL,&runOrb,NULL)) { | ||
cerr << "Error creating thread for corba communication." << endl; | ||
RML_TAILCALLK(rmlFC); | ||
} | ||
|
||
std::cout << "Created server." << std::endl; | ||
RML_TAILCALLK(rmlSC); | ||
} | ||
RML_END_LABEL | ||
|
||
void* runOrb(void* arg) | ||
{ | ||
orb->run(); | ||
CORBA::release(server); | ||
return NULL; | ||
} | ||
|
||
void writeServerId(CORBA::ORB_var orb) | ||
{ | ||
ofstream tmpFile ("/tmp/openmodelica.objid"); // Should be different on Windows | ||
CORBA::String_var ref = orb->object_to_string(server); | ||
tmpFile << ref << endl; | ||
tmpFile.close(); | ||
} | ||
|
||
RML_BEGIN_LABEL(Corba__wait_5ffor_5fcommand) | ||
{ | ||
pthread_mutex_lock(&modeq_waitlock); | ||
while (!modeq_waiting) { | ||
pthread_cond_wait(&modeq_waitformsg,&modeq_waitlock); | ||
} | ||
modeq_waiting = false; | ||
pthread_mutex_unlock(&modeq_waitlock); | ||
|
||
rmlA0=mk_scon(modeq_message); | ||
pthread_mutex_lock(&lock); // Lock so no other tread can talk to modeq. | ||
RML_TAILCALLK(rmlSC); | ||
} | ||
RML_END_LABEL | ||
|
||
RML_BEGIN_LABEL(Corba__sendreply) | ||
{ | ||
char *msg=RML_STRINGDATA(rmlA0); | ||
|
||
// Signal to Corba that it can return, taking the value in message | ||
pthread_mutex_lock(&corba_waitlock); | ||
corba_waiting=true; | ||
modeq_message =CORBA::string_dup(msg); | ||
|
||
pthread_cond_signal(&corba_waitformsg); | ||
pthread_mutex_unlock(&corba_waitlock); | ||
|
||
pthread_mutex_unlock(&lock); // Unlock, so other threads can ask modeq stuff. | ||
RML_TAILCALLK(rmlSC); | ||
} | ||
RML_END_LABEL | ||
|
||
RML_BEGIN_LABEL(Corba__close) | ||
{ | ||
boa->deactivate_impl(CORBA::ImplementationDef::_nil()); | ||
orb->shutdown(TRUE); | ||
pthread_yield(); // Allowing other thread to shutdown. | ||
RML_TAILCALLK(rmlSC); | ||
} | ||
RML_END_LABEL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// As simple as can be modeq communication, sending and recieving of strings. | ||
|
||
interface ModeqCommunication { | ||
string sendExpression( in string expr); | ||
string sendClass( in string model); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "modeq_communication_impl.h" | ||
|
||
extern "C" { | ||
#include "rml.h" | ||
#include <pthread.h> | ||
} | ||
|
||
extern pthread_cond_t modeq_waitformsg; | ||
extern pthread_mutex_t modeq_waitlock; | ||
|
||
extern bool modeq_waiting; | ||
|
||
extern pthread_cond_t corba_waitformsg; | ||
extern pthread_mutex_t corba_waitlock; | ||
|
||
extern bool corba_waiting; | ||
|
||
extern char * modeq_message; | ||
using namespace std; | ||
|
||
//This is the implementation of the modeq communication using mico (CORBA) | ||
|
||
ModeqCommunication_impl::ModeqCommunication_impl() | ||
{ | ||
} | ||
|
||
char* ModeqCommunication_impl::sendExpression( const char* expr ) | ||
{ | ||
char* result; | ||
// Signal to modeq that message has arrived. | ||
pthread_mutex_lock(&modeq_waitlock); | ||
modeq_waiting=true; | ||
modeq_message = (char*)expr; | ||
pthread_cond_signal(&modeq_waitformsg); | ||
pthread_mutex_unlock(&modeq_waitlock); | ||
|
||
// Wait for modeq to process message | ||
pthread_mutex_lock(&corba_waitlock); | ||
while (!corba_waiting) { | ||
pthread_cond_wait(&corba_waitformsg,&corba_waitlock); | ||
} | ||
corba_waiting = false; | ||
pthread_mutex_unlock(&corba_waitlock); | ||
|
||
return modeq_message; // Has already been string_dup (prepared for CORBA) | ||
} | ||
|
||
char* ModeqCommunication_impl::sendClass( const char* expr ) | ||
{ | ||
// Signal to modeq that message has arrived. | ||
pthread_mutex_lock(&modeq_waitlock); | ||
modeq_waiting=true; | ||
modeq_message = (char*)expr; | ||
pthread_cond_signal(&modeq_waitformsg); | ||
pthread_mutex_unlock(&modeq_waitlock); | ||
|
||
// Wait for modeq to process message | ||
pthread_mutex_lock(&corba_waitlock); | ||
|
||
while (!modeq_waiting) { | ||
pthread_cond_wait(&corba_waitformsg,&corba_waitlock); | ||
} | ||
corba_waiting = false; | ||
pthread_mutex_unlock(&corba_waitlock); | ||
|
||
return modeq_message; // Has already been string_dup (prepared for CORBA) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef _MODEQ_COMMUNICATION_IMPL_H | ||
#define _MODEQ_COMMUNICATION_IMPL_H | ||
#include "modeq_communication.h" | ||
|
||
class ModeqCommunication_impl : virtual public ModeqCommunication_skel{ | ||
public: | ||
ModeqCommunication_impl(); | ||
char* sendExpression( const char* expr ); | ||
char* sendClass( const char* expr ); | ||
}; | ||
|
||
|
||
#endif |