Commit ed9473bf authored by Pavel Vainerman's avatar Pavel Vainerman

Added 'mtype' for TextMessage.

parent 8f3305c5
......@@ -55,6 +55,7 @@
/*! Функция посылки текстового сообщения объекту */
void pushMessage( in string msg
, in long mtype
, in uniset::Timespec tm
, in uniset::ProducerInfo pi
, in long priority
......
......@@ -78,7 +78,7 @@ int getState( const string& args, UInterface& ui );
int getCalibrate( const string& args, UInterface& ui );
int oinfo(const string& args, UInterface& ui , const string& userparam );
int apiRequest( const string& args, UInterface& ui, const string& query );
void sendText( const string& args, UInterface& ui, const string& txt );
void sendText( const string& args, UInterface& ui, const string& txt, int mtype );
// --------------------------------------------------------------------------
static void print_help(int width, const string& cmd, const string& help, const string& tab = " " )
{
......@@ -125,7 +125,7 @@ static void usage()
print_help(36, "-v|--verbose", "Подробный вывод логов.\n");
print_help(36, "-q|--quiet", "Выводит только результат.\n");
print_help(36, "-z|--csv", "Вывести результат (getValue) в виде val1,val2,val3...\n");
print_help(36, "-m|--sendText id1@node1,id2@node2,id3,.. text", "Послать объектам текстовое сообщение text\n");
print_help(36, "-m|--sendText id1@node1,id2@node2,id3,.. mtype text", "Послать объектам текстовое сообщение text типа mtype\n");
cout << endl;
}
......@@ -377,17 +377,35 @@ int main(int argc, char** argv)
if( checkArg(optind, argc, argv) == 0 )
{
if( !quiet )
cerr << "admin(sendText): Unknown 'text'. Use: id,name,name2@nodeX text" << endl;
cerr << "admin(sendText): Unknown 'mtype'. Use: id,name,name2@nodeX mtype text" << endl;
return 1;
}
ostringstream txt;
if( checkArg(optind+1, argc, argv) == 0 )
{
if( !quiet )
cerr << "admin(sendText): Unknown 'text'. Use: id,name,name2@nodeX mtype text" << endl;
return 1;
}
for( int i=optind+1; i<argc; i++ )
{
if( checkArg(i, argc, argv) == 0 )
break;
txt << " " << argv[optind+1];
}
auto conf = uniset_init(argc, argv, conffile);
UInterface ui(conf);
ui.initBackId(uniset::AdminID);
std::string txt = string(argv[optind]);
int mtype = uni_atoi(argv[optind]);
sendText(optarg, ui, txt);
sendText(optarg, ui, txt.str(), mtype);
return 0;
}
break;
......@@ -1111,7 +1129,7 @@ int apiRequest( const string& args, UInterface& ui, const string& query )
}
// --------------------------------------------------------------------------------------
void sendText( const string& args, UInterface& ui, const string& txt )
void sendText( const string& args, UInterface& ui, const string& txt, int mtype )
{
auto conf = uniset_conf();
auto sl = uniset::getObjectsList( args, conf );
......
......@@ -138,11 +138,12 @@ void DBServer_MySQL::onTextMessage( const TextMessage* msg )
ostringstream data;
data << "INSERT INTO " << tblName(msg->type)
<< "(date, time, time_usec, text, node) VALUES( '"
<< "(date, time, time_usec, text, mtype, node) VALUES( '"
<< dateToString(msg->tm.tv_sec, "-") << "','" // date
<< timeToString(msg->tm.tv_sec, ":") << "','" // time
<< msg->tm.tv_nsec << "','" // time_usec
<< msg->txt << "','" // text
<< msg->mtype << "','" // mtype
<< msg->node << "')"; // node
dbinfo << myname << "(insert_main_messages): " << data.str() << endl;
......
......@@ -128,11 +128,12 @@ void DBServer_PostgreSQL::onTextMessage( const TextMessage* msg )
{
ostringstream data;
data << "INSERT INTO " << tblName(msg->type)
<< "(date, time, time_usec, text, node) VALUES( '"
<< "(date, time, time_usec, text, mtype, node) VALUES( '"
<< dateToString(msg->tm.tv_sec, "-") << "','" // date
<< timeToString(msg->tm.tv_sec, ":") << "','" // time
<< msg->tm.tv_nsec << "','" // time_usec
<< msg->txt << "','" // text
<< msg->mtype << "','" // mtype
<< msg->node << "')"; // node
dbinfo << myname << "(insert_main_messages): " << data.str() << endl;
......
......@@ -125,11 +125,12 @@ void DBServer_SQLite::onTextMessage( const TextMessage* msg )
{
ostringstream data;
data << "INSERT INTO " << tblName(msg->type)
<< "(date, time, time_usec, text, node) VALUES( '"
<< "(date, time, time_usec, text, mtype, node) VALUES( '"
<< dateToString(msg->tm.tv_sec, "-") << "','" // date
<< timeToString(msg->tm.tv_sec, ":") << "','" // time
<< msg->tm.tv_nsec << "','" // time_usec
<< msg->txt << "','" // text
<< msg->mtype << "','" // mtype
<< msg->node << "')"; // node
dbinfo << myname << "(insert_main_messages): " << data.str() << endl;
......
......@@ -59,6 +59,7 @@ void TestObject::sensorInfo( const SensorMessage* sm )
void TestObject::onTextMessage( const TextMessage* msg )
{
lastText = msg->txt;
lastTextType = msg->mtype;
}
// -----------------------------------------------------------------------------
void TestObject::stopHeartbeat()
......@@ -112,4 +113,9 @@ string TestObject::getLastTextMessage() const
{
return lastText;
}
int TestObject::getLastTextMessageType() const
{
return lastTextType;
}
// -----------------------------------------------------------------------------
......@@ -37,6 +37,7 @@ class TestObject:
bool isFullQueue();
std::string getLastTextMessage() const;
int getLastTextMessageType() const;
protected:
TestObject();
......@@ -52,6 +53,7 @@ class TestObject:
long lostMessages = { false };
long lastValue = { 0 };
std::string lastText = { "" };
int lastTextType = { 0 };
};
// -----------------------------------------------------------------------------
#endif // _TestObject_H_
......
......@@ -317,8 +317,9 @@ TEST_CASE("[SM]: sendText", "[sm][sendText]")
std::string txt = "Hello world";
ui->sendText(obj->getId(), txt);
ui->sendText(obj->getId(), txt, 3);
msleep(300);
REQUIRE( obj->getLastTextMessage() == txt );
REQUIRE( obj->getLastTextMessageType() == 3 );
}
......@@ -287,6 +287,7 @@ namespace uniset
TextMessage() noexcept;
TextMessage( const VoidMessage* msg ) noexcept;
TextMessage( const char* msg,
int mtype,
const ::uniset::Timespec& tm,
const ::uniset::ProducerInfo& pi,
Priority prior = Message::Medium,
......@@ -295,6 +296,7 @@ namespace uniset
std::shared_ptr<VoidMessage> toLocalVoidMessage() const;
std::string txt;
int mtype;
};
}
......
......@@ -233,7 +233,7 @@ namespace uniset
/*! посылка сообщения msg объекту name на узел node */
void send( const uniset::ObjectId name, const uniset::TransportMessage& msg, uniset::ObjectId node );
void send( const uniset::ObjectId name, const uniset::TransportMessage& msg);
void sendText(const uniset::ObjectId name, const std::string& text, const uniset::ObjectId node = uniset::DefaultObjectId );
void sendText(const uniset::ObjectId name, const std::string& text, int mtype, const uniset::ObjectId node = uniset::DefaultObjectId );
void sendText(const uniset::ObjectId name, const uniset::TextMessage& msg, const uniset::ObjectId node = uniset::DefaultObjectId );
// ---------------------------------------------------------------
......
......@@ -109,6 +109,7 @@ namespace uniset
//! поместить текстовое сообщение в очередь
virtual void pushMessage( const char* msg,
::CORBA::Long mtype,
const ::uniset::Timespec& tm,
const ::uniset::ProducerInfo& pi,
::CORBA::Long priority,
......
......@@ -241,6 +241,7 @@ namespace uniset
tm = m->tm;
consumer = m->consumer;
supplier = m->supplier;
mtype = m->mtype;
txt = m->txt;
}
}
......@@ -250,7 +251,8 @@ namespace uniset
type = Message::TextMessage;
}
TextMessage::TextMessage( const char* msg,
TextMessage::TextMessage(const char* msg,
int _mtype,
const uniset::Timespec& tm,
const ::uniset::ProducerInfo& pi,
Priority prior,
......@@ -263,7 +265,8 @@ namespace uniset
this->consumer = cons;
this->tm.tv_sec = tm.sec;
this->tm.tv_nsec = tm.nsec;
txt = std::string(msg);
this->txt = std::string(msg);
this->mtype = _mtype;
}
//--------------------------------------------------------------------------------------------
std::shared_ptr<VoidMessage> TextMessage::toLocalVoidMessage() const
......@@ -276,7 +279,7 @@ namespace uniset
ts.sec = tm.tv_sec;
ts.nsec = tm.tv_nsec;
auto tmsg = std::make_shared<TextMessage>(txt.c_str(), ts, pi, priority, consumer);
auto tmsg = std::make_shared<TextMessage>(txt.c_str(), mtype, ts, pi, priority, consumer);
return std::static_pointer_cast<VoidMessage>(tmsg);
}
//--------------------------------------------------------------------------------------------
......
......@@ -1020,7 +1020,7 @@ namespace uniset
send(name, msg, uconf->getLocalNode());
}
// ------------------------------------------------------------------------------------------------------------
void UInterface::sendText( const ObjectId name, const std::string& txt, const ObjectId node )
void UInterface::sendText(const ObjectId name, const std::string& txt, int mtype, const ObjectId node )
{
if ( name == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(sendText): ERROR: id=uniset::DefaultObjectId");
......@@ -1051,7 +1051,7 @@ namespace uniset
oref = resolve( name, onode );
UniSetObject_i_var obj = UniSetObject_i::_narrow(oref);
obj->pushMessage(txt.c_str(), ts, pi, Message::Medium, uniset::DefaultObjectId);
obj->pushMessage(txt.c_str(), mtype, ts, pi, Message::Medium, uniset::DefaultObjectId);
return;
}
catch( const CORBA::TRANSIENT& ) {}
......@@ -1125,7 +1125,7 @@ namespace uniset
oref = resolve( name, onode );
UniSetObject_i_var obj = UniSetObject_i::_narrow(oref);
obj->pushMessage(msg.txt.c_str(),ts, pi, msg.priority, msg.consumer);
obj->pushMessage(msg.txt.c_str(), msg.mtype, ts, pi, msg.priority, msg.consumer);
return;
}
catch( const CORBA::TRANSIENT& ) {}
......
......@@ -400,13 +400,14 @@ namespace uniset
termWaiting();
}
// ------------------------------------------------------------------------------------------
void UniSetObject::pushMessage( const char* msg,
void UniSetObject::pushMessage(const char* msg,
::CORBA::Long mtype,
const ::uniset::Timespec& tm,
const ::uniset::ProducerInfo& pi,
::CORBA::Long priority,
::CORBA::Long consumer )
{
uniset::TextMessage tmsg(msg, tm, pi, (uniset::Message::Priority)priority, consumer);
uniset::TextMessage tmsg(msg, mtype, tm, pi, (uniset::Message::Priority)priority, consumer);
auto vm = tmsg.toLocalVoidMessage();
if( vm->priority == Message::Medium )
......
......@@ -260,25 +260,27 @@ TEST_CASE("TextMessage", "[basic][message types][TextMessage]" )
ObjectId consumer = 40;
TextMessage tm(txt.c_str(), tspec, pi, uniset::Message::High, consumer );
TextMessage tm(txt.c_str(), 3, tspec, pi, uniset::Message::High, consumer );
REQUIRE( tm.consumer == consumer );
REQUIRE( tm.node == pi.node );
REQUIRE( tm.supplier == pi.id );
REQUIRE( tm.txt == txt );
REQUIRE( tm.tm.tv_sec == tspec.sec );
REQUIRE( tm.tm.tv_nsec == tspec.nsec );
REQUIRE( tm.mtype == 3 );
auto vm = tm.toLocalVoidMessage();
REQUIRE( vm->type == Message::TextMessage );
TextMessage tm2(vm.get());
REQUIRE( tm.consumer == consumer );
REQUIRE( tm.node == pi.node );
REQUIRE( tm.supplier == pi.id );
REQUIRE( tm.txt == txt );
REQUIRE( tm.tm.tv_sec == tspec.sec );
REQUIRE( tm.tm.tv_nsec == tspec.nsec );
REQUIRE( tm2.consumer == consumer );
REQUIRE( tm2.node == pi.node );
REQUIRE( tm2.supplier == pi.id );
REQUIRE( tm2.txt == txt );
REQUIRE( tm2.tm.tv_sec == tspec.sec );
REQUIRE( tm2.tm.tv_nsec == tspec.nsec );
REQUIRE( tm2.mtype == 3 );
}
}
// ---------------------------------------------------------------
......@@ -44,8 +44,8 @@ TEST_CASE("UInterface", "[UInterface]")
REQUIRE_THROWS_AS( ui.getTimeChange(sid, -20), uniset::Exception );
REQUIRE_THROWS_AS( ui.getTimeChange(sid, DefaultObjectId), uniset::Exception );
REQUIRE_THROWS_AS( ui.getTimeChange(sid, conf->getLocalNode()), uniset::Exception );
REQUIRE_THROWS_AS( ui.sendText(testOID, "hello"), uniset::Exception );
REQUIRE_THROWS_AS( ui.sendText(testOID, "hello", -20), uniset::Exception );
REQUIRE_THROWS_AS( ui.sendText(testOID, "hello", 1), uniset::Exception );
REQUIRE_THROWS_AS( ui.sendText(testOID, "hello", 1, -20), uniset::Exception );
CHECK_FALSE( ui.isExist(sid) );
CHECK_FALSE( ui.isExist(sid, DefaultObjectId) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment