From bdaae5b6704e29919ec7f284b9e3abe54f96f2f8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 17 Jun 2010 13:07:17 +0200 Subject: Added CMake build system --- .gitignore | 2 +- CMakeLists.txt | 18 ++++ cmake/erlang/ErlangTarget.cmake | 26 ++++++ cmake/erlang/FindErlang.cmake | 6 ++ cmake/vala/FindVala.cmake | 65 +++++++++++++ cmake/vala/ParseArguments.cmake | 36 ++++++++ cmake/vala/ValaPrecompile.cmake | 156 +++++++++++++++++++++++++++++++ cmake/vala/ValaVersion.cmake | 96 +++++++++++++++++++ core/ephraim.erl | 62 ------------- core/ephraim_conn.erl | 45 --------- core/ephraim_conv.erl | 23 ----- gui/CoreConnector.vala | 72 --------------- gui/Ephraim.vala | 31 ------- gui/ephraim.glade | 200 ---------------------------------------- src/CMakeLists.txt | 6 ++ src/core/CMakeLists.txt | 5 + src/core/ephraim.erl | 62 +++++++++++++ src/core/ephraim_conn.erl | 45 +++++++++ src/core/ephraim_conv.erl | 23 +++++ src/gui/CMakeLists.txt | 13 +++ src/gui/CoreConnector.vala | 73 +++++++++++++++ src/gui/Ephraim.vala | 27 ++++++ src/gui/ephraim.glade | 200 ++++++++++++++++++++++++++++++++++++++++ 23 files changed, 858 insertions(+), 434 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/erlang/ErlangTarget.cmake create mode 100644 cmake/erlang/FindErlang.cmake create mode 100644 cmake/vala/FindVala.cmake create mode 100644 cmake/vala/ParseArguments.cmake create mode 100644 cmake/vala/ValaPrecompile.cmake create mode 100644 cmake/vala/ValaVersion.cmake delete mode 100644 core/ephraim.erl delete mode 100644 core/ephraim_conn.erl delete mode 100644 core/ephraim_conv.erl delete mode 100644 gui/CoreConnector.vala delete mode 100644 gui/Ephraim.vala delete mode 100644 gui/ephraim.glade create mode 100644 src/CMakeLists.txt create mode 100644 src/core/CMakeLists.txt create mode 100644 src/core/ephraim.erl create mode 100644 src/core/ephraim_conn.erl create mode 100644 src/core/ephraim_conv.erl create mode 100644 src/gui/CMakeLists.txt create mode 100644 src/gui/CoreConnector.vala create mode 100644 src/gui/Ephraim.vala create mode 100644 src/gui/ephraim.glade diff --git a/.gitignore b/.gitignore index c2a0d67..adf8d81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.beam *~ -gui/Ephraim +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..49f4f09 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +project("ephraim" C) +cmake_minimum_required(VERSION 2.6) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/erlang ${CMAKE_SOURCE_DIR}/cmake/vala) + +include(ErlangTarget) +include(ValaPrecompile) +include(ValaVersion) + +find_package(Erlang REQUIRED) +find_package(Vala REQUIRED) +ensure_vala_version("0.8" MINIMUM) + + +find_package(PkgConfig) +pkg_check_modules(GTK REQUIRED gtk+-2.0) +pkg_check_modules(ERL REQUIRED erl_interface) + +add_subdirectory(src) diff --git a/cmake/erlang/ErlangTarget.cmake b/cmake/erlang/ErlangTarget.cmake new file mode 100644 index 0000000..cfcc431 --- /dev/null +++ b/cmake/erlang/ErlangTarget.cmake @@ -0,0 +1,26 @@ +macro(erl_target name) + set(in_files "") + set(out_files "") + + foreach(src ${ARGN}) + list(APPEND in_files "${CMAKE_CURRENT_SOURCE_DIR}/${src}") + string(REPLACE ".erl" ".beam" src ${src}) + set(out_file "${CMAKE_CURRENT_BINARY_DIR}/${src}") + list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${src}") + endforeach(src ${ARGN}) + + add_custom_command( + OUTPUT + ${out_files} + COMMAND + ${ERLC_EXECUTABLE} + ARGS + "-o" ${CMAKE_CURRENT_BINARY_DIR} + ${in_files} + DEPENDS + ${in_files} + ) + add_custom_target( + ${name} ALL DEPENDS ${out_files} + ) +endmacro(erl_target) diff --git a/cmake/erlang/FindErlang.cmake b/cmake/erlang/FindErlang.cmake new file mode 100644 index 0000000..e7cb60f --- /dev/null +++ b/cmake/erlang/FindErlang.cmake @@ -0,0 +1,6 @@ +find_program(ERLC_EXECUTABLE NAMES erlc) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Erlang DEFAULT_MSG ERLC_EXECUTABLE) +mark_as_advanced(ERLC_EXECUTABLE) + diff --git a/cmake/vala/FindVala.cmake b/cmake/vala/FindVala.cmake new file mode 100644 index 0000000..50f1aed --- /dev/null +++ b/cmake/vala/FindVala.cmake @@ -0,0 +1,65 @@ +## +# Copyright 2009 Jakob Westhoff. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL JAKOB WESTHOFF OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of Jakob Westhoff +## + +## +# Find module for the Vala compiler (valac) +# +# This module determines wheter a Vala compiler is installed on the current +# system and where its executable is. +# +# Call the module using "find_package(Vala) from within your CMakeLists.txt. +# +# The following variables will be set after an invocation: +# +# VALA_FOUND Whether the vala compiler has been found or not +# VALA_EXECUTABLE Full path to the valac executable if it has been found +# VALA_VERSION Version number of the available valac +## + + +# Search for the valac executable in the usual system paths. +find_program(VALA_EXECUTABLE + NAMES valac) + +# Handle the QUIETLY and REQUIRED arguments, which may be given to the find call. +# Furthermore set VALA_FOUND to TRUE if Vala has been found (aka. +# VALA_EXECUTABLE is set) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Vala DEFAULT_MSG VALA_EXECUTABLE) + +mark_as_advanced(VALA_EXECUTABLE) + +# Determine the valac version +if(VALA_FOUND) + execute_process(COMMAND ${VALA_EXECUTABLE} "--version" + OUTPUT_VARIABLE "VALA_VERSION") + string(REPLACE "Vala" "" "VALA_VERSION" ${VALA_VERSION}) + string(STRIP ${VALA_VERSION} "VALA_VERSION") +endif(VALA_FOUND) diff --git a/cmake/vala/ParseArguments.cmake b/cmake/vala/ParseArguments.cmake new file mode 100644 index 0000000..717c0f5 --- /dev/null +++ b/cmake/vala/ParseArguments.cmake @@ -0,0 +1,36 @@ +## +# This is a helper Macro to parse optional arguments in Macros/Functions +# It has been taken from the public CMake wiki. +# See http://www.cmake.org/Wiki/CMakeMacroParseArguments for documentation and +# licensing. +## +macro(parse_arguments prefix arg_names option_names) + set(DEFAULT_ARGS) + foreach(arg_name ${arg_names}) + set(${prefix}_${arg_name}) + endforeach(arg_name) + foreach(option ${option_names}) + set(${prefix}_${option} FALSE) + endforeach(option) + + set(current_arg_name DEFAULT_ARGS) + set(current_arg_list) + foreach(arg ${ARGN}) + set(larg_names ${arg_names}) + list(FIND larg_names "${arg}" is_arg_name) + if(is_arg_name GREATER -1) + set(${prefix}_${current_arg_name} ${current_arg_list}) + set(current_arg_name ${arg}) + set(current_arg_list) + else(is_arg_name GREATER -1) + set(loption_names ${option_names}) + list(FIND loption_names "${arg}" is_option) + if(is_option GREATER -1) + set(${prefix}_${arg} TRUE) + else(is_option GREATER -1) + set(current_arg_list ${current_arg_list} ${arg}) + endif(is_option GREATER -1) + endif(is_arg_name GREATER -1) + endforeach(arg) + set(${prefix}_${current_arg_name} ${current_arg_list}) +endmacro(parse_arguments) diff --git a/cmake/vala/ValaPrecompile.cmake b/cmake/vala/ValaPrecompile.cmake new file mode 100644 index 0000000..f69a096 --- /dev/null +++ b/cmake/vala/ValaPrecompile.cmake @@ -0,0 +1,156 @@ +## +# Copyright 2009 Jakob Westhoff. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL JAKOB WESTHOFF OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of Jakob Westhoff +## + +include(ParseArguments) +find_package(Vala REQUIRED) + +## +# Compile vala files to their c equivalents for further processing. +# +# The "vala_precompile" macro takes care of calling the valac executable on the +# given source to produce c files which can then be processed further using +# default cmake functions. +# +# The first parameter provided is a variable, which will be filled with a list +# of c files outputted by the vala compiler. This list can than be used in +# conjuction with functions like "add_executable" or others to create the +# neccessary compile rules with CMake. +# +# The initial variable is followed by a list of .vala files to be compiled. +# Please take care to add every vala file belonging to the currently compiled +# project or library as Vala will otherwise not be able to resolve all +# dependencies. +# +# The following sections may be specified afterwards to provide certain options +# to the vala compiler: +# +# PACKAGES +# A list of vala packages/libraries to be used during the compile cycle. The +# package names are exactly the same, as they would be passed to the valac +# "--pkg=" option. +# +# OPTIONS +# A list of optional options to be passed to the valac executable. This can be +# used to pass "--thread" for example to enable multi-threading support. +# +# CUSTOM_VAPIS +# A list of custom vapi files to be included for compilation. This can be +# useful to include freshly created vala libraries without having to install +# them in the system. +# +# GENERATE_VAPI +# Pass all the needed flags to the compiler to create an internal vapi for +# the compiled library. The provided name will be used for this and a +# .vapi file will be created. +# +# GENERATE_HEADER +# Let the compiler generate a header file for the compiled code. There will +# be a header file as well as an internal header file being generated called +# .h and _internal.h +# +# The following call is a simple example to the vala_precompile macro showing +# an example to every of the optional sections: +# +# vala_precompile(VALA_C +# source1.vala +# source2.vala +# source3.vala +# PACKAGES +# gtk+-2.0 +# gio-1.0 +# posix +# OPTIONS +# --thread +# CUSTOM_VAPIS +# some_vapi.vapi +# GENERATE_VAPI +# myvapi +# GENERATE_HEADER +# myheader +# ) +# +# Most important is the variable VALA_C which will contain all the generated c +# file names after the call. +## + +macro(vala_precompile output) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + parse_arguments(ARGS "PACKAGES;OPTIONS;GENERATE_HEADER;GENERATE_VAPI;CUSTOM_VAPIS" "" ${ARGN}) + set(vala_pkg_opts "") + foreach(pkg ${ARGS_PACKAGES}) + list(APPEND vala_pkg_opts "--pkg=${pkg}") + endforeach(pkg ${ARGS_PACKAGES}) + set(in_files "") + set(out_files "") + set(${output} "") + foreach(src ${ARGS_DEFAULT_ARGS}) + list(APPEND in_files "${CMAKE_CURRENT_SOURCE_DIR}/${src}") + string(REPLACE ".vala" ".c" src ${src}) + set(out_file "${CMAKE_CURRENT_BINARY_DIR}/${src}") + list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${src}") + list(APPEND ${output} ${out_file}) + endforeach(src ${ARGS_DEFAULT_ARGS}) + + set(vapi_arguments "") + if(ARGS_GENERATE_VAPI) + list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_GENERATE_VAPI}.vapi") + set(vapi_arguments "--internal-vapi=${ARGS_GENERATE_VAPI}.vapi") + + # Header and internal header is needed to generate internal vapi + if (NOT ARGS_GENERATE_HEADER) + set(ARGS_GENERATE_HEADER ${ARGS_GENERATE_VAPI}) + endif(NOT ARGS_GENERATE_HEADER) + endif(ARGS_GENERATE_VAPI) + + set(header_arguments "") + if(ARGS_GENERATE_HEADER) + list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_GENERATE_HEADER}.h") + list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_GENERATE_HEADER}_internal.h") + list(APPEND header_arguments "--header=${ARGS_GENERATE_HEADER}.h") + list(APPEND header_arguments "--internal-header=${ARGS_GENERATE_HEADER}_internal.h") + endif(ARGS_GENERATE_HEADER) + + add_custom_command(OUTPUT ${out_files} + COMMAND + ${VALA_EXECUTABLE} + ARGS + "-C" + ${header_arguments} + ${vapi_arguments} + "-b" ${CMAKE_CURRENT_SOURCE_DIR} + "-d" ${CMAKE_CURRENT_BINARY_DIR} + ${vala_pkg_opts} + ${ARGS_OPTIONS} + ${in_files} + ${ARGS_CUSTOM_VAPIS} + DEPENDS + ${in_files} + ${ARGS_CUSTOM_VAPIS} + ) +endmacro(vala_precompile) diff --git a/cmake/vala/ValaVersion.cmake b/cmake/vala/ValaVersion.cmake new file mode 100644 index 0000000..fba9df6 --- /dev/null +++ b/cmake/vala/ValaVersion.cmake @@ -0,0 +1,96 @@ +## +# Copyright 2009 Jakob Westhoff. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL JAKOB WESTHOFF OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of Jakob Westhoff +## + +include(ParseArguments) +find_package(Vala REQUIRED) + +## +# Ensure a certain valac version is available +# +# The initial argument is the version to check for +# +# It may be followed by a optional parameter to specifiy a version range. The +# following options are valid: +# +# EXACT +# Vala needs to be available in the exact version given +# +# MINIMUM +# The provided version is the minimum version. Therefore Vala needs to be +# available in the given version or any higher version +# +# MAXIMUM +# The provided version is the maximum. Therefore Vala needs to be available +# in the given version or any version older than this +# +# If no option is specified the version will be treated as a minimal version. +## +macro(ensure_vala_version version) + parse_arguments(ARGS "" "MINIMUM;MAXIMUM;EXACT" ${ARGN}) + set(compare_message "") + set(error_message "") + if(ARGS_MINIMUM) + set(compare_message "a minimum ") + set(error_message "or greater ") + elseif(ARGS_MAXIMUM) + set(compare_message "a maximum ") + set(error_message "or less ") + endif(ARGS_MINIMUM) + + message(STATUS + "checking for ${compare_message}Vala version of ${version}" + ) + + unset(version_accepted) + + # MINIMUM is the default if no option is specified + if(ARGS_EXACT) + if(${VALA_VERSION} VERSION_EQUAL ${version} ) + set(version_accepted TRUE) + endif(${VALA_VERSION} VERSION_EQUAL ${version}) + elseif(ARGS_MAXIMUM) + if(${VALA_VERSION} VERSION_LESS ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version}) + set(version_accepted TRUE) + endif(${VALA_VERSION} VERSION_LESS ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version}) + else(ARGS_MAXIMUM) + if(${VALA_VERSION} VERSION_GREATER ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version}) + set(version_accepted TRUE) + endif(${VALA_VERSION} VERSION_GREATER ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version}) + endif(ARGS_EXACT) + + if (NOT version_accepted) + message(FATAL_ERROR + "Vala version ${version} ${error_message}is required." + ) + endif(NOT version_accepted) + + message(STATUS + " found Vala, version ${VALA_VERSION}" + ) +endmacro(ensure_vala_version) diff --git a/core/ephraim.erl b/core/ephraim.erl deleted file mode 100644 index 6a68de0..0000000 --- a/core/ephraim.erl +++ /dev/null @@ -1,62 +0,0 @@ --module(ephraim). --compile([debug_info, export_all]). - --record(state, { - conn :: pid(), - convs :: dict(), - guis :: set() - }). - --spec start() -> ok. -start() -> - Pid = spawn(?MODULE, init, []), - case register(ephraim, Pid) of - true -> - ok - end. - --spec stop() -> ok. -stop() -> - ephraim ! stop, - ok. - --spec init() -> ok. -init() -> - Conn = spawn(ephraim_conn, init, []), - loop(#state{conn=Conn,convs=dict:new(),guis=sets:new()}). - --spec get_conv(#state{},exmpp_jid:jid()) -> {#state{},pid()}. -get_conv(State, JID) -> - Key = exmpp_jid:to_lower(exmpp_jid:bare(JID)), - case dict:find(Key, State#state.convs) of - {ok, Conv} -> - {State, Conv}; - error -> - Conv = spawn(ephraim_conv, init, [Key]), - Dict = dict:store(Key, Conv, State#state.convs), - {State#state{convs=Dict}, Conv} - end. - --spec loop(#state{}) -> ok. -loop(State) -> - receive - stop -> - dict:fold(fun(_,Conv,Msg) -> Conv ! Msg end, stop, State#state.convs), - State#state.conn ! stop, - ok; - {register_gui, Pid} -> - GUIs = State#state.guis, - State2 = State#state{guis=sets:add_element(Pid,GUIs)}, - loop(State2); - {unregister_gui, Pid} -> - GUIs = State#state.guis, - State2 = State#state{guis=sets:del_element(Pid,GUIs)}, - loop(State2); - {receive_message, From, Packet} -> - {State2, Conv} = get_conv(State, From), - Conv ! {receive_message, Packet}, - loop(State2); - Msg -> - io:format("ephraim: ~p~n", [Msg]), - loop(State) - end. diff --git a/core/ephraim_conn.erl b/core/ephraim_conn.erl deleted file mode 100644 index 18edd6a..0000000 --- a/core/ephraim_conn.erl +++ /dev/null @@ -1,45 +0,0 @@ --module(ephraim_conn). --include_lib("exmpp/include/exmpp_client.hrl"). --compile([debug_info, export_all]). - --record(conn_state, { - session :: any(), - roster :: any() - }). - --spec init() -> ok. -init() -> - application:start(exmpp), - Session = exmpp_session:start(), - JID = exmpp_jid:make("ephraim-test", "jabber.ccc.de", "Bar"), - exmpp_session:auth_basic_digest(Session, JID, "foobarbla"), - exmpp_session:connect_TCP(Session, "jabber.ccc.de", 5222), - session(#conn_state{session=Session}). - --spec session(#conn_state{}) -> ok. -session(State) -> - exmpp_session:login(State#conn_state.session), - exmpp_session:send_packet(State#conn_state.session, exmpp_presence:set_status(exmpp_presence:available(), "Foo/Test\\Bar")), - loop(State). - --spec loop(#conn_state{}) -> ok. -loop(State) -> - receive - stop -> - exmpp_session:stop(State#conn_state.session); - - #received_packet{packet_type=presence, raw_packet=Packet} -> - From = exmpp_xml:get_attribute(Packet, from, <<"unknown">>), - Type = atom_to_list(exmpp_presence:get_type(Packet)), - Status = exmpp_presence:get_status(Packet), - io:format("~ts is now ~ts: ~ts~n", [From, Type, Status]), - loop(State); - - #received_packet{packet_type=message, raw_packet=Packet} -> - From = exmpp_xml:get_attribute(Packet, from, <<"unknown">>), - ephraim ! {receive_message, From, Packet}, - loop(State); - Msg -> - io:format("ephraim_conn: ~p~n", [Msg]), - loop(State) - end. diff --git a/core/ephraim_conv.erl b/core/ephraim_conv.erl deleted file mode 100644 index 99c7668..0000000 --- a/core/ephraim_conv.erl +++ /dev/null @@ -1,23 +0,0 @@ --module(ephraim_conv). --compile([debug_info, export_all]). - --record(conv_state, { - jid :: exmpp_jid:jid() - }). - --spec init(exmpp_jid:jid()) -> ok. -init(JID) -> - loop(#conv_state{jid=JID}). - --spec loop(#conv_state{}) -> ok. -loop(State) -> - receive - stop -> - ok; - {receive_message, Packet} -> - io:format("Received packet from ~p: ~p~n", [State#conv_state.jid, Packet]), - loop(State); - Msg -> - io:format("ephraim_conv (~p): ~p~n", [State#conv_state.jid, Msg]), - loop(State) - end. diff --git a/gui/CoreConnector.vala b/gui/CoreConnector.vala deleted file mode 100644 index a3f0910..0000000 --- a/gui/CoreConnector.vala +++ /dev/null @@ -1,72 +0,0 @@ -using Erl; - - -public class CoreConnector { - unowned Thread thread; - bool running; - - private class TermStore { - public Erl.Term term; - } - - public CoreConnector() { - running = false; - } - - public bool start() { - if(running) - return true; - - running = true; - - try { - thread = Thread.create(receive, true); - return true; - } catch(ThreadError e) { - return false; - } - } - - public void stop() { - if(!running) - return; - - running = false; - thread.join(); - } - - private void* receive() { - Erl.Node node = Erl.Node("ephraim-gtk", "magiccookie", 0); - Erl.Connection con = node.connect("ephraim-core@avalon.local"); - - con.reg_send("ephraim", Erl.mk_self_pid(node)); - - while(running) { - TermStore response = new TermStore(); - Erl.ReceiveType ret = con.receive(out response.term, 1000); - - switch(ret) { - case Erl.ReceiveType.ERROR: - if(Erl.errno == Erl.Error.TIMEDOUT) - break; - - running = false; - break; - case Erl.ReceiveType.TICK: - // Do nothing - break; - case Erl.ReceiveType.MSG: - Idle.add(() => {handleTerm(response); return false;}); - break; - } - } - - return null; - } - - private void handleTerm(TermStore store) { - unowned Term term = store.term; - Erl.print_term(stdout, term); - stdout.printf("\n"); - } -} diff --git a/gui/Ephraim.vala b/gui/Ephraim.vala deleted file mode 100644 index d05e449..0000000 --- a/gui/Ephraim.vala +++ /dev/null @@ -1,31 +0,0 @@ -using Gtk; - - -public class Ephraim { - public static int main(string[] args) { - Gtk.init(ref args); - Erl.init(); - - Gtk.Builder builder = new Gtk.Builder(); - try { - builder.add_from_file("ephraim.glade"); - } catch(Error e) { - return 1; - } - - CoreConnector coreconn = new CoreConnector(); - - if(!coreconn.start()) - return 1; - - unowned Gtk.Window window = builder.get_object("MainWindow") as Gtk.Window; - window.hide.connect(Gtk.main_quit); - window.show(); - - Gtk.main(); - - coreconn.stop(); - - return 0; - } -} diff --git a/gui/ephraim.glade b/gui/ephraim.glade deleted file mode 100644 index b1b3455..0000000 --- a/gui/ephraim.glade +++ /dev/null @@ -1,200 +0,0 @@ - - - - - - - - True - vertical - - - True - - - True - _Datei - True - - - True - - - gtk-new - True - True - True - - - - - gtk-open - True - True - True - - - - - gtk-save - True - True - True - - - - - gtk-save-as - True - True - True - - - - - True - - - - - gtk-quit - True - True - True - - - - - - - - - True - _Bearbeiten - True - - - True - - - gtk-cut - True - True - True - - - - - gtk-copy - True - True - True - - - - - gtk-paste - True - True - True - - - - - gtk-delete - True - True - True - - - - - - - - - True - _Ansicht - True - - - - - True - _Hilfe - True - - - True - - - gtk-about - True - True - True - - - - - - - - - False - 0 - - - - - True - True - - - True - True - RosterStore - - - False - True - - - - - True - True - True - - - - - - - - - - - - - - - - - - - - - True - True - - - - - 1 - - - - - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..859b25d --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +add_definitions(${GTK_CFLAGS} ${GTK_CFLAGS_OTHER} ${ERL_CFLAGS} ${ERL_CFLAGS_OTHER}) +link_libraries(${GTK_LIBRARIES} ${ERL_LIBRARIES}) +link_directories(${GTK_LIBRARY_DIRS} ${ERL_LIBRARY_DIRS}) + +add_subdirectory(core ${ephraim_BINARY_DIR}/core) +add_subdirectory(gui ${ephraim_BINARY_DIR}/gui) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt new file mode 100644 index 0000000..470e686 --- /dev/null +++ b/src/core/CMakeLists.txt @@ -0,0 +1,5 @@ +erl_target(ephraim-core + ephraim.erl + ephraim_conn.erl + ephraim_conv.erl +) diff --git a/src/core/ephraim.erl b/src/core/ephraim.erl new file mode 100644 index 0000000..6a68de0 --- /dev/null +++ b/src/core/ephraim.erl @@ -0,0 +1,62 @@ +-module(ephraim). +-compile([debug_info, export_all]). + +-record(state, { + conn :: pid(), + convs :: dict(), + guis :: set() + }). + +-spec start() -> ok. +start() -> + Pid = spawn(?MODULE, init, []), + case register(ephraim, Pid) of + true -> + ok + end. + +-spec stop() -> ok. +stop() -> + ephraim ! stop, + ok. + +-spec init() -> ok. +init() -> + Conn = spawn(ephraim_conn, init, []), + loop(#state{conn=Conn,convs=dict:new(),guis=sets:new()}). + +-spec get_conv(#state{},exmpp_jid:jid()) -> {#state{},pid()}. +get_conv(State, JID) -> + Key = exmpp_jid:to_lower(exmpp_jid:bare(JID)), + case dict:find(Key, State#state.convs) of + {ok, Conv} -> + {State, Conv}; + error -> + Conv = spawn(ephraim_conv, init, [Key]), + Dict = dict:store(Key, Conv, State#state.convs), + {State#state{convs=Dict}, Conv} + end. + +-spec loop(#state{}) -> ok. +loop(State) -> + receive + stop -> + dict:fold(fun(_,Conv,Msg) -> Conv ! Msg end, stop, State#state.convs), + State#state.conn ! stop, + ok; + {register_gui, Pid} -> + GUIs = State#state.guis, + State2 = State#state{guis=sets:add_element(Pid,GUIs)}, + loop(State2); + {unregister_gui, Pid} -> + GUIs = State#state.guis, + State2 = State#state{guis=sets:del_element(Pid,GUIs)}, + loop(State2); + {receive_message, From, Packet} -> + {State2, Conv} = get_conv(State, From), + Conv ! {receive_message, Packet}, + loop(State2); + Msg -> + io:format("ephraim: ~p~n", [Msg]), + loop(State) + end. diff --git a/src/core/ephraim_conn.erl b/src/core/ephraim_conn.erl new file mode 100644 index 0000000..18edd6a --- /dev/null +++ b/src/core/ephraim_conn.erl @@ -0,0 +1,45 @@ +-module(ephraim_conn). +-include_lib("exmpp/include/exmpp_client.hrl"). +-compile([debug_info, export_all]). + +-record(conn_state, { + session :: any(), + roster :: any() + }). + +-spec init() -> ok. +init() -> + application:start(exmpp), + Session = exmpp_session:start(), + JID = exmpp_jid:make("ephraim-test", "jabber.ccc.de", "Bar"), + exmpp_session:auth_basic_digest(Session, JID, "foobarbla"), + exmpp_session:connect_TCP(Session, "jabber.ccc.de", 5222), + session(#conn_state{session=Session}). + +-spec session(#conn_state{}) -> ok. +session(State) -> + exmpp_session:login(State#conn_state.session), + exmpp_session:send_packet(State#conn_state.session, exmpp_presence:set_status(exmpp_presence:available(), "Foo/Test\\Bar")), + loop(State). + +-spec loop(#conn_state{}) -> ok. +loop(State) -> + receive + stop -> + exmpp_session:stop(State#conn_state.session); + + #received_packet{packet_type=presence, raw_packet=Packet} -> + From = exmpp_xml:get_attribute(Packet, from, <<"unknown">>), + Type = atom_to_list(exmpp_presence:get_type(Packet)), + Status = exmpp_presence:get_status(Packet), + io:format("~ts is now ~ts: ~ts~n", [From, Type, Status]), + loop(State); + + #received_packet{packet_type=message, raw_packet=Packet} -> + From = exmpp_xml:get_attribute(Packet, from, <<"unknown">>), + ephraim ! {receive_message, From, Packet}, + loop(State); + Msg -> + io:format("ephraim_conn: ~p~n", [Msg]), + loop(State) + end. diff --git a/src/core/ephraim_conv.erl b/src/core/ephraim_conv.erl new file mode 100644 index 0000000..99c7668 --- /dev/null +++ b/src/core/ephraim_conv.erl @@ -0,0 +1,23 @@ +-module(ephraim_conv). +-compile([debug_info, export_all]). + +-record(conv_state, { + jid :: exmpp_jid:jid() + }). + +-spec init(exmpp_jid:jid()) -> ok. +init(JID) -> + loop(#conv_state{jid=JID}). + +-spec loop(#conv_state{}) -> ok. +loop(State) -> + receive + stop -> + ok; + {receive_message, Packet} -> + io:format("Received packet from ~p: ~p~n", [State#conv_state.jid, Packet]), + loop(State); + Msg -> + io:format("ephraim_conv (~p): ~p~n", [State#conv_state.jid, Msg]), + loop(State) + end. diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt new file mode 100644 index 0000000..8839e16 --- /dev/null +++ b/src/gui/CMakeLists.txt @@ -0,0 +1,13 @@ +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ephraim_BINARY_DIR}) + +vala_precompile(VALA_C + "Ephraim.vala" + "CoreConnector.vala" +PACKAGES + gtk+-2.0 + erl_interface +OPTIONS + --thread +) + +add_executable("ephraim-gtk" ${VALA_C}) diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala new file mode 100644 index 0000000..08ed43f --- /dev/null +++ b/src/gui/CoreConnector.vala @@ -0,0 +1,73 @@ +public class CoreConnector { + unowned Thread thread; + bool running; + + private class TermStore { + public Erl.Term term; + } + + static construct { + Erl.init(); + } + + public CoreConnector() { + running = false; + } + + public bool start() { + if(running) + return true; + + running = true; + + try { + thread = Thread.create(receive, true); + return true; + } catch(ThreadError e) { + return false; + } + } + + public void stop() { + if(!running) + return; + + running = false; + thread.join(); + } + + private void* receive() { + Erl.Node node = Erl.Node("ephraim-gtk", "magiccookie", 0); + Erl.Connection con = node.connect("ephraim-core@avalon.local"); + + con.reg_send("ephraim", Erl.mk_self_pid(node)); + + while(running) { + TermStore response = new TermStore(); + Erl.ReceiveType ret = con.receive(out response.term, 1000); + + switch(ret) { + case Erl.ReceiveType.ERROR: + if(Erl.errno == Erl.Error.TIMEDOUT) + break; + + running = false; + break; + case Erl.ReceiveType.TICK: + // Do nothing + break; + case Erl.ReceiveType.MSG: + Idle.add(() => {handleTerm(response); return false;}); + break; + } + } + + return null; + } + + private void handleTerm(TermStore store) { + unowned Erl.Term term = store.term; + Erl.print_term(stdout, term); + stdout.printf("\n"); + } +} diff --git a/src/gui/Ephraim.vala b/src/gui/Ephraim.vala new file mode 100644 index 0000000..a52c4df --- /dev/null +++ b/src/gui/Ephraim.vala @@ -0,0 +1,27 @@ +public class Ephraim { + public static int main(string[] args) { + Gtk.init(ref args); + + Gtk.Builder builder = new Gtk.Builder(); + try { + builder.add_from_file("ephraim.glade"); + } catch(Error e) { + return 1; + } + + CoreConnector coreconn = new CoreConnector(); + + if(!coreconn.start()) + return 1; + + unowned Gtk.Window window = builder.get_object("MainWindow") as Gtk.Window; + window.hide.connect(Gtk.main_quit); + window.show(); + + Gtk.main(); + + coreconn.stop(); + + return 0; + } +} diff --git a/src/gui/ephraim.glade b/src/gui/ephraim.glade new file mode 100644 index 0000000..b1b3455 --- /dev/null +++ b/src/gui/ephraim.glade @@ -0,0 +1,200 @@ + + + + + + + + True + vertical + + + True + + + True + _Datei + True + + + True + + + gtk-new + True + True + True + + + + + gtk-open + True + True + True + + + + + gtk-save + True + True + True + + + + + gtk-save-as + True + True + True + + + + + True + + + + + gtk-quit + True + True + True + + + + + + + + + True + _Bearbeiten + True + + + True + + + gtk-cut + True + True + True + + + + + gtk-copy + True + True + True + + + + + gtk-paste + True + True + True + + + + + gtk-delete + True + True + True + + + + + + + + + True + _Ansicht + True + + + + + True + _Hilfe + True + + + True + + + gtk-about + True + True + True + + + + + + + + + False + 0 + + + + + True + True + + + True + True + RosterStore + + + False + True + + + + + True + True + True + + + + + + + + + + + + + + + + + + + + + True + True + + + + + 1 + + + + + + + -- cgit v1.2.3