Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed May 20, 2022
1 parent 27c0f3d commit bde9a1b
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
* limitations under the License.
*/

#include "../../java/ContentAppCommandDelegate.h"
#include "AppContentLauncherManager.h"
#include "../../java/ContentAppCommandDelegate.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::DataModel;
using namespace chip::app::Clusters::ContentLauncher;
using ContentAppCommandDelegate = chip::AppPlatform::ContentAppCommandDelegate;
using ContentAppCommandDelegate = chip::AppPlatform::ContentAppCommandDelegate;

AppContentLauncherManager::AppContentLauncherManager(ContentAppCommandDelegate commandDelegate, list<std::string> acceptHeaderList, uint32_t supportedStreamingProtocols) : mCommandDelegate(commandDelegate)
AppContentLauncherManager::AppContentLauncherManager(ContentAppCommandDelegate commandDelegate, list<std::string> acceptHeaderList,
uint32_t supportedStreamingProtocols) :
mCommandDelegate(commandDelegate)
{
mAcceptHeaderList = acceptHeaderList;
mSupportedStreamingProtocols = supportedStreamingProtocols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ using chip::CharSpan;
using chip::EndpointId;
using chip::app::AttributeValueEncoder;
using chip::app::CommandResponseHelper;
using ContentLauncherDelegate = chip::app::Clusters::ContentLauncher::Delegate;
using LaunchResponseType = chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type;
using ParameterType = chip::app::Clusters::ContentLauncher::Structs::Parameter::DecodableType;
using BrandingInformationType = chip::app::Clusters::ContentLauncher::Structs::BrandingInformation::Type;
using ContentAppCommandDelegate = chip::AppPlatform::ContentAppCommandDelegate;
using ContentLauncherDelegate = chip::app::Clusters::ContentLauncher::Delegate;
using LaunchResponseType = chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type;
using ParameterType = chip::app::Clusters::ContentLauncher::Structs::Parameter::DecodableType;
using BrandingInformationType = chip::app::Clusters::ContentLauncher::Structs::BrandingInformation::Type;
using ContentAppCommandDelegate = chip::AppPlatform::ContentAppCommandDelegate;

class AppContentLauncherManager : public ContentLauncherDelegate
{
public:
AppContentLauncherManager(ContentAppCommandDelegate commandDelegate, std::list<std::string> acceptHeaderList, uint32_t supportedStreamingProtocols);
AppContentLauncherManager(ContentAppCommandDelegate commandDelegate, std::list<std::string> acceptHeaderList,
uint32_t supportedStreamingProtocols);

void HandleLaunchContent(CommandResponseHelper<LaunchResponseType> & helper,
const chip::app::DataModel::DecodableList<ParameterType> & parameterList, bool autoplay,
Expand All @@ -44,7 +45,7 @@ class AppContentLauncherManager : public ContentLauncherDelegate
CHIP_ERROR HandleGetAcceptHeaderList(AttributeValueEncoder & aEncoder) override;
uint32_t HandleGetSupportedStreamingProtocols() override;

void SetEndpointId(EndpointId epId) {mEndpointId = epId;};
void SetEndpointId(EndpointId epId) { mEndpointId = epId; };

protected:
std::list<std::string> mAcceptHeaderList;
Expand Down
47 changes: 28 additions & 19 deletions examples/tv-app/android/java/AppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <app/util/af.h>
#include <cstdio>
#include <inttypes.h>
#include <jni.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/DataModelTypes.h>
#include <lib/shell/Commands.h>
Expand All @@ -41,7 +42,6 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/ZclString.h>
#include <platform/CHIPDeviceLayer.h>
#include <jni.h>

using namespace chip;
using namespace chip::AppPlatform;
Expand Down Expand Up @@ -396,55 +396,64 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend
return nullptr;
}

EndpointId ContentAppFactoryImpl::AddContentApp(ContentAppImpl & app) {
EndpointId ContentAppFactoryImpl::AddContentApp(ContentAppImpl & app)
{
DataVersion dataVersionBuf[ArraySize(contentAppClusters)];
EndpointId epId = ContentAppPlatform::GetInstance().AddContentApp(&app, &contentAppEndpoint, Span<DataVersion>(dataVersionBuf),
Span<const EmberAfDeviceType>(gContentAppDeviceType));
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl AddContentApp endpoint returned %d. Endpoint set %d", epId, app.GetEndpointId());
Span<const EmberAfDeviceType>(gContentAppDeviceType));
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl AddContentApp endpoint returned %d. Endpoint set %d", epId,
app.GetEndpointId());
mContentApps.push_back(app);
return epId;
}


/**
* @brief Code for testing the message flow path.
*
*/
class TestCommandHandlerCallback : public app::CommandHandler::Callback {
void OnDone(app::CommandHandler & apCommandObj){}
class TestCommandHandlerCallback : public app::CommandHandler::Callback
{
void OnDone(app::CommandHandler & apCommandObj) {}

void DispatchCommand(app::CommandHandler & apCommandObj, const app::ConcreteCommandPath & aCommandPath,
TLV::TLVReader & apPayload){}
void DispatchCommand(app::CommandHandler & apCommandObj, const app::ConcreteCommandPath & aCommandPath,
TLV::TLVReader & apPayload)
{}

Protocols::InteractionModel::Status CommandExists(const app::ConcreteCommandPath & aCommandPath){return Protocols::InteractionModel::Status::Success;}
Protocols::InteractionModel::Status CommandExists(const app::ConcreteCommandPath & aCommandPath)
{
return Protocols::InteractionModel::Status::Success;
}
};

/**
* @brief Code for testing the message flow path.
*
*/
void ContentAppFactoryImpl::SendTestMessage(EndpointId epId, const char * message){
void ContentAppFactoryImpl::SendTestMessage(EndpointId epId, const char * message)
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl SendTestMessage called with message %s & endpointId %d", message, epId);
for (size_t i = 0; i < mContentApps.size(); ++i)
{
ContentAppImpl app = mContentApps.at(i);
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl checking app with endpointId %d", app.ContentApp::GetEndpointId());
if (app.GetEndpointId() == epId) {
if (app.GetEndpointId() == epId)
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl SendTestMessage endpoint found");
app::ConcreteCommandPath commandPath(epId,app::Clusters::ContentLauncher::Id,app::Clusters::ContentLauncher::Commands::LaunchURL::Id);
app::ConcreteCommandPath commandPath(epId, app::Clusters::ContentLauncher::Id,
app::Clusters::ContentLauncher::Commands::LaunchURL::Id);
chip::AppPlatform::TestCommandHandlerCallback callback;
app::CommandHandler commandHandler(&callback);
CommandResponseHelper<LaunchResponseType> helper(&commandHandler, commandPath);
chip::app::Clusters::ContentLauncher::Structs::BrandingInformation::Type branding;
app.GetContentLauncherDelegate()->HandleLaunchUrl(helper, CharSpan::fromCharString(message), CharSpan::fromCharString("Temp Display"), branding);
app.GetContentLauncherDelegate()->HandleLaunchUrl(helper, CharSpan::fromCharString(message),
CharSpan::fromCharString("Temp Display"), branding);
}
}
}

} // namespace AppPlatform
} // namespace chip


#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED

CHIP_ERROR InitVideoPlayerPlatform()
Expand Down Expand Up @@ -485,11 +494,11 @@ CHIP_ERROR PreServerInit()
}

EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, jobject manager)
const char * szApplicationVersion, jobject manager)
{
ContentAppImpl app = ContentAppImpl(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion, "34567890", manager);
ChipLogProgress(DeviceLayer, "AppImpl: AddContentApp vendorId=%d applicationName=%s ",
vendorId, szApplicationName);
ContentAppImpl app =
ContentAppImpl(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion, "34567890", manager);
ChipLogProgress(DeviceLayer, "AppImpl: AddContentApp vendorId=%d applicationName=%s ", vendorId, szApplicationName);
return gFactory.AddContentApp(app);
}

Expand Down
24 changes: 12 additions & 12 deletions examples/tv-app/android/java/AppImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
#include <app/app-platform/ContentAppPlatform.h>
#include <app/util/attribute-storage.h>
#include <functional>
#include <stdbool.h>
#include <stdint.h>
#include <jni.h>
#include <lib/support/JniReferences.h>
#include <stdbool.h>
#include <stdint.h>

#include "../include/account-login/AccountLoginManager.h"
#include "../include/application-basic/ApplicationBasicManager.h"
#include "../include/application-launcher/ApplicationLauncherManager.h"
#include "../include/content-launcher/AppContentLauncherManager.h"
#include "../include/target-navigator/TargetNavigatorManager.h"
#include "ContentAppCommandDelegate.h"
#include "ChannelManager.h"
#include "CommissionerMain.h"
#include "ContentAppCommandDelegate.h"
#include "KeypadInputManager.h"
#include "MediaPlaybackManager.h"
#include <app/clusters/account-login-server/account-login-delegate.h>
Expand All @@ -54,7 +54,7 @@
CHIP_ERROR InitVideoPlayerPlatform();
CHIP_ERROR PreServerInit();
EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, jobject manager);
const char * szApplicationVersion, jobject manager);
void SendTestMessage(EndpointId epID, const char * message);

