Skip to content

Commit

Permalink
support filename when compiling MMKV for Android in Win32 env
Browse files Browse the repository at this point in the history
  • Loading branch information
lingol committed Aug 6, 2019
1 parent 6d9a7bc commit 8bffb6c
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@

package com.tencent.mmkv;

import static org.junit.Assert.*;

import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import androidx.test.InstrumentationRegistry;

import java.util.HashSet;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.HashSet;

import static org.junit.Assert.*;

public class MMKVTest {

static MMKV mmkv;
Expand Down
12 changes: 12 additions & 0 deletions Android/MMKV/mmkv/src/main/cpp/MMKVLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ MMKVLogLevel g_currentLogLevel = MMKVLogDebug;
MMKVLogLevel g_currentLogLevel = MMKVLogInfo;
#endif

const char *_getFileName(const char *path) {
const char *ptr = strrchr(path, '/');
if (!ptr) {
ptr = strrchr(path, '\\');
}
if (ptr) {
return ptr + 1;
} else {
return path;
}
}

static android_LogPriority MMKVLogLevelDesc(MMKVLogLevel level) {
switch (level) {
case MMKVLogDebug:
Expand Down
4 changes: 3 additions & 1 deletion Android/MMKV/mmkv/src/main/cpp/MMKVLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ enum MMKVLogLevel : uint32_t {
extern bool g_isLogRedirecting;
extern MMKVLogLevel g_currentLogLevel;

#define __filename__ (strrchr(__FILE__, '/') + 1)
extern const char *_getFileName(const char *path);

#define __filename__ _getFileName(__FILE__)

#define MMKVError(format, ...) \
_MMKVLogWithLevel(MMKVLogError, __filename__, __func__, __LINE__, format, ##__VA_ARGS__)
Expand Down
3 changes: 1 addition & 2 deletions Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.Nullable;
import android.util.Log;

import androidx.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.EnumMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.Log;

public class MMKVContentProvider extends ContentProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;

import java.io.IOException;

public final class ParcelableMMKV implements Parcelable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@

package com.tencent.mmkvdemo;

import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;

import java.util.Random;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.tencent.mmkv.MMKV;
import java.util.Random;

public final class Baseline {
private String[] m_arrStrings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import androidx.annotation.Nullable;
import android.util.Log;

import java.util.Random;

import androidx.annotation.Nullable;
import com.tencent.mmkv.MMKV;
import com.tencent.mmkv.ParcelableMMKV;
import java.util.Random;

public abstract class BenchMarkBaseService extends Service {
public static final String CMD_ID = "cmd_id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@

package com.tencent.mmkvdemo;

import static com.tencent.mmkvdemo.BenchMarkBaseService.AshmemMMKV_ID;
import static com.tencent.mmkvdemo.BenchMarkBaseService.AshmemMMKV_Size;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Arrays;
import java.util.HashSet;

import androidx.appcompat.app.AppCompatActivity;
import com.getkeepsafe.relinker.ReLinker;
import com.tencent.mmkv.MMKV;
import com.tencent.mmkv.MMKVHandler;
import com.tencent.mmkv.MMKVRecoverStrategic;
import com.tencent.mmkv.MMKVLogLevel;
import com.getkeepsafe.relinker.ReLinker;
import com.tencent.mmkv.MMKVRecoverStrategic;
import com.tencent.mmkv.NativeBuffer;

import java.util.Arrays;
import java.util.HashSet;
import org.jetbrains.annotations.Nullable;

import static com.tencent.mmkvdemo.BenchMarkBaseService.AshmemMMKV_ID;
import static com.tencent.mmkvdemo.BenchMarkBaseService.AshmemMMKV_Size;

public class MainActivity extends AppCompatActivity implements MMKVHandler {
static private final String KEY_1 = "Ashmem_Key_1";
static private final String KEY_2 = "Ashmem_Key_2";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package com.tencent.mmkvdemo;

import java.lang.ref.SoftReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import android.content.BroadcastReceiver;
import android.content.ContentProvider;
import android.content.ContentResolver;
Expand All @@ -28,6 +17,16 @@
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Bundle;
import java.lang.ref.SoftReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* 使用ContentProvider实现多进程SharedPreferences读写;<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import android.content.Intent;
import android.util.Log;

import com.tencent.mmkv.MMKV;

public class MyService extends BenchMarkBaseService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import com.tencent.mmkv.ParcelableMMKV;

public class MyService_1 extends BenchMarkBaseService implements ServiceConnection {
Expand Down

0 comments on commit 8bffb6c

Please sign in to comment.