University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Using JAVA Client to send VHMSG to SmartBody | General SmartBody Discussion | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Using JAVA Client to send VHMSG to SmartBody
February 12, 2017
6:45 am
Avatar
Member
Members
Forum Posts: 3
Member Since:
February 12, 2017
sp_UserOfflineSmall Offline

hello all

I currently work on a project to port SmartBody and FAtiMA to reflect the emotional state of an agent FAtiMA on a character of SmartBody, I considered several approaches (Sockets, Native API), but it seems to me that the " Approach via sending VHMSG messages to SmartBody is the most appropriate, nevertheless I do not know how to do it, I installed ActiveMQ I sent messages to the tpoic DEFAULT_SCOPE (ex: sb scene.run (' 'Somepytonfile.py' '), but looking in the list of messages I do not find stacked in the topic
If you have an example of communication via VHMSG (whatever the language) it will be of great help to me
Thank you for your efforts.

February 12, 2017
9:05 am
Avatar
Admin
Forum Posts: 944
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

SmartBody uses the VHMSG system to communicate among components. VHMSG uses ActiveMQ, but encodes part of the message, here's a code snippet from the VHMSG library inside the SmartBody distribution:

 

bool Client::Send( const char * op, const char * arg )
{
string arg_encoded = encodeString(arg);
string mess = string( op ) + " " + arg_encoded;

cms::TextMessage * message = NULL;
try
{
message = pimpl->m_session->createTextMessage( mess );
}
catch ( cms::CMSException & )
{
return false;
}

message->setStringProperty( "ELVISH_SCOPE", pimpl->m_scope );
message->setStringProperty( "MESSAGE_PREFIX", op );

try
{
pimpl->m_producer->send( message );
}
catch ( cms::CMSException & )
{
delete message;
return false;
}

delete message;
return true;
}

 

and here's the string encoding:

 

static string encodeString(const string & in_string)
{
// copied from bool Client::Send( const char * op, const char * arg )
#ifdef ANDROID_BUILD
return HtppUtility_UrlEncode_ByteChar(in_string);
#else
return vhcl::WStringToAnsi( HtppUtility_UrlEncode( vhcl::AnsiToWString( in_string ) ) );
#endif
}

So you can see that it takes the first parameter and attaches it to an encoded part of the rest of the message, and sets properties on the message. essentially, that's it.

You can use the VHMSG C++ library if you like or you can write your own.

 

Ari

February 12, 2017
11:07 am
Avatar
Member
Members
Forum Posts: 3
Member Since:
February 12, 2017
sp_UserOfflineSmall Offline

Hello and thank you for your fast and effective answer, but I still have some points to clear up
1- in the "lib" directory I found only .lib files not .dll files (or sources)
2- where to find the lib API's doc
3- if the lib is to be used on the client side (java), is there something to do on SmartBody side (in the gui or python script)

thanks

 

 

February 12, 2017
11:40 am
Avatar
Admin
Forum Posts: 944
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

You can get the VHMSG sources from here: https://svn.ict.usc.edu/svn_vh_public/trunk/lib/vhmsg 

 

which include a Java API.

February 13, 2017
12:32 am
Avatar
Member
Members
Forum Posts: 3
Member Since:
February 12, 2017
sp_UserOfflineSmall Offline

first, thank you for your kind assistance
I explored the source code and found one of the examples of using the VHMSG
via Java "class https://svn.ict.usc.edu/svn_vh_public/trunk/lib/vhmsg/vhmsg-java/src /edu/usc/ict/vhmsg/VHMsg.java "
that I used in a java program to send BML commands to SmartBody, here are the steps :

1-install ActiveMQ and run it as a service.

2-dowload the example source from https://svn.ict.usc.edu/svn_vh_public/trunk/lib/vhmsg/vhmsg-java/src/edu/usc/ict/vhmsg/

3- write à simple java class "VHMSGClient"

package edu.ustmb.vhmsg;

import edu.usc.ict.vhmsg.MessageEvent;

import edu.usc.ict.vhmsg.MessageListener;

import edu.usc.ict.vhmsg.VHMsg;

 

public class VHMSGClient implements MessageListener {

      

       public static void main(String[] args) {

             // TODO Auto-generated method stub

             VHMsg vhmsgClient = new VHMsg();

             vhmsgClient.openConnection();

             vhmsgClient.addMessageListener(new VHMSGClient());

             vhmsgClient.sendMessage("sb", "bml.execBML('*', '<head type="NOD"/>')");

       }

 

       @Override

       public void messageAction(MessageEvent e) {

             // TODO Auto-generated method stub

             System.out.println(e.toString());

       }

}

4- run SmartBody's gui and load a the HeadDemo script, comment out the animation instructions, and enable vhmsg service (in the left panel"

5- run the simple class, et voilà

February 13, 2017
10:17 am
Avatar
Admin
Forum Posts: 944
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Excellent!

You can write whatever functions or logic you want in SmartBody; it will respond to the 'sb' VHMSG command. So if you write a function called foo() in SmartBody, you can send it a message like this:

sb foo()

 

Ari

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 733

Currently Online: bonadio56, irmawy11
25 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Member Stats:

Guest Posters: 61

Members: 11750

Moderators: 3

Admins: 4

Forum Stats:

Groups: 1

Forums: 5

Topics: 409

Posts: 2264