AppPlatform-JNI.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2021 Project CHIP Authors
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include "AppImpl.h"
  19. #include <jni.h>
  20. #include <lib/core/CHIPError.h>
  21. #include <lib/support/CHIPJNIError.h>
  22. #include <lib/support/JniReferences.h>
  23. #include <lib/support/JniTypeWrappers.h>
  24. using namespace chip;
  25. using namespace chip::app;
  26. using namespace chip::AppPlatform;
  27. using namespace chip::Credentials;
  28. /*
  29. * This file provides the native implementation of methods of the
  30. * com.matter.tv.server.tvapp.AppPlatform class.
  31. */
  32. #define JNI_METHOD(RETURN, METHOD_NAME) \
  33. extern "C" JNIEXPORT RETURN JNICALL Java_com_matter_tv_server_tvapp_AppPlatform_##METHOD_NAME
  34. JNI_METHOD(void, nativeInit)(JNIEnv *, jobject app, jobject contentAppEndpointManager)
  35. {
  36. chip::DeviceLayer::StackLock lock;
  37. InitVideoPlayerPlatform(contentAppEndpointManager);
  38. }
  39. JNI_METHOD(jint, addContentApp)
  40. (JNIEnv *, jobject, jstring vendorName, jint vendorId, jstring appName, jint productId, jstring appVersion, jobject manager)
  41. {
  42. chip::DeviceLayer::StackLock lock;
  43. JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
  44. JniUtfString vName(env, vendorName);
  45. JniUtfString aName(env, appName);
  46. JniUtfString aVersion(env, appVersion);
  47. EndpointId epId = AddContentApp(vName.c_str(), static_cast<uint16_t>(vendorId), aName.c_str(), static_cast<uint16_t>(productId),
  48. aVersion.c_str(), manager);
  49. return static_cast<uint16_t>(epId);
  50. }
  51. JNI_METHOD(jint, addContentAppAtEndpoint)
  52. (JNIEnv *, jobject, jstring vendorName, jint vendorId, jstring appName, jint productId, jstring appVersion, jint endpointId,
  53. jobject manager)
  54. {
  55. chip::DeviceLayer::StackLock lock;
  56. JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
  57. JniUtfString vName(env, vendorName);
  58. JniUtfString aName(env, appName);
  59. JniUtfString aVersion(env, appVersion);
  60. EndpointId epId = AddContentApp(vName.c_str(), static_cast<uint16_t>(vendorId), aName.c_str(), static_cast<uint16_t>(productId),
  61. aVersion.c_str(), static_cast<EndpointId>(endpointId), manager);
  62. return static_cast<uint16_t>(epId);
  63. }
  64. JNI_METHOD(jint, removeContentApp)
  65. (JNIEnv *, jobject, jint endpointId)
  66. {
  67. chip::DeviceLayer::StackLock lock;
  68. EndpointId epId = RemoveContentApp(static_cast<EndpointId>(endpointId));
  69. return static_cast<uint16_t>(epId);
  70. }
  71. JNI_METHOD(void, reportAttributeChange)
  72. (JNIEnv *, jobject, jint endpointId, jint clusterId, jint attributeId)
  73. {
  74. chip::DeviceLayer::StackLock lock;
  75. ReportAttributeChange(static_cast<EndpointId>(endpointId), static_cast<chip::ClusterId>(clusterId),
  76. static_cast<chip::AttributeId>(attributeId));
  77. }
  78. JNI_METHOD(void, addSelfVendorAsAdmin)
  79. (JNIEnv *, jobject, jint endpointId, jint clusterId, jint attributeId)
  80. {
  81. AddSelfVendorAsAdmin();
  82. }