Skip to content

Commit

Permalink
fix restyled errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xylophone21 committed Oct 26, 2021
1 parent 0968cd2 commit 1f4f4c4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 62 deletions.
42 changes: 26 additions & 16 deletions src/platform/android/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobject sResolverObject = nullptr;
jobject sMdnsCallbackObject = nullptr;
jmethodID sResolveMethod = nullptr;
jmethodID sPublishMethod = nullptr;
jmethodID sRemoveMethod = nullptr;
jmethodID sRemoveMethod = nullptr;
} // namespace

// Implemention of functions declared in lib/dnssd/platform/Dnssd.h
Expand Down Expand Up @@ -75,9 +75,12 @@ CHIP_ERROR ChipDnssdRemoveServices()
return CHIP_JNI_ERROR_EXCEPTION_THROWN;
}

if(jret) {
if (jret)
{
return CHIP_NO_ERROR;
} else {
}
else
{
return CHIP_JNI_ERROR_JAVA_ERROR;
}
}
Expand All @@ -97,27 +100,29 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service)
UtfString jniServiceType(env, serviceType.c_str());

jclass stringClass = env->FindClass("java/lang/String");
jobjectArray keys = env->NewObjectArray(service->mTextEntrySize, stringClass, nullptr);
jobjectArray keys = env->NewObjectArray(service->mTextEntrySize, stringClass, nullptr);

jclass arrayElemType = env->FindClass("[B");
jobjectArray datas = env->NewObjectArray(service->mTextEntrySize, arrayElemType, nullptr);
jobjectArray datas = env->NewObjectArray(service->mTextEntrySize, arrayElemType, nullptr);

for(size_t i=0;i < service->mTextEntrySize;i++) {
for (size_t i = 0; i < service->mTextEntrySize; i++)
{
UtfString jniKey(env, service->mTextEntries[i].mKey);
env->SetObjectArrayElement(keys,i,jniKey.jniValue());
env->SetObjectArrayElement(keys, i, jniKey.jniValue());

ByteArray jniData(env, (const jbyte *)service->mTextEntries[i].mData, service->mTextEntries[i].mDataSize);
env->SetObjectArrayElement(datas,i,jniData.jniValue());
ByteArray jniData(env, (const jbyte *) service->mTextEntries[i].mData, service->mTextEntries[i].mDataSize);
env->SetObjectArrayElement(datas, i, jniData.jniValue());
}

jobjectArray subTypes = env->NewObjectArray(service->mSubTypeSize, stringClass, nullptr);
for(size_t i=0; i< service->mSubTypeSize; i++) {
for (size_t i = 0; i < service->mSubTypeSize; i++)
{
UtfString jniSubType(env, service->mSubTypes[i]);
env->SetObjectArrayElement(subTypes,i,jniSubType.jniValue());
env->SetObjectArrayElement(subTypes, i, jniSubType.jniValue());
}

jboolean jret = env->CallBooleanMethod(sResolverObject, sPublishMethod, jniName.jniValue(), jniHostName.jniValue()
, jniServiceType.jniValue(), service->mPort, keys, datas, subTypes);
jboolean jret = env->CallBooleanMethod(sResolverObject, sPublishMethod, jniName.jniValue(), jniHostName.jniValue(),
jniServiceType.jniValue(), service->mPort, keys, datas, subTypes);

env->DeleteLocalRef(keys);
env->DeleteLocalRef(datas);
Expand All @@ -131,9 +136,12 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service)
return CHIP_JNI_ERROR_EXCEPTION_THROWN;
}

if(jret) {
if (jret)
{
return CHIP_NO_ERROR;
} else {
}
else
{
return CHIP_JNI_ERROR_JAVA_ERROR;
}
}
Expand Down Expand Up @@ -197,7 +205,9 @@ void InitializeWithObjects(jobject resolverObject, jobject mdnsCallbackObject)
env->ExceptionClear();
}

sPublishMethod = env->GetMethodID(resolverClass, "publish", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;[[B[Ljava/lang/String;)Z");
sPublishMethod =
env->GetMethodID(resolverClass, "publish",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;[[B[Ljava/lang/String;)Z");
if (sPublishMethod == nullptr)
{
ChipLogError(Discovery, "Failed to access Resolver 'publish' method");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import java.util.*;

public class NsdManagerServiceResolver implements ServiceResolver {
Expand Down Expand Up @@ -116,49 +115,60 @@ public void onServiceResolved(NsdServiceInfo serviceInfo) {
mainThreadHandler.postDelayed(timeoutRunnable, RESOLVE_SERVICE_TIMEOUT);
}

@Override
public boolean publish(String serviceName, String hostName, String type, int port, String[] textEntriesKeys, byte[][] textEntriesDatas, String[] subTypes) {
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setServiceName(serviceName);
serviceInfo.setServiceType(type);
serviceInfo.setPort(port);
Log.i(TAG,"publish serviceName="+serviceName+" type="+type+" port="+port);

NsdManager.RegistrationListener registrationListener = new NsdManager.RegistrationListener() {
@Override
public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.w(TAG, "service " + serviceInfo.getServiceName() + " onRegistrationFailed:" + errorCode);
}
@Override
public boolean publish(
String serviceName,
String hostName,
String type,
int port,
String[] textEntriesKeys,
byte[][] textEntriesDatas,
String[] subTypes) {
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setServiceName(serviceName);
serviceInfo.setServiceType(type);
serviceInfo.setPort(port);
Log.i(TAG, "publish serviceName=" + serviceName + " type=" + type + " port=" + port);

@Override
public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.w(TAG, "service " + serviceInfo.getServiceName() + " onUnregistrationFailed:" + errorCode);
}
NsdManager.RegistrationListener registrationListener =
new NsdManager.RegistrationListener() {
@Override
public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.w(
TAG,
"service " + serviceInfo.getServiceName() + " onRegistrationFailed:" + errorCode);
}

@Override
public void onServiceRegistered(NsdServiceInfo serviceInfo) {
Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:");
}
@Override
public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.w(
TAG,
"service " + serviceInfo.getServiceName() + " onUnregistrationFailed:" + errorCode);
}

@Override
public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:");
}
};
mRegistrationListeners.add(registrationListener);
@Override
public void onServiceRegistered(NsdServiceInfo serviceInfo) {
Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:");
}

nsdManager.registerService(
serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener);
@Override
public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:");
}
};
mRegistrationListeners.add(registrationListener);

return true;
}
nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener);

@Override
public boolean remove() {
for (NsdManager.RegistrationListener l:mRegistrationListeners) {
nsdManager.unregisterService(l);
}
return true;
}

return true;
@Override
public boolean remove() {
for (NsdManager.RegistrationListener l : mRegistrationListeners) {
nsdManager.unregisterService(l);
}

return true;
}
}
13 changes: 5 additions & 8 deletions src/platform/android/java/chip/platform/ServiceResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void resolve(
/**
* Publishes a service via DNS-SD.
*
* Calling the function again with the same service name, type, protocol,
* interface and port but different text will update the text published.
* This function will NOT take the ownership of service->mTextEntries memory.
* <p>Calling the function again with the same service name, type, protocol, interface and port
* but different text will update the text published. This function will NOT take the ownership of
* service->mTextEntries memory.
*/
boolean publish(
String serviceName,
Expand All @@ -45,11 +45,8 @@ boolean publish(
int port,
String[] textEntriesKeys,
byte[][] textEntriesDatas,
String[] subTypes
);
String[] subTypes);

/**
* Removes or marks all services being advertised for removal.
*/
/** Removes or marks all services being advertised for removal. */
boolean remove();
}

0 comments on commit 1f4f4c4

Please sign in to comment.