Skip to content

Commit 6fce82e

Browse files
committed
title is swizzled to record the title of images, which is now stored in the sessionimage table
1 parent 03158d3 commit 6fce82e

File tree

11 files changed

+119
-14
lines changed

11 files changed

+119
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/prepareRInside.sh\"
118118
install(TARGETS rserver rsession RUNTIME DESTINATION .)
119119
install(DIRECTORY ${CMAKE_BINARY_DIR}/RInside DESTINATION . ${INSTALL_PATH})
120120
install(DIRECTORY ${CMAKE_SOURCE_DIR}/R/rc2 DESTINATION . ${INSTALL_PATH})
121+
install(DIRECTORY ${CMAKE_SOURCE_DIR}/rsrc DESTINATION . ${INSTALL_PATH})

R/rc2/DESCRIPTION

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
Package: rc2
22
Type: Package
33
Title: Assists communication with rc2compute engine
4-
Version: 2.0
5-
Date: 2016-05-23
4+
Version: 3.0
5+
Date: 2017-03-23
66
Author: Mark Lilback
77
Maintainer: Mark Lilback <[email protected]>
88
Description:Assists rc2compute engine
99
License: BSD
10-
Depends: stringr
1110
LazyLoad: yes

R/rc2/NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export("help", "rc2.defineFunction", "rc2.pngdev", "rc2.pngoff")
1+
export("help", "rc2.defineFunction", "rc2.pngdev", "rc2.pngoff", "rc2.errlog")

R/rc2/R/rc2.R

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
helpIndexSearch <- getFromNamespace("index.search", getNamespace("utils"))
22

3+
utils::suppressForeignCheck("rc2cache")
4+
rc2cache <- new.env(parent = emptyenv())
5+
assign("imgNum", 100, envir=rc2cache)
6+
37
#called from EnvList.cpp c++ code
48
rc2.defineFunction <- function(func) {
5-
zz <- textConnection("def", open = "w", local = TRUE)
9+
zz <- textConnection(NULL, open = "w", local = TRUE)
610
capture.output(print(func), file=zz)
11+
result <- paste(textConnectionValue(zz), sep="\n")
712
close(zz)
8-
paste(def, sep="\n")
13+
result
914
}
1015

1116
#override to just return help paths
@@ -29,11 +34,20 @@ help <- function(topic) {
2934

3035
rc2.pngdev <- function()
3136
{
32-
png("rc2img%03d.png")
37+
imgNum <- as.integer(get("imgNum", envir=rc2:::rc2cache))
38+
assign("imgNum", imgNum + 1, envir=rc2:::rc2cache)
39+
fname <- sprintf("rc2img%03d.png", imgNum, envir=rc2:::rc2cache)
40+
png(fname)
41+
rc2.errlog("rc2.imgstart=%s\n", fname)
3342
}
3443

3544
rc2.pngoff <- function()
3645
{
46+
rc2.errlog("dev off")
3747
if (dev.cur()[1] != 1)
3848
dev.off();
3949
}
50+
51+
52+
rc2.errlog <- function(...) cat(sprintf(...), sep='', file=stderr())
53+

computeClient/.perl-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.23.4

computeClient/query.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"msg": "execScript", "argument": "rnorm(11)"}

rsrc/swizzle.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
library(inline)
2+
local( {
3+
myenv <- new.env(parent = emptyenv())
4+
oldtitle <- graphics::title
5+
#assign("oldtitle", graphics::title, envir = myenv)
6+
7+
#oldtitle <- title
8+
mytitle <- function(...) {
9+
args <- list(...)
10+
if (!is.null(args$main)) {
11+
rc2.errlog("rc2.imgtitle=%s\n", args$main)
12+
}
13+
oldtitle(...)
14+
}
15+
16+
inc <- '
17+
/* This is taken from envir.c in the R 2.15.1 source
18+
https://github.com/SurajGupta/r-source/blob/master/src/main/envir.c
19+
*/
20+
#define FRAME_LOCK_MASK (1<<14)
21+
#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) & FRAME_LOCK_MASK)
22+
#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) & (~ FRAME_LOCK_MASK))
23+
'
24+
25+
src <- '
26+
if (TYPEOF(env) == NILSXP)
27+
error("use of NULL environment is defunct");
28+
if (TYPEOF(env) != ENVSXP)
29+
error("not an environment");
30+
UNLOCK_FRAME(env);
31+
// Return TRUE if unlocked; FALSE otherwise
32+
SEXP result = PROTECT( Rf_allocVector(LGLSXP, 1) );
33+
LOGICAL(result)[0] = FRAME_IS_LOCKED(env) == 0;
34+
UNPROTECT(1);
35+
return result;
36+
'
37+
38+
unlockEnvironment <- cfunction(signature(env = "environment"),
39+
includes = inc,
40+
body = src)
41+
42+
43+
ns_g <- asNamespace('graphics')
44+
unlockEnvironment(ns_g)
45+
unlockBinding("title", ns_g)
46+
ns_g$title <- mytitle
47+
lockBinding("title", ns_g)
48+
detach(package:graphics)
49+
library(graphics)
50+
51+
})

src/FileManager.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class RC2::FileManager::Impl : public ZeroInitializedClass {
6666
int inotifyFd_;
6767
FSDirectory rootDir_;
6868
boost::regex imgRegex_;
69+
map<string, string> imgNameToTitle_;
6970
bool ignoreFSNotifications_;
7071
bool ignoreDBNotifications_;
7172

@@ -150,6 +151,10 @@ RC2::FileManager::Impl::connect(std::shared_ptr<PGDBConnection> connection, long
150151
long
151152
RC2::FileManager::Impl::insertImage(string fname, string imgNumStr)
152153
{
154+
string title = "";
155+
if (imgNameToTitle_.count(fname) > 0) {
156+
dbConnection_->escapeLiteral(imgNameToTitle_[fname], title);
157+
}
153158
string filePath = workingDir + "/" + fname;
154159
size_t size;
155160
unique_ptr<char[]> buffer = ReadFileBlob(filePath, size);
@@ -166,8 +171,11 @@ RC2::FileManager::Impl::insertImage(string fname, string imgNumStr)
166171
sessionImageBatch_ = dbConnection_->longFromQuery(batchq.str().c_str()) + 1;
167172
}
168173
stringstream query;
169-
query << "insert into sessionimage (id,sessionid,batchid,name,imgdata) values (" << imgId
170-
<< "," << sessionRecId_ << "," << sessionImageBatch_ << ",'img" << imgId << ".png',$1::bytea)";
174+
query << "insert into sessionimage (id,sessionid,batchid,name,title,imgdata) values (" << imgId
175+
<< "," << sessionRecId_ << "," << sessionImageBatch_
176+
<< ",'img" << imgId << ".png',"
177+
<< title << ","
178+
<< "$1::bytea)";
171179
int pformats = 1;
172180
int pSizes[] = {(int)size};
173181
const char *params[] = {buffer.get()};
@@ -527,7 +535,6 @@ RC2::FileManager::resetWatch()
527535
// LOG(INFO) << "fm:resetWatch called: " << _impl->imageIds_.size();
528536
if (_impl->imageIds_.size() > 0) {
529537
_impl->sessionImageBatch_++;
530-
LOG(INFO) << "incrementing batch_id:" << _impl->sessionImageBatch_;
531538
}
532539
_impl->imageIds_.erase(_impl->imageIds_.begin(), _impl->imageIds_.end());
533540
_impl->manuallyAddedFiles_.clear();
@@ -541,9 +548,15 @@ RC2::FileManager::checkWatch(vector<long> &imageIds, long &batchId)
541548
// _impl->sessionImageBatch_ = 0;
542549
}
543550

551+
void RC2::FileManager::setTitle(std::string title, std::string imageName)
552+
{
553+
_impl->imgNameToTitle_[imageName] = title;
554+
}
555+
544556
void RC2::FileManager::cleanupImageWatch()
545557
{
546558
_impl->cleanupImageWatch();
559+
_impl->imgNameToTitle_.clear();
547560
}
548561

549562
bool

src/FileManager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace RC2 {
6464
virtual void suspendNotifyEvents();
6565
virtual void resumeNotifyEvents();
6666

67+
virtual void setTitle(std::string title, std::string imageName);
6768
//for unit testing
6869
virtual void processDBNotification(std::string message);
6970

0 commit comments

Comments
 (0)