mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-14 07:07:46 +02:00
xxx
git-svn-id: svn://elaine/murooma/trunk@122 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
b0fe090d21
commit
ce1c5fb3ac
5 changed files with 73 additions and 40 deletions
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
VERSION = 0.01
|
VERSION = 0.01
|
||||||
CC = /usr/bin/g++
|
CC = /usr/bin/g++
|
||||||
CFLAGS = -std=gnu++0x -Wall -g -O3 -D_REENTRANT -DVERSION=\"$(VERSION)\"
|
CFLAGS = -std=gnu++0x -Wall -Wno-unused-function -g -O3 -D_REENTRANT -DVERSION=\"$(VERSION)\"
|
||||||
LDFLAGS = -lrt -lzmq -lpthread -lportaudio
|
LDFLAGS = -lrt -lzmq -lpthread -lportaudio
|
||||||
|
|
||||||
OBJ_SERVER = server.o
|
OBJ_SERVER = server.o
|
||||||
|
|
20
client.cpp
20
client.cpp
|
@ -8,7 +8,6 @@
|
||||||
#include <zmq.hpp>
|
#include <zmq.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
@ -16,9 +15,9 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
#include <iterator>
|
|
||||||
|
|
||||||
#include "chunk.h"
|
#include "chunk.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "zhelpers.hpp"
|
#include "zhelpers.hpp"
|
||||||
|
|
||||||
|
@ -49,17 +48,6 @@ void player()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string getMacAddress()
|
|
||||||
{
|
|
||||||
std::ifstream t("/sys/class/net/eth0/address");
|
|
||||||
std::string str((std::istreambuf_iterator<char>(t)),
|
|
||||||
std::istreambuf_iterator<char>());
|
|
||||||
str.erase(std::find_if(str.rbegin(), str.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), str.end());
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void control(Stream* stream)
|
void control(Stream* stream)
|
||||||
{
|
{
|
||||||
zmq::context_t context(1);
|
zmq::context_t context(1);
|
||||||
|
@ -74,11 +62,7 @@ void control(Stream* stream)
|
||||||
s_send (worker, "ready");
|
s_send (worker, "ready");
|
||||||
while (1) {
|
while (1) {
|
||||||
std::string cmd = s_recv (worker);
|
std::string cmd = s_recv (worker);
|
||||||
istringstream iss(cmd);
|
vector<std::string> splitCmd = split(cmd);
|
||||||
vector<std::string> splitCmd;
|
|
||||||
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(splitCmd));
|
|
||||||
for (size_t n=0; n<splitCmd.size(); ++n)
|
|
||||||
std::cout << "cmd: " << splitCmd[n] << "\n";
|
|
||||||
if (splitCmd.size() > 1)
|
if (splitCmd.size() > 1)
|
||||||
{
|
{
|
||||||
if (splitCmd[0] == "buffer")
|
if (splitCmd[0] == "buffer")
|
||||||
|
|
|
@ -13,20 +13,11 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
std::string getMacAddress()
|
|
||||||
{
|
|
||||||
std::ifstream t("/sys/class/net/eth0/address");
|
|
||||||
std::string str((std::istreambuf_iterator<char>(t)),
|
|
||||||
std::istreambuf_iterator<char>());
|
|
||||||
str.erase(std::find_if(str.rbegin(), str.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), str.end());
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void control()
|
void control()
|
||||||
{
|
{
|
||||||
|
@ -36,15 +27,13 @@ void control()
|
||||||
// We use a string identity for ease here
|
// We use a string identity for ease here
|
||||||
string macAddress = getMacAddress();
|
string macAddress = getMacAddress();
|
||||||
worker.setsockopt(ZMQ_IDENTITY, macAddress.c_str(), macAddress.length());
|
worker.setsockopt(ZMQ_IDENTITY, macAddress.c_str(), macAddress.length());
|
||||||
worker.connect("tcp://127.0.0.1:10000");
|
worker.connect("tcp://127.0.0.1:123459");
|
||||||
|
|
||||||
// Tell the router we're ready for work
|
// Tell the router we're ready for work
|
||||||
s_send (worker, "ready");
|
s_send (worker, "ready");
|
||||||
while (1) {
|
while (1) {
|
||||||
std::string cmd = s_recv (worker);
|
std::string cmd = s_recv (worker);
|
||||||
istringstream iss(cmd);
|
vector<std::string> splitCmd = split(cmd);
|
||||||
vector<std::string> splitCmd;
|
|
||||||
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(splitCmd));
|
|
||||||
for (size_t n=0; n<splitCmd.size(); ++n)
|
for (size_t n=0; n<splitCmd.size(); ++n)
|
||||||
std::cout << "cmd: " << splitCmd[n] << "\n";
|
std::cout << "cmd: " << splitCmd[n] << "\n";
|
||||||
s_send(worker, "ACK " + cmd);
|
s_send(worker, "ACK " + cmd);
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include "zhelpers.hpp"
|
#include "zhelpers.hpp"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
zmq::socket_t* client;
|
||||||
|
|
||||||
void receiver(zmq::socket_t* client)
|
void receiver(zmq::socket_t* client)
|
||||||
{
|
{
|
||||||
|
@ -24,13 +25,20 @@ void receiver(zmq::socket_t* client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void send(const std::string& address, const std::string& cmd)
|
||||||
|
{
|
||||||
|
s_sendmore (*client, address);
|
||||||
|
s_sendmore (*client, "");
|
||||||
|
s_send (*client, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
zmq::context_t context(2);
|
zmq::context_t context(2);
|
||||||
zmq::socket_t client (context, ZMQ_ROUTER);
|
client = new zmq::socket_t(context, ZMQ_ROUTER);
|
||||||
client.bind("tcp://0.0.0.0:123459");
|
client->bind("tcp://0.0.0.0:123459");
|
||||||
|
|
||||||
std::thread receiveThread(receiver, &client);
|
std::thread receiveThread(receiver, client);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -39,9 +47,7 @@ int main () {
|
||||||
|
|
||||||
std::getline(std::cin, address);
|
std::getline(std::cin, address);
|
||||||
std::getline(std::cin, cmd);
|
std::getline(std::cin, cmd);
|
||||||
s_sendmore (client, address);
|
send(trim(address), trim(cmd));
|
||||||
s_sendmore (client, "");
|
|
||||||
s_send (client, cmd);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
54
utils.h
Normal file
54
utils.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#ifndef UTILS_H
|
||||||
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include <cctype>
|
||||||
|
#include <locale>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
|
||||||
|
// trim from start
|
||||||
|
static inline std::string <rim(std::string &s) {
|
||||||
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// trim from end
|
||||||
|
static inline std::string &rtrim(std::string &s) {
|
||||||
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// trim from both ends
|
||||||
|
static inline std::string &trim(std::string &s) {
|
||||||
|
return ltrim(rtrim(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static std::string getMacAddress()
|
||||||
|
{
|
||||||
|
std::ifstream t("/sys/class/net/eth0/address");
|
||||||
|
std::string str((std::istreambuf_iterator<char>(t)),
|
||||||
|
std::istreambuf_iterator<char>());
|
||||||
|
return trim(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> split(const std::string& str)
|
||||||
|
{
|
||||||
|
std::istringstream iss(str);
|
||||||
|
std::vector<std::string> splitStr;
|
||||||
|
std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(splitStr));
|
||||||
|
return splitStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue