Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yurii Rashkovskii
committed
Apr 25, 2012
1 parent
34b487d
commit 61d3465
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CMakeCache.txt | ||
CMakeFiles | ||
Makefile | ||
cmake_install.cmake | ||
hypnotoad | ||
clips | ||
c_src/clp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required (VERSION 2.8) | ||
cmake_policy(SET CMP0015 OLD) | ||
project (Hypnotoad) | ||
aux_source_directory(c_src SRC) | ||
aux_source_directory(deps/clips/core CLIPS_SRC) | ||
set(MAIN_CLIPS_SRC ${CLIPS_SRC}) | ||
list(REMOVE_ITEM CLIPS_SRC deps/clips/core/main.c) | ||
list(REMOVE_ITEM CLIPS_SRC deps/clips/core/userfunctions.c) | ||
link_directories(deps/zeromq/src/.libs) | ||
add_executable(clips ${MAIN_CLIPS_SRC}) | ||
add_executable(hypnotoad ${SRC} ${CLIPS_SRC}) | ||
target_link_libraries(hypnotoad libzmq.a) | ||
include_directories("deps/clips/core" "deps/zeromq/include") | ||
|
||
add_custom_command(OUTPUT deps/zeromq/src/.libs/libzmq.a | ||
COMMAND ./autogen.sh | ||
COMMAND ./configure | ||
COMMAND make | ||
WORKING_DIRECTORY deps/zeromq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
#include "zmq.h" | ||
#include "clips.h" | ||
|
||
static void *zmq; | ||
|
||
int main(int argc, char **argv) { | ||
InitializeEnvironment(); | ||
IncrementGCLocks(); | ||
Load("src/main.clp"); | ||
void * module = FindDefmodule("Hypnotoad"); | ||
SetCurrentModule(module); | ||
|
||
UserFunctions(); | ||
|
||
zmq = zmq_init(1); | ||
void * sub = zmq_socket(zmq, ZMQ_SUB); | ||
zmq_bind(sub, "tcp://*:5555"); | ||
zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "", 0); | ||
|
||
while (1) { | ||
char * msg; | ||
zmq_msg_t request; | ||
zmq_msg_init (&request); | ||
zmq_recv (sub, &request, 0); | ||
msg = zmq_msg_data (&request); | ||
LoadFactsFromString(msg, zmq_msg_size(&request)); | ||
Focus(module); | ||
Run(-1); | ||
zmq_msg_close (&request); | ||
} | ||
|
||
|
||
zmq_term(zmq); | ||
|
||
DecrementGCLocks(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "clips.h" | ||
|
||
void UserFunctions(void); | ||
void EnvUserFunctions(void *); | ||
|
||
void * remote_retr_file() | ||
{ | ||
DATA_OBJECT data; | ||
RtnUnknown(1, &data); | ||
|
||
char * filename = (char *) DOToString(data); | ||
|
||
printf("Fetching %s\n", filename); | ||
|
||
return filename; | ||
} | ||
|
||
void UserFunctions() | ||
{ | ||
DefineFunction2("remote-retrieve-file",'s',PTIF remote_retr_file,"remote-retrieve-file","1s"); | ||
} | ||
|
||
#if WIN_BTC | ||
#pragma argsused | ||
#endif | ||
void EnvUserFunctions( | ||
void *theEnv) | ||
{ | ||
#if MAC_MCW || WIN_MCW || MAC_XCD | ||
#pragma unused(theEnv) | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(defmodule Hypnotoad) | ||
|
||
(defrule load-constructs (require ?filename) | ||
=> | ||
(load (remote-retrieve-file ?filename))) | ||
|
||
(defrule load-facts (include ?filename) | ||
=> | ||
(load-facts (remote-retrieve-file ?filename))) |