@@ -131,6 +131,7 @@ CKodiNode::CKodiNode(boost::asio::io_service *pIos, const int pHwdID, const int
131
131
{
132
132
m_stoprequested = false ;
133
133
m_Busy = false ;
134
+ m_Stoppable = false ;
134
135
135
136
m_Ios = pIos;
136
137
m_HwdID = pHwdID;
@@ -256,6 +257,9 @@ void CKodiNode::handleMessage(std::string& pMessage)
256
257
{
257
258
if ((root.isMember (" result" ) && (root.isMember (" id" ))))
258
259
{
260
+ bool bCanShutdown = false ;
261
+ bool bCanHibernate = false ;
262
+ bool bCanSuspend = false ;
259
263
int iMessageID = root[" id" ].asInt ();
260
264
switch (iMessageID)
261
265
{
@@ -335,9 +339,6 @@ void CKodiNode::handleMessage(std::string& pMessage)
335
339
case 4 : // Shutdown details response
336
340
{
337
341
std::string sAction = " Nothing" ;
338
- bool bCanShutdown = false ;
339
- bool bCanHibernate = false ;
340
- bool bCanSuspend = false ;
341
342
if (root[" result" ].isMember (" canshutdown" ))
342
343
{
343
344
bCanShutdown = root[" result" ][" canshutdown" ].asBool ();
@@ -375,6 +376,22 @@ void CKodiNode::handleMessage(std::string& pMessage)
375
376
if (root[" result" ] != " OK" )
376
377
_log.Log (LOG_ERROR, " Kodi: (%s) Send Command Failed: '%s'" , m_Name.c_str (), root[" result" ].asCString ());
377
378
break ;
379
+ case 7 : // Can Shutdown response (after connect)
380
+ handleWrite (std::string (" {\" jsonrpc\" :\" 2.0\" ,\" method\" :\" Player.GetActivePlayers\" ,\" id\" :5}" ));
381
+ if (root[" result" ].isMember (" canshutdown" ))
382
+ {
383
+ bCanShutdown = root[" result" ][" canshutdown" ].asBool ();
384
+ }
385
+ if (root[" result" ].isMember (" canhibernate" ))
386
+ {
387
+ bCanHibernate = root[" result" ][" canhibernate" ].asBool ();
388
+ }
389
+ if (root[" result" ].isMember (" cansuspend" ))
390
+ {
391
+ bCanSuspend = root[" result" ][" cansuspend" ].asBool ();
392
+ }
393
+ m_Stoppable = (bCanShutdown || bCanHibernate || bCanSuspend);
394
+ break ;
378
395
default :
379
396
_log.Log (LOG_ERROR, " Kodi: (%s) Message error, unknown ID found: '%s'" , m_Name.c_str (), pMessage.c_str ());
380
397
}
@@ -445,7 +462,7 @@ void CKodiNode::handleConnect()
445
462
}
446
463
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, sizeof m_Buffer),
447
464
boost::bind (&CKodiNode::handleRead, shared_from_this (), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
448
- handleWrite (std::string (" {\" jsonrpc\" :\" 2.0\" ,\" method\" :\" Player.GetActivePlayers \" ,\" id\" :5 }" ));
465
+ handleWrite (std::string (" {\" jsonrpc\" :\" 2.0\" ,\" method\" :\" System.GetProperties \" ,\" params \" :{ \" properties \" :[ \" canhibernate \" , \" cansuspend \" , \" canshutdown \" ]}, \" id\" :7 }" ));
449
466
}
450
467
else
451
468
{
@@ -643,7 +660,7 @@ bool CKodiNode::SendShutdown()
643
660
std::string sMessage = " {\" jsonrpc\" :\" 2.0\" ,\" method\" :\" System.GetProperties\" ,\" params\" :{\" properties\" :[\" canhibernate\" ,\" cansuspend\" ,\" canshutdown\" ]},\" id\" :4}" ;
644
661
handleWrite (sMessage );
645
662
646
- return false ;
663
+ return m_Stoppable ;
647
664
}
648
665
649
666
std::vector<boost::shared_ptr<CKodiNode> > CKodi::m_pNodes;
0 commit comments