Skip to content

Commit

Permalink
internal/mobileinit: new package for shared logic
Browse files Browse the repository at this point in the history
Package app contains some logic that we want to share with
gobind-based libraries. So move it to a new internal package
that both can import.

Long term the log changes should be in the standard library,
but the Go tree is currently frozen.

Fixes golang/go#11630.

Change-Id: I9ff622fc499bf255bce18df23cb68b03f667947f
Reviewed-on: https://go-review.googlesource.com/11981
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
  • Loading branch information
crawshaw committed Jul 8, 2015
1 parent 08407a4 commit 960fedd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/app.go
Expand Up @@ -6,7 +6,10 @@

package app

import "golang.org/x/mobile/event"
import (
"golang.org/x/mobile/event"
_ "golang.org/x/mobile/internal/mobileinit"
)

// Main is called by the main.main function to run the mobile application.
//
Expand Down
6 changes: 5 additions & 1 deletion bind/seq/seq.go
Expand Up @@ -16,7 +16,11 @@ package seq // import "golang.org/x/mobile/bind/seq"
// bindings which requires deconstructing seq into something
// gnarly. So don't get too attached to the design.

import "fmt"
import (
"fmt"

_ "golang.org/x/mobile/internal/mobileinit"
)

// Transact calls a method on a foreign object instance.
// It blocks until the call is complete.
Expand Down
9 changes: 9 additions & 0 deletions internal/mobileinit/mobileinit.go
@@ -0,0 +1,9 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package mobileinit contains common initialization logic for mobile platforms
// that is relevant to both all-Go apps and gobind-based apps.
//
// Long-term, any code in this package should consider moving into Go stdlib.
package mobileinit
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package app
package mobileinit

/*
To view the log output run:
Expand All @@ -16,6 +16,8 @@ adb logcat GoLog:I *:S
// Unfortunately, logcat is line oriented, so we must buffer.

/*
#cgo LDFLAGS: -landroid -llog
#include <android/log.h>
#include <string.h>
*/
Expand All @@ -37,7 +39,7 @@ type infoWriter struct{}

func (infoWriter) Write(p []byte) (n int, err error) {
cstr := C.CString(string(p))
C.__android_log_write(C.ANDROID_LOG_INFO, ctagLog, cstr)
C.__android_log_write(C.ANDROID_LOG_INFO, ctag, cstr)
C.free(unsafe.Pointer(cstr))
return len(p), nil
}
Expand Down

0 comments on commit 960fedd

Please sign in to comment.