Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dave Griffiths
mongoose-2000
Commits
60fb8084
Commit
60fb8084
authored
Sep 29, 2013
by
Dave Griffiths
Browse files
syncing fixes -> server
parent
cd09f3e9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
38 deletions
+54
-38
android/assets/eavdb.scm
android/assets/eavdb.scm
+1
-1
android/assets/lib.scm
android/assets/lib.scm
+3
-1
android/assets/starwisp.scm
android/assets/starwisp.scm
+47
-29
android/src/foam/mongoose/NetworkManager.java
android/src/foam/mongoose/NetworkManager.java
+3
-7
No files found.
android/assets/eavdb.scm
View file @
60fb8084
...
...
@@ -119,7 +119,7 @@
;; insert an entire entity
(
define
(
insert-entity
db
table
entity-type
user
ktvlist
)
(
insert-entity-wholesale
db
table
entity-type
(
get-unique
user
)
"1"
"0"
ktvlist
))
(
insert-entity-wholesale
db
table
entity-type
(
get-unique
user
)
1
0
ktvlist
))
;; all the parameters - for syncing purposes
(
define
(
insert-entity-wholesale
db
table
entity-type
unique-id
dirty
version
ktvlist
)
...
...
android/assets/lib.scm
View file @
60fb8084
...
...
@@ -534,7 +534,9 @@
(
let
((
dialog
(
dialog-find
dialogs
name
)))
(
if
(
not
dialog
)
(
begin
(
display
"no dialog called "
)(
display
name
)(
newline
))
(
send
(
scheme->json
(
apply
(
dialog-fn
dialog
)
args
))))))
(
let
((
events
(
apply
(
dialog-fn
dialog
)
args
)))
(
update-dialogs!
events
)
(
send
(
scheme->json
events
))))))
;; called by java
(
define
(
activity-callback
type
activity-name
args
)
...
...
android/assets/starwisp.scm
View file @
60fb8084
...
...
@@ -19,6 +19,8 @@
(
define
db
"/sdcard/test.db"
)
(
db-open
db
)
(
display
"hello one two three"
)(
newline
)
(
setup
db
"local"
)
(
setup
db
"sync"
)
(
setup
db
"stream"
)
...
...
@@ -28,9 +30,14 @@
(
list
(
ktv
"user-id"
"varchar"
"No name yet..."
)))
(
display
"sonwassa"
)(
newline
)
(
msg
"001"
)
(
display
(
db-all
db
"local"
"app-settings"
))(
newline
)
(
msg
"002"
)
(
display
(
db-status
db
))(
newline
)
(
msg
"003"
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
...
...
@@ -120,16 +127,45 @@
(
display
"somefink went wrong"
)(
newline
)))))
(
dirty-entities
db
table
)))
(
define
(
suck-entity-from-server
db
table
unique-id
)
(
msg
"suck-entity-from-server"
unique-id
)
;; ask for the current version
(
http-request
(
string-append
unique-id
"-update-new"
)
(
string-append
url
"fn=entity&table="
table
"&unique-id="
unique-id
)
(
lambda
(
data
)
(
msg
"data from server request"
data
)
;; check "sync-insert" in sync.ss raspberry pi-side for the contents of 'entity'
(
let
((
entity
(
list-ref
data
1
))
(
ktvlist
(
list-ref
data
2
)))
(
msg
"1111"
exists
)
(
if
(
not
exists
)
(
insert-entity-wholesale
db
table
(
list-ref
entity
0
)
;; entity-type
(
list-ref
entity
1
)
;; unique-id
"0"
(
list-ref
entity
2
)
;; version
ktvlist
)
(
update-to-version
db
table
(
get-entity-id
db
table
unique-id
)
(
list-ref
entity
4
)
ktvlist
)))
(
msg
"2222"
exists
)
'
())))
;; repeatedly read version and request updates
(
define
(
get-new-entities
db
table
)
(
define
(
suck-new
db
table
)
(
msg
"suck-new"
)
(
list
(
http-request
"new-entities-req"
(
dbg
(
string-append
url
"fn=entity-versions&table="
table
))
(
lambda
(
data
)
(
msg
data
)
(
for-each
(
lambda
(
i
)
(
dbg
(
foldl
(
lambda
(
i
r
)
(
msg
"inner loop"
i
)
(
let*
((
unique-id
(
car
i
))
(
version
(
cadr
i
))
(
exists
(
entity-exists?
db
table
unique-id
))
...
...
@@ -139,31 +175,13 @@
(
dbg
(
get-entity-version
db
table
unique-id
))))
#f
)))
;; if we don't have this entity or the version on the server is newer
(
when
(
or
(
not
exists
)
old
)
(
msg
"sending for new version"
)
;; ask for the current version
(
http-request
(
string-append
unique-id
"-update-new"
)
(
string-append
url
"fn=entity&table="
table
"&unique-id="
unique-id
)
(
lambda
(
data
)
(
msg
data
)
;; check "sync-insert" in sync.ss raspberry pi-side for the contents of 'entity'
(
let
((
entity
(
list-ref
data
1
))
(
ktvlist
(
list-ref
data
2
)))
(
if
(
not
exists
)
(
insert-entity-wholesale
db
table
(
list-ref
entity
0
)
;; entity-type
(
list-ref
entity
1
)
;; unique-id
"0"
(
list-ref
entity
2
)
;; version
ktvlist
)
(
update-to-version
db
table
(
get-entity-id
db
table
unique-id
)
(
list-ref
entity
4
)
ktvlist
))))))))
data
)))))
;;(display (get-new-entities db "local"))(newline)
(
if
(
or
(
not
exists
)
old
)
(
cons
(
suck-entity-from-server
db
table
unique-id
)
r
)
r
)))
'
()
data
))))))
(
msg
"004"
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
...
...
@@ -683,7 +701,7 @@
(
spit-dirty
db
"sync"
)))
(
mbutton
"sync-pull"
"Pull"
(
lambda
()
(
dbg
(
get-new-entities
db
"sync"
)))))
(
dbg
(
suck-new
db
"sync"
)))))
(
text-view
(
make-id
"sync-console"
)
"..."
15
(
layout
300
'wrap-content
1
'left
))
(
mbutton
"main-send"
"Done"
(
lambda
()
(
list
(
finish-activity
2
)))))
...
...
android/src/foam/mongoose/NetworkManager.java
View file @
60fb8084
...
...
@@ -120,22 +120,18 @@ public class NetworkManager {
private
void
Request
(
String
u
,
String
CallbackName
)
{
try
{
Log
.
i
(
"starwisp"
,
"Pinging URL"
);
Log
.
i
(
"starwisp"
,
u
);
Log
.
i
(
"starwisp"
,
"pinging: "
+
u
);
URL
url
=
new
URL
(
u
);
HttpURLConnection
con
=
(
HttpURLConnection
)
url
.
openConnection
();
con
.
setUseCaches
(
false
);
con
.
setReadTimeout
(
10000
/* milliseconds */
);
con
.
setConnectTimeout
(
15000
/* milliseconds */
);
con
.
setRequestMethod
(
"GET"
);
con
.
setDoInput
(
true
);
// Starts the query
con
.
connect
();
Log
.
i
(
"starwisp"
,
"Connection open"
);
//readStream(con.getInputStream());
Log
.
i
(
"starwisp"
,
"read stream, ending"
);
m_RequestHandler
.
sendMessage
(
Message
.
obtain
(
m_RequestHandler
,
0
,
new
ReqMsg
(
con
.
getInputStream
(),
CallbackName
)));
...
...
@@ -163,8 +159,8 @@ public class NetworkManager {
String
all
=
""
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
all
+=
line
+
"\n"
;
Log
.
i
(
"starwisp"
,
line
);
}
Log
.
i
(
"starwisp"
,
"got data: "
+
all
);
m_Builder
.
DialogCallback
(
m_Context
,
m
.
m_CallbackName
,
all
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment