ContentAppAttributeDelegate.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * @brief Contains Implementation of the ContentAppAttributeDelegate
  20. */
  21. #include "ContentAppAttributeDelegate.h"
  22. #include <app-common/zap-generated/cluster-objects.h>
  23. #include <app/AttributeAccessInterface.h>
  24. #include <app/util/config.h>
  25. #include <jni.h>
  26. #include <lib/support/CHIPJNIError.h>
  27. #include <lib/support/JniReferences.h>
  28. #include <lib/support/JniTypeWrappers.h>
  29. #include <zap-generated/endpoint_config.h>
  30. namespace chip {
  31. namespace AppPlatform {
  32. using LaunchResponseType = chip::app::Clusters::ContentLauncher::Commands::LauncherResponse::Type;
  33. std::string ContentAppAttributeDelegate::Read(const chip::app::ConcreteReadAttributePath & aPath)
  34. {
  35. if (aPath.mEndpointId < FIXED_ENDPOINT_COUNT)
  36. {
  37. // returning blank string causes the caller to default to output required by the tests
  38. return "";
  39. }
  40. JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
  41. ChipLogProgress(Zcl, "ContentAppAttributeDelegate::Read being called for endpoint %d cluster %d attribute %d",
  42. aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
  43. jstring resp =
  44. (jstring) env->CallObjectMethod(mContentAppEndpointManager, mReadAttributeMethod, static_cast<jint>(aPath.mEndpointId),
  45. static_cast<jlong>(aPath.mClusterId), static_cast<jlong>(aPath.mAttributeId));
  46. if (env->ExceptionCheck())
  47. {
  48. ChipLogError(Zcl, "Java exception in ContentAppAttributeDelegate::Read");
  49. env->ExceptionDescribe();
  50. env->ExceptionClear();
  51. // returning blank string causes the caller to default to output required by the tests
  52. return "";
  53. }
  54. const char * respStr = env->GetStringUTFChars(resp, 0);
  55. std::string retStr(respStr);
  56. env->ReleaseStringUTFChars(resp, respStr);
  57. env->DeleteLocalRef(resp);
  58. ChipLogProgress(Zcl, "ContentAppAttributeDelegate::Read got response %s", respStr);
  59. return retStr;
  60. }
  61. } // namespace AppPlatform
  62. } // namespace chip