#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
Expand Down Expand Up @@ -85,25 +85,26 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
const char * szApplicationVersion, const char * setupPIN, jobject manager) :
mApplicationBasicDelegate(kCatalogVendorId, BuildAppId(vendorId), szVendorName, vendorId, szApplicationName, productId,
szApplicationVersion),
mAccountLoginDelegate(setupPIN),
mContentLauncherDelegate(ContentAppCommandDelegate(manager), { "image/*", "video/*" },
to_underlying(SupportedStreamingProtocol::kDash) |
to_underlying(SupportedStreamingProtocol::kHls)),
mAccountLoginDelegate(setupPIN), mContentLauncherDelegate(ContentAppCommandDelegate(manager), { "image/*", "video/*" },
to_underlying(SupportedStreamingProtocol::kDash) |
to_underlying(SupportedStreamingProtocol::kHls)),
mTargetNavigatorDelegate({ "home", "search", "info", "guide", "menu" }, 0){};
virtual ~ContentAppImpl() {}

AccountLoginDelegate * GetAccountLoginDelegate() override { return &mAccountLoginDelegate; };
ApplicationBasicDelegate * GetApplicationBasicDelegate() override { return &mApplicationBasicDelegate; };
ApplicationLauncherDelegate * GetApplicationLauncherDelegate() override { return &mApplicationLauncherDelegate; };
ChannelDelegate * GetChannelDelegate() override { return &mChannelDelegate; };
ContentLauncherDelegate * GetContentLauncherDelegate() override { mContentLauncherDelegate.SetEndpointId(GetEndpointId()); return &mContentLauncherDelegate; };
ContentLauncherDelegate * GetContentLauncherDelegate() override
{
mContentLauncherDelegate.SetEndpointId(GetEndpointId());
return &mContentLauncherDelegate;
};
KeypadInputDelegate * GetKeypadInputDelegate() override { return &mKeypadInputDelegate; };
MediaPlaybackDelegate * GetMediaPlaybackDelegate() override { return &mMediaPlaybackDelegate; };
TargetNavigatorDelegate * GetTargetNavigatorDelegate() override { return &mTargetNavigatorDelegate; };


protected:

ApplicationBasicManager mApplicationBasicDelegate;
AccountLoginManager mAccountLoginDelegate;
ApplicationLauncherManager mApplicationLauncherDelegate;
Expand All @@ -112,7 +113,6 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
KeypadInputManager mKeypadInputDelegate;
MediaPlaybackManager mMediaPlaybackDelegate;
TargetNavigatorManager mTargetNavigatorDelegate;

};

class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
Expand Down
16 changes: 9 additions & 7 deletions examples/tv-app/android/java/ContentAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@
#include "ContentAppCommandDelegate.h"

#include <jni.h>
#include <lib/support/CHIPJNIError.h>
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>
#include <lib/support/CHIPJNIError.h>

namespace chip {
namespace AppPlatform {

const char * ContentAppCommandDelegate::sendCommand(chip::EndpointId epID, std::string commandPayload) {
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
const char * ContentAppCommandDelegate::sendCommand(chip::EndpointId epID, std::string commandPayload)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
UtfString jCommandPayload(env, commandPayload.c_str());
ChipLogProgress(Zcl, "ContentAppCommandDelegate::sendCommand with payload %s", commandPayload.c_str());
jstring resp = (jstring) env->CallObjectMethod(mContentAppEndpointManager, mSendCommandMethod, static_cast<jint>(epID), jCommandPayload.jniValue());
jstring resp = (jstring) env->CallObjectMethod(mContentAppEndpointManager, mSendCommandMethod, static_cast<jint>(epID),
jCommandPayload.jniValue());
if (env->ExceptionCheck())
{
ChipLogError(Zcl, "Java exception in ContentAppCommandDelegate::sendCommand");
env->ExceptionDescribe();
env->ExceptionClear();
return "Failed";
}
const char *ret = env->GetStringUTFChars(resp, 0);
const char * ret = env->GetStringUTFChars(resp, 0);
return ret;
}

}
}
} // namespace AppPlatform
} // namespace chip
42 changes: 22 additions & 20 deletions examples/tv-app/android/java/ContentAppCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,44 @@

#pragma once


#include <jni.h>
#include <lib/support/JniReferences.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/JniReferences.h>

