Commit ed9473bf authored by Pavel Vainerman's avatar Pavel Vainerman

Added 'mtype' for TextMessage.

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