namespace chip {
namespace AppPlatform {

class ContentAppCommandDelegate
{
public:
ContentAppCommandDelegate(jobject manager){
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentAppEndpointManager"));

mContentAppEndpointManager = env->NewGlobalRef(manager);
VerifyOrReturn(mContentAppEndpointManager != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef ContentAppEndpointManager"));
ContentAppCommandDelegate(jobject manager)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentAppEndpointManager"));

jclass ContentAppEndpointManagerClass = env->GetObjectClass(manager);
VerifyOrReturn(ContentAppEndpointManagerClass != nullptr, ChipLogError(Zcl, "Failed to get ContentAppEndpointManager Java class"));
mContentAppEndpointManager = env->NewGlobalRef(manager);
VerifyOrReturn(mContentAppEndpointManager != nullptr,
ChipLogError(Zcl, "Failed to NewGlobalRef ContentAppEndpointManager"));

mSendCommandMethod = env->GetMethodID(ContentAppEndpointManagerClass, "sendCommand", "(ILjava/lang/String;)Ljava/lang/String;");
if (mSendCommandMethod == nullptr)
{
ChipLogError(Zcl, "Failed to access ContentAppEndpointManager 'sendCommand' method");
env->ExceptionClear();
}
jclass ContentAppEndpointManagerClass = env->GetObjectClass(manager);
VerifyOrReturn(ContentAppEndpointManagerClass != nullptr,
ChipLogError(Zcl, "Failed to get ContentAppEndpointManager Java class"));

mSendCommandMethod =
env->GetMethodID(ContentAppEndpointManagerClass, "sendCommand", "(ILjava/lang/String;)Ljava/lang/String;");
if (mSendCommandMethod == nullptr)
{
ChipLogError(Zcl, "Failed to access ContentAppEndpointManager 'sendCommand' method");
env->ExceptionClear();
}
};

const char * sendCommand(chip::EndpointId epID, std::string commandPayload);

private:
jobject mContentAppEndpointManager = nullptr;
jmethodID mSendCommandMethod = nullptr;
jobject mContentAppEndpointManager = nullptr;
jmethodID mSendCommandMethod = nullptr;
};

}
}
} // namespace AppPlatform
} // namespace chip
16 changes: 9 additions & 7 deletions examples/tv-app/android/java/TVApp-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,16 @@ JNI_METHOD(jboolean, setCurrentLevel)(JNIEnv *, jobject, jint endpoint, jboolean
return LevelManager::SetLevel(endpoint, value);
}

JNI_METHOD(jint, addContentApp)(JNIEnv *, jobject, jstring vendorName, jint vendorId, jstring appName, jint productId, jstring appVersion, jobject manager)
JNI_METHOD(jint, addContentApp)
(JNIEnv *, jobject, jstring vendorName, jint vendorId, jstring appName, jint productId, jstring appVersion, jobject manager)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();

const char *nVendorName = env->GetStringUTFChars(vendorName, 0);
const char *nAppName = env->GetStringUTFChars(appName, 0);
const char *nAppVersion = env->GetStringUTFChars(appVersion, 0);
EndpointId epId = AddContentApp(nVendorName, static_cast<uint16_t>(vendorId), nAppName, static_cast<uint16_t>(productId), nAppVersion, manager);
const char * nVendorName = env->GetStringUTFChars(vendorName, 0);
const char * nAppName = env->GetStringUTFChars(appName, 0);
const char * nAppVersion = env->GetStringUTFChars(appVersion, 0);
EndpointId epId = AddContentApp(nVendorName, static_cast<uint16_t>(vendorId), nAppName, static_cast<uint16_t>(productId),
nAppVersion, manager);
env->ReleaseStringUTFChars(vendorName, nVendorName);
env->ReleaseStringUTFChars(appName, nAppName);
env->ReleaseStringUTFChars(appVersion, nAppVersion);
Expand All @@ -192,8 +194,8 @@ JNI_METHOD(jint, addContentApp)(JNIEnv *, jobject, jstring vendorName, jint vend

JNI_METHOD(void, sendTestMessage)(JNIEnv *, jobject, jint endpoint, jstring message)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
const char *nmessage = env->GetStringUTFChars(message, 0);
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
const char * nmessage = env->GetStringUTFChars(message, 0);
ChipLogProgress(Zcl, "TvApp-JNI SendTestMessage called with message %s", nmessage);
SendTestMessage(static_cast<EndpointId>(endpoint), nmessage);
}

0 comments on commit bde9a1b

Please sign in to comment.