Upload folder using huggingface_hub (part 110)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard010/C++/0111158_CompressRGB.cpp +140 -0
- pool/shard010/C++/0111161_Server.cpp +132 -0
- pool/shard010/C++/0111165_Base32Test.cpp +184 -0
- pool/shard010/C++/0111171_output_accel_angle.cpp +20 -0
- pool/shard010/C++/0111173_webfilesystem_impl.cc +144 -0
- pool/shard010/C++/0111175_WiggleRangeParser.cc +19 -0
- pool/shard010/C++/0111180_testopenstreetmap.cpp +193 -0
- pool/shard010/C++/0111181_LengthNormWriter.cpp +102 -0
- pool/shard010/C++/0111182_GSGrid_Residuals.cpp +230 -0
- pool/shard010/C++/0111185_get_reference_vreg_jni.cc +88 -0
- pool/shard010/C++/0111194_editaddressdialog.cpp +137 -0
- pool/shard010/C++/0111200_HardwareTimer.cpp +156 -0
- pool/shard010/C++/0111202_LinkerObject.cpp +79 -0
- pool/shard010/C++/0111204_VRMarker.cpp +55 -0
- pool/shard010/C++/0111207_EnhancedPositionClient.cpp +95 -0
- pool/shard010/C++/0111208_CWE23_Relative_Path_Traversal__wchar_t_listen_socket_fopen_45.cpp +228 -0
- pool/shard010/C++/0111210_catalog_proxy.cpp +92 -0
- pool/shard010/C++/0111212_helpers.cpp +59 -0
- pool/shard010/C++/0111214_DWARFDebugArangeSet.cpp +274 -0
- pool/shard010/C++/0111216_lru.cc +62 -0
- pool/shard010/C++/0111221_mirror_layer_impl.cc +91 -0
- pool/shard010/C++/0111222_switch.cc +217 -0
- pool/shard010/C++/0111225_bitcoind.cpp +141 -0
- pool/shard010/C++/0111231_chapter24_ex10.cpp +48 -0
- pool/shard010/C++/0111233_c_net_engine.cpp +159 -0
- pool/shard010/C++/0111234_print_preview_data_source.cc +178 -0
- pool/shard010/C++/0111244_CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82a.cpp +94 -0
- pool/shard010/C++/0111246_call_combiner.cc +214 -0
- pool/shard010/C++/0111247_Settings.cpp +54 -0
- pool/shard010/C++/0111251_platform.cpp +113 -0
- pool/shard010/C++/0111256_main.cpp +99 -0
- pool/shard010/C++/0111257_describelocalgatewayroutetablesresponse.cpp +132 -0
- pool/shard010/C++/0111259_decode_svc_test.cc +125 -0
- pool/shard010/C++/0111260_bitcoin.cpp +297 -0
- pool/shard010/C++/0111266_CryptoKeyReader.cc +80 -0
- pool/shard010/C++/0111268_Jit_Branch.cpp +251 -0
- pool/shard010/C++/0111275_best_time_to_buy_and_sell_stock.cpp +31 -0
- pool/shard010/C++/0111278_SetSelectionCommand.cpp +59 -0
- pool/shard010/C++/0111279_unnamed_event.cc +197 -0
- pool/shard010/C++/0111283_connect_test.cpp +222 -0
- pool/shard010/C++/0111284_main.cpp +48 -0
- pool/shard010/C++/0111285_speedwidget.cpp +205 -0
- pool/shard010/C++/0111286_camera_self_filter_server.cpp +186 -0
- pool/shard010/C++/0111288_CAirbusStaticPort.cpp +53 -0
- pool/shard010/C++/0111293_MSOfficeTextStripper.cpp +98 -0
- pool/shard010/C++/0111295_dfsalgo.cpp +107 -0
- pool/shard010/C++/0111298_DeferredRenderPipeline.cpp +74 -0
- pool/shard010/C++/0111302_QGis.cpp +78 -0
- pool/shard010/C++/0111303_enumliterals.cpp +26 -0
- pool/shard010/C++/0111308_playerwatcher.cpp +153 -0
pool/shard010/C++/0111158_CompressRGB.cpp
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
|
| 2 |
+
//
|
| 3 |
+
// Permission is hereby granted, free of charge, to any person
|
| 4 |
+
// obtaining a copy of this software and associated documentation
|
| 5 |
+
// files (the "Software"), to deal in the Software without
|
| 6 |
+
// restriction, including without limitation the rights to use,
|
| 7 |
+
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
// copies of the Software, and to permit persons to whom the
|
| 9 |
+
// Software is furnished to do so, subject to the following
|
| 10 |
+
// conditions:
|
| 11 |
+
//
|
| 12 |
+
// The above copyright notice and this permission notice shall be
|
| 13 |
+
// included in all copies or substantial portions of the Software.
|
| 14 |
+
//
|
| 15 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 16 |
+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 17 |
+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 18 |
+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 19 |
+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 20 |
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 21 |
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 22 |
+
// OTHER DEALINGS IN THE SOFTWARE.
|
| 23 |
+
|
| 24 |
+
#include <nvcore/Debug.h>
|
| 25 |
+
|
| 26 |
+
#include <nvimage/Image.h>
|
| 27 |
+
#include <nvimage/PixelFormat.h>
|
| 28 |
+
#include <nvmath/Color.h>
|
| 29 |
+
|
| 30 |
+
#include "CompressRGB.h"
|
| 31 |
+
#include "CompressionOptions.h"
|
| 32 |
+
#include "OutputOptions.h"
|
| 33 |
+
|
| 34 |
+
using namespace nv;
|
| 35 |
+
using namespace nvtt;
|
| 36 |
+
|
| 37 |
+
namespace
|
| 38 |
+
{
|
| 39 |
+
|
| 40 |
+
inline uint computePitch(uint w, uint bitsize)
|
| 41 |
+
{
|
| 42 |
+
uint p = w * ((bitsize + 7) / 8);
|
| 43 |
+
|
| 44 |
+
// Align to 32 bits.
|
| 45 |
+
return ((p + 3) / 4) * 4;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
inline void convert_to_a8r8g8b8(const void * src, void * dst, uint w)
|
| 49 |
+
{
|
| 50 |
+
memcpy(dst, src, 4 * w);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
inline void convert_to_x8r8g8b8(const void * src, void * dst, uint w)
|
| 54 |
+
{
|
| 55 |
+
memcpy(dst, src, 4 * w);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
} // namespace
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
// Pixel format converter.
|
| 62 |
+
void nv::compressRGB(const Image * image, const OutputOptions::Private & outputOptions, const CompressionOptions::Private & compressionOptions)
|
| 63 |
+
{
|
| 64 |
+
nvCheck(image != NULL);
|
| 65 |
+
|
| 66 |
+
const uint w = image->width();
|
| 67 |
+
const uint h = image->height();
|
| 68 |
+
|
| 69 |
+
const uint bitCount = compressionOptions.bitcount;
|
| 70 |
+
nvCheck(bitCount == 8 || bitCount == 16 || bitCount == 24 || bitCount == 32);
|
| 71 |
+
|
| 72 |
+
const uint byteCount = bitCount / 8;
|
| 73 |
+
|
| 74 |
+
const uint rmask = compressionOptions.rmask;
|
| 75 |
+
uint rshift, rsize;
|
| 76 |
+
PixelFormat::maskShiftAndSize(rmask, &rshift, &rsize);
|
| 77 |
+
|
| 78 |
+
const uint gmask = compressionOptions.gmask;
|
| 79 |
+
uint gshift, gsize;
|
| 80 |
+
PixelFormat::maskShiftAndSize(gmask, &gshift, &gsize);
|
| 81 |
+
|
| 82 |
+
const uint bmask = compressionOptions.bmask;
|
| 83 |
+
uint bshift, bsize;
|
| 84 |
+
PixelFormat::maskShiftAndSize(bmask, &bshift, &bsize);
|
| 85 |
+
|
| 86 |
+
const uint amask = compressionOptions.amask;
|
| 87 |
+
uint ashift, asize;
|
| 88 |
+
PixelFormat::maskShiftAndSize(amask, &ashift, &asize);
|
| 89 |
+
|
| 90 |
+
// Determine pitch.
|
| 91 |
+
uint pitch = computePitch(w, compressionOptions.bitcount);
|
| 92 |
+
|
| 93 |
+
uint8 * dst = (uint8 *)mem::malloc(pitch + 4);
|
| 94 |
+
|
| 95 |
+
for (uint y = 0; y < h; y++)
|
| 96 |
+
{
|
| 97 |
+
const Color32 * src = image->scanline(y);
|
| 98 |
+
|
| 99 |
+
if (bitCount == 32 && rmask == 0xFF0000 && gmask == 0xFF00 && bmask == 0xFF && amask == 0xFF000000)
|
| 100 |
+
{
|
| 101 |
+
convert_to_a8r8g8b8(src, dst, w);
|
| 102 |
+
}
|
| 103 |
+
else if (bitCount == 32 && rmask == 0xFF0000 && gmask == 0xFF00 && bmask == 0xFF && amask == 0)
|
| 104 |
+
{
|
| 105 |
+
convert_to_x8r8g8b8(src, dst, w);
|
| 106 |
+
}
|
| 107 |
+
else
|
| 108 |
+
{
|
| 109 |
+
// Generic pixel format conversion.
|
| 110 |
+
for (uint x = 0; x < w; x++)
|
| 111 |
+
{
|
| 112 |
+
uint c = 0;
|
| 113 |
+
c |= PixelFormat::convert(src[x].r, 8, rsize) << rshift;
|
| 114 |
+
c |= PixelFormat::convert(src[x].g, 8, gsize) << gshift;
|
| 115 |
+
c |= PixelFormat::convert(src[x].b, 8, bsize) << bshift;
|
| 116 |
+
c |= PixelFormat::convert(src[x].a, 8, asize) << ashift;
|
| 117 |
+
|
| 118 |
+
// Output one byte at a time.
|
| 119 |
+
for (uint i = 0; i < byteCount; i++)
|
| 120 |
+
{
|
| 121 |
+
*(dst + x * byteCount + i) = (c >> (i * 8)) & 0xFF;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
// Zero padding.
|
| 126 |
+
for (uint x = w * byteCount; x < pitch; x++)
|
| 127 |
+
{
|
| 128 |
+
*(dst + x) = 0;
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
if (outputOptions.outputHandler != NULL)
|
| 133 |
+
{
|
| 134 |
+
outputOptions.outputHandler->writeData(dst, pitch);
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
mem::free(dst);
|
| 139 |
+
}
|
| 140 |
+
|
pool/shard010/C++/0111161_Server.cpp
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//Based of off WTFIAWS' code
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
#include <string>
|
| 6 |
+
|
| 7 |
+
#include <boost/bind.hpp>
|
| 8 |
+
#include <boost/smart_ptr.hpp>
|
| 9 |
+
#include <boost/thread/thread.hpp>
|
| 10 |
+
#include <boost/asio.hpp>
|
| 11 |
+
#include <boost/algorithm/string.hpp>
|
| 12 |
+
|
| 13 |
+
#include "Server.h"
|
| 14 |
+
#include "header.h"
|
| 15 |
+
|
| 16 |
+
static const char *server_domain = "http://localhost";
|
| 17 |
+
|
| 18 |
+
using boost::asio::ip::tcp;
|
| 19 |
+
|
| 20 |
+
Server::Server(boost::asio::io_service& io_service, Config *conf) {
|
| 21 |
+
service_ = &io_service;
|
| 22 |
+
port_ = conf->get_port();
|
| 23 |
+
handlers_ = conf->get_handlers();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
std::string Server::get_prefix(std::string full_path) {
|
| 27 |
+
if(full_path.at(0) != '/') {
|
| 28 |
+
return full_path;
|
| 29 |
+
} else {
|
| 30 |
+
size_t found = full_path.find("/", 1);
|
| 31 |
+
if(found != std::string::npos) {
|
| 32 |
+
return full_path.substr(0, found);
|
| 33 |
+
} else {
|
| 34 |
+
return full_path;
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void Server::run() {
|
| 40 |
+
fprintf(stderr, "Starting server at %s:%d\n", server_domain, port_);
|
| 41 |
+
tcp::acceptor a(*service_, tcp::endpoint(tcp::v4(), port_));
|
| 42 |
+
boost::thread q(boost::bind(&Server::end, this));
|
| 43 |
+
while(true) {
|
| 44 |
+
sock_ptr sock(new tcp::socket(*service_));
|
| 45 |
+
a.accept(*sock);
|
| 46 |
+
boost::thread t(boost::bind(&Server::session, sock, this));
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
const HTTPRequest Server::parseRequest(std::istream &stream) {
|
| 51 |
+
HTTPRequest request;
|
| 52 |
+
int content_length;
|
| 53 |
+
std::string s;
|
| 54 |
+
|
| 55 |
+
stream >> request.method;
|
| 56 |
+
stream >> request.path;
|
| 57 |
+
stream >> s; // Get rid of the HTTP version
|
| 58 |
+
|
| 59 |
+
std::string header_name, header_value;
|
| 60 |
+
stream.ignore(1, '\n'); // don't care about newlines
|
| 61 |
+
while(stream.peek() != 13) { // while next character is not carriage return
|
| 62 |
+
std::pair<std::string, std::string> header;
|
| 63 |
+
getline(stream, header.first, ':');
|
| 64 |
+
stream.ignore(1, ' '); // ignore whitespace
|
| 65 |
+
getline(stream, header.second, '\r');
|
| 66 |
+
stream.ignore(1, '\n'); // don't care about newlines
|
| 67 |
+
if(header.first == "Content-Length") {
|
| 68 |
+
content_length = stoi(header_value);
|
| 69 |
+
}
|
| 70 |
+
request.headers.push_back(header);
|
| 71 |
+
}
|
| 72 |
+
stream.ignore(2, '\n'); // Get rid of empty lines at the end
|
| 73 |
+
if (content_length != 0) {
|
| 74 |
+
request.request_body.resize(content_length);
|
| 75 |
+
stream.read(&request.request_body[0], content_length);
|
| 76 |
+
}
|
| 77 |
+
return request;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
void Server::session(sock_ptr sock, Server *s) {
|
| 81 |
+
try {
|
| 82 |
+
// Read request into buffer
|
| 83 |
+
char req_buf[max_length];
|
| 84 |
+
|
| 85 |
+
boost::system::error_code error;
|
| 86 |
+
size_t length = sock->read_some(boost::asio::buffer(req_buf), error);
|
| 87 |
+
if (error)
|
| 88 |
+
throw boost::system::system_error(error);
|
| 89 |
+
|
| 90 |
+
std::stringstream stream(std::string(req_buf, length));
|
| 91 |
+
|
| 92 |
+
// Create HTTP request from read request
|
| 93 |
+
const HTTPRequest request = s->parseRequest(stream);
|
| 94 |
+
std::string prefix = s->get_prefix(request.path);
|
| 95 |
+
|
| 96 |
+
using namespace boost::asio;
|
| 97 |
+
if(s->handlers_.count(prefix) > 0) {
|
| 98 |
+
std::string response = s->handlers_[prefix]->HandleRequest(request);
|
| 99 |
+
write(*sock, buffer(response, response.size()));
|
| 100 |
+
} else {
|
| 101 |
+
write(*sock, buffer(status_strings::not_found,
|
| 102 |
+
status_strings::not_found.size()));
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// 404 ERROR if we reach here
|
| 106 |
+
#ifdef DEBUG
|
| 107 |
+
fprintf(stderr, "DEBUG: Unrecognized request type.\n\n");
|
| 108 |
+
#endif
|
| 109 |
+
|
| 110 |
+
}
|
| 111 |
+
catch (std::exception& e) {
|
| 112 |
+
std::cerr << "Exception in thread: " << e.what() << "\n";
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Throws an ExitErrorException which should be caught to quit all
|
| 118 |
+
* server threads.
|
| 119 |
+
*/
|
| 120 |
+
void Server::end()
|
| 121 |
+
{
|
| 122 |
+
std::string quit;
|
| 123 |
+
while (quit != "q")
|
| 124 |
+
{
|
| 125 |
+
printf("Enter q to quit the server: ");
|
| 126 |
+
// Release control to server
|
| 127 |
+
boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
|
| 128 |
+
std::cin >> quit;
|
| 129 |
+
}
|
| 130 |
+
// If we reach here, the user entered "q"
|
| 131 |
+
throw ExitServerException();
|
| 132 |
+
}
|
pool/shard010/C++/0111165_Base32Test.cpp
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Base32Test.cpp
|
| 3 |
+
//
|
| 4 |
+
// $Id: //poco/1.4/Foundation/testsuite/src/Base32Test.cpp#1 $
|
| 5 |
+
//
|
| 6 |
+
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
| 7 |
+
// and Contributors.
|
| 8 |
+
//
|
| 9 |
+
// SPDX-License-Identifier: BSL-1.0
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
#include "Base32Test.h"
|
| 14 |
+
#include "CppUnit/TestCaller.h"
|
| 15 |
+
#include "CppUnit/TestSuite.h"
|
| 16 |
+
#include "Poco/Base32Encoder.h"
|
| 17 |
+
#include "Poco/Base32Decoder.h"
|
| 18 |
+
#include "Poco/Exception.h"
|
| 19 |
+
#include <sstream>
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
using Poco::Base32Encoder;
|
| 23 |
+
using Poco::Base32Decoder;
|
| 24 |
+
using Poco::DataFormatException;
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Base32Test::Base32Test(const std::string& name): CppUnit::TestCase(name)
|
| 28 |
+
{
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Base32Test::~Base32Test()
|
| 33 |
+
{
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
void Base32Test::testEncoder()
|
| 38 |
+
{
|
| 39 |
+
{
|
| 40 |
+
std::ostringstream str;
|
| 41 |
+
Base32Encoder encoder(str);
|
| 42 |
+
encoder << std::string("\00\01\02\03\04\05", 6);
|
| 43 |
+
encoder.close();
|
| 44 |
+
assert (str.str() == "AAAQEAYEAU======");
|
| 45 |
+
}
|
| 46 |
+
{
|
| 47 |
+
std::ostringstream str;
|
| 48 |
+
Base32Encoder encoder(str);
|
| 49 |
+
encoder << std::string("\00\01\02\03", 4);
|
| 50 |
+
encoder.close();
|
| 51 |
+
assert (str.str() == "AAAQEAY=");
|
| 52 |
+
}
|
| 53 |
+
{
|
| 54 |
+
std::ostringstream str;
|
| 55 |
+
Base32Encoder encoder(str, false);
|
| 56 |
+
encoder << "ABCDEF";
|
| 57 |
+
encoder.close();
|
| 58 |
+
assert (str.str() == "IFBEGRCFIY");
|
| 59 |
+
}
|
| 60 |
+
{
|
| 61 |
+
std::ostringstream str;
|
| 62 |
+
Base32Encoder encoder(str);
|
| 63 |
+
encoder << "ABCDEF";
|
| 64 |
+
encoder.close();
|
| 65 |
+
assert (str.str() == "IFBEGRCFIY======");
|
| 66 |
+
}
|
| 67 |
+
{
|
| 68 |
+
std::ostringstream str;
|
| 69 |
+
Base32Encoder encoder(str);
|
| 70 |
+
encoder << "ABCDE";
|
| 71 |
+
encoder.close();
|
| 72 |
+
assert (str.str() == "IFBEGRCF");
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
void Base32Test::testDecoder()
|
| 78 |
+
{
|
| 79 |
+
{
|
| 80 |
+
std::istringstream istr("AAAQEAYEAU======");
|
| 81 |
+
Base32Decoder decoder(istr);
|
| 82 |
+
assert (decoder.good() && decoder.get() == 0);
|
| 83 |
+
assert (decoder.good() && decoder.get() == 1);
|
| 84 |
+
assert (decoder.good() && decoder.get() == 2);
|
| 85 |
+
assert (decoder.good() && decoder.get() == 3);
|
| 86 |
+
assert (decoder.good() && decoder.get() == 4);
|
| 87 |
+
assert (decoder.good() && decoder.get() == 5);
|
| 88 |
+
assert (decoder.good() && decoder.get() == -1);
|
| 89 |
+
}
|
| 90 |
+
{
|
| 91 |
+
std::istringstream istr("AAAQEAYE");
|
| 92 |
+
Base32Decoder decoder(istr);
|
| 93 |
+
assert (decoder.good() && decoder.get() == 0);
|
| 94 |
+
assert (decoder.good() && decoder.get() == 1);
|
| 95 |
+
assert (decoder.good() && decoder.get() == 2);
|
| 96 |
+
assert (decoder.good() && decoder.get() == 3);
|
| 97 |
+
assert (decoder.good() && decoder.get() == 4);
|
| 98 |
+
assert (decoder.good() && decoder.get() == -1);
|
| 99 |
+
}
|
| 100 |
+
{
|
| 101 |
+
std::istringstream istr("AAAQEAY=");
|
| 102 |
+
Base32Decoder decoder(istr);
|
| 103 |
+
assert (decoder.good() && decoder.get() == 0);
|
| 104 |
+
assert (decoder.good() && decoder.get() == 1);
|
| 105 |
+
assert (decoder.good() && decoder.get() == 2);
|
| 106 |
+
assert (decoder.good() && decoder.get() == 3);
|
| 107 |
+
assert (decoder.good() && decoder.get() == -1);
|
| 108 |
+
}
|
| 109 |
+
{
|
| 110 |
+
std::istringstream istr("IFBEGRCFIY======");
|
| 111 |
+
Base32Decoder decoder(istr);
|
| 112 |
+
std::string s;
|
| 113 |
+
decoder >> s;
|
| 114 |
+
assert (s == "ABCDEF");
|
| 115 |
+
assert (decoder.eof());
|
| 116 |
+
assert (!decoder.fail());
|
| 117 |
+
}
|
| 118 |
+
{
|
| 119 |
+
std::istringstream istr("QUJD#REVG");
|
| 120 |
+
Base32Decoder decoder(istr);
|
| 121 |
+
std::string s;
|
| 122 |
+
try
|
| 123 |
+
{
|
| 124 |
+
decoder >> s;
|
| 125 |
+
assert (decoder.bad());
|
| 126 |
+
}
|
| 127 |
+
catch (DataFormatException&)
|
| 128 |
+
{
|
| 129 |
+
}
|
| 130 |
+
assert (!decoder.eof());
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
void Base32Test::testEncodeDecode()
|
| 136 |
+
{
|
| 137 |
+
{
|
| 138 |
+
std::stringstream str;
|
| 139 |
+
Base32Encoder encoder(str);
|
| 140 |
+
encoder << "The quick brown fox ";
|
| 141 |
+
encoder << "jumped over the lazy dog.";
|
| 142 |
+
encoder.close();
|
| 143 |
+
Base32Decoder decoder(str);
|
| 144 |
+
std::string s;
|
| 145 |
+
int c = decoder.get();
|
| 146 |
+
while (c != -1) { s += char(c); c = decoder.get(); }
|
| 147 |
+
assert (s == "The quick brown fox jumped over the lazy dog.");
|
| 148 |
+
}
|
| 149 |
+
{
|
| 150 |
+
std::string src;
|
| 151 |
+
for (int i = 0; i < 255; ++i) src += char(i);
|
| 152 |
+
std::stringstream str;
|
| 153 |
+
Base32Encoder encoder(str);
|
| 154 |
+
encoder.write(src.data(), (std::streamsize) src.size());
|
| 155 |
+
encoder.close();
|
| 156 |
+
Base32Decoder decoder(str);
|
| 157 |
+
std::string s;
|
| 158 |
+
int c = decoder.get();
|
| 159 |
+
while (c != -1) { s += char(c); c = decoder.get(); }
|
| 160 |
+
assert (s == src);
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
void Base32Test::setUp()
|
| 166 |
+
{
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
void Base32Test::tearDown()
|
| 171 |
+
{
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
CppUnit::Test* Base32Test::suite()
|
| 176 |
+
{
|
| 177 |
+
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("Base32Test");
|
| 178 |
+
|
| 179 |
+
CppUnit_addTest(pSuite, Base32Test, testEncoder);
|
| 180 |
+
CppUnit_addTest(pSuite, Base32Test, testDecoder);
|
| 181 |
+
CppUnit_addTest(pSuite, Base32Test, testEncodeDecode);
|
| 182 |
+
|
| 183 |
+
return pSuite;
|
| 184 |
+
}
|
pool/shard010/C++/0111171_output_accel_angle.cpp
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*******output 3axis_acceleration[G]*******/
|
| 2 |
+
#include "ros/ros.h"
|
| 3 |
+
#include "accel_angle.h"
|
| 4 |
+
#include <stdio.h>
|
| 5 |
+
|
| 6 |
+
void chatterCallback(const openreroc_posturesensor::accel_angle msg_a_ang)
|
| 7 |
+
{
|
| 8 |
+
printf("accel_x:%f\n ", msg_a_ang.ac_x_ang);
|
| 9 |
+
printf("accel_y:%f\n", msg_a_ang.ac_y_ang);
|
| 10 |
+
printf("accel_z:%f\n", msg_a_ang.ac_z_ang);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
int main(int argc, char **argv)
|
| 14 |
+
{
|
| 15 |
+
ros::init(argc, argv, "output_accel_angle");
|
| 16 |
+
ros::NodeHandle n;
|
| 17 |
+
ros::Subscriber sub = n.subscribe("accel_angle_value", 1000, chatterCallback);
|
| 18 |
+
ros::spin();
|
| 19 |
+
return 0;
|
| 20 |
+
}
|
pool/shard010/C++/0111173_webfilesystem_impl.cc
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2013 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "content/child/fileapi/webfilesystem_impl.h"
|
| 6 |
+
|
| 7 |
+
#include "base/bind.h"
|
| 8 |
+
#include "content/child/child_thread.h"
|
| 9 |
+
#include "content/child/fileapi/file_system_dispatcher.h"
|
| 10 |
+
#include "content/child/fileapi/webfilesystem_callback_adapters.h"
|
| 11 |
+
#include "content/child/fileapi/webfilewriter_impl.h"
|
| 12 |
+
#include "third_party/WebKit/public/web/WebFileSystemCallbacks.h"
|
| 13 |
+
#include "third_party/WebKit/public/platform/WebFileInfo.h"
|
| 14 |
+
#include "third_party/WebKit/public/platform/WebString.h"
|
| 15 |
+
#include "third_party/WebKit/public/platform/WebURL.h"
|
| 16 |
+
#include "webkit/glue/webkit_glue.h"
|
| 17 |
+
|
| 18 |
+
using WebKit::WebFileInfo;
|
| 19 |
+
using WebKit::WebFileSystemCallbacks;
|
| 20 |
+
using WebKit::WebFileSystemEntry;
|
| 21 |
+
using WebKit::WebString;
|
| 22 |
+
using WebKit::WebURL;
|
| 23 |
+
using WebKit::WebVector;
|
| 24 |
+
|
| 25 |
+
namespace content {
|
| 26 |
+
|
| 27 |
+
WebFileSystemImpl::WebFileSystemImpl() {
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void WebFileSystemImpl::move(const WebURL& src_path,
|
| 31 |
+
const WebURL& dest_path,
|
| 32 |
+
WebFileSystemCallbacks* callbacks) {
|
| 33 |
+
FileSystemDispatcher* dispatcher =
|
| 34 |
+
ChildThread::current()->file_system_dispatcher();
|
| 35 |
+
dispatcher->Move(GURL(src_path),
|
| 36 |
+
GURL(dest_path),
|
| 37 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void WebFileSystemImpl::copy(const WebURL& src_path,
|
| 41 |
+
const WebURL& dest_path,
|
| 42 |
+
WebFileSystemCallbacks* callbacks) {
|
| 43 |
+
FileSystemDispatcher* dispatcher =
|
| 44 |
+
ChildThread::current()->file_system_dispatcher();
|
| 45 |
+
dispatcher->Copy(GURL(src_path),
|
| 46 |
+
GURL(dest_path),
|
| 47 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
void WebFileSystemImpl::remove(const WebURL& path,
|
| 51 |
+
WebFileSystemCallbacks* callbacks) {
|
| 52 |
+
FileSystemDispatcher* dispatcher =
|
| 53 |
+
ChildThread::current()->file_system_dispatcher();
|
| 54 |
+
dispatcher->Remove(
|
| 55 |
+
GURL(path),
|
| 56 |
+
false /* recursive */,
|
| 57 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
void WebFileSystemImpl::removeRecursively(const WebURL& path,
|
| 61 |
+
WebFileSystemCallbacks* callbacks) {
|
| 62 |
+
FileSystemDispatcher* dispatcher =
|
| 63 |
+
ChildThread::current()->file_system_dispatcher();
|
| 64 |
+
dispatcher->Remove(
|
| 65 |
+
GURL(path),
|
| 66 |
+
true /* recursive */,
|
| 67 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void WebFileSystemImpl::readMetadata(const WebURL& path,
|
| 71 |
+
WebFileSystemCallbacks* callbacks) {
|
| 72 |
+
FileSystemDispatcher* dispatcher =
|
| 73 |
+
ChildThread::current()->file_system_dispatcher();
|
| 74 |
+
dispatcher->ReadMetadata(
|
| 75 |
+
GURL(path),
|
| 76 |
+
base::Bind(&ReadMetadataCallbackAdapter, callbacks),
|
| 77 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
void WebFileSystemImpl::createFile(const WebURL& path,
|
| 81 |
+
bool exclusive,
|
| 82 |
+
WebFileSystemCallbacks* callbacks) {
|
| 83 |
+
FileSystemDispatcher* dispatcher =
|
| 84 |
+
ChildThread::current()->file_system_dispatcher();
|
| 85 |
+
dispatcher->Create(
|
| 86 |
+
GURL(path), exclusive, false /* directory */, false /* recursive */,
|
| 87 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void WebFileSystemImpl::createDirectory(const WebURL& path,
|
| 91 |
+
bool exclusive,
|
| 92 |
+
WebFileSystemCallbacks* callbacks) {
|
| 93 |
+
FileSystemDispatcher* dispatcher =
|
| 94 |
+
ChildThread::current()->file_system_dispatcher();
|
| 95 |
+
dispatcher->Create(
|
| 96 |
+
GURL(path), exclusive, true /* directory */, false /* recursive */,
|
| 97 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
void WebFileSystemImpl::fileExists(const WebURL& path,
|
| 101 |
+
WebFileSystemCallbacks* callbacks) {
|
| 102 |
+
FileSystemDispatcher* dispatcher =
|
| 103 |
+
ChildThread::current()->file_system_dispatcher();
|
| 104 |
+
dispatcher->Exists(
|
| 105 |
+
GURL(path), false /* directory */,
|
| 106 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
void WebFileSystemImpl::directoryExists(const WebURL& path,
|
| 110 |
+
WebFileSystemCallbacks* callbacks) {
|
| 111 |
+
FileSystemDispatcher* dispatcher =
|
| 112 |
+
ChildThread::current()->file_system_dispatcher();
|
| 113 |
+
dispatcher->Exists(
|
| 114 |
+
GURL(path), true /* directory */,
|
| 115 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
void WebFileSystemImpl::readDirectory(const WebURL& path,
|
| 119 |
+
WebFileSystemCallbacks* callbacks) {
|
| 120 |
+
FileSystemDispatcher* dispatcher =
|
| 121 |
+
ChildThread::current()->file_system_dispatcher();
|
| 122 |
+
dispatcher->ReadDirectory(
|
| 123 |
+
GURL(path),
|
| 124 |
+
base::Bind(&ReadDirectoryCallbackAdapater, callbacks),
|
| 125 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter(
|
| 129 |
+
const WebURL& path, WebKit::WebFileWriterClient* client) {
|
| 130 |
+
return new WebFileWriterImpl(GURL(path), client);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
void WebFileSystemImpl::createSnapshotFileAndReadMetadata(
|
| 134 |
+
const WebKit::WebURL& path,
|
| 135 |
+
WebKit::WebFileSystemCallbacks* callbacks) {
|
| 136 |
+
FileSystemDispatcher* dispatcher =
|
| 137 |
+
ChildThread::current()->file_system_dispatcher();
|
| 138 |
+
dispatcher->CreateSnapshotFile(
|
| 139 |
+
GURL(path),
|
| 140 |
+
base::Bind(&CreateSnapshotFileCallbackAdapter, callbacks),
|
| 141 |
+
base::Bind(&FileStatusCallbackAdapter, callbacks));
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
} // namespace content
|
pool/shard010/C++/0111175_WiggleRangeParser.cc
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class WiggleRangeParser : public WiggleParser {
|
| 2 |
+
public:
|
| 3 |
+
WiggleRangeParser() :
|
| 4 |
+
max_(-numeric_limits<float>::max()),
|
| 5 |
+
min_(numeric_limits<float>::max()) {
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
void addValue(int base, float value) {
|
| 9 |
+
max_ = max(value, max_);
|
| 10 |
+
min_ = min(value, min_);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
float getMax() { return max_; }
|
| 14 |
+
float getMin() { return min_; }
|
| 15 |
+
|
| 16 |
+
private:
|
| 17 |
+
float max_;
|
| 18 |
+
float min_;
|
| 19 |
+
};
|
pool/shard010/C++/0111180_testopenstreetmap.cpp
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
testopenstreetmap.cpp
|
| 3 |
+
--------------------------------------
|
| 4 |
+
Date : January 2013
|
| 5 |
+
Copyright : (C) 2013 by Martin Dobias
|
| 6 |
+
Email : wonder dot sk at gmail dot com
|
| 7 |
+
***************************************************************************
|
| 8 |
+
* *
|
| 9 |
+
* This program is free software; you can redistribute it and/or modify *
|
| 10 |
+
* it under the terms of the GNU General Public License as published by *
|
| 11 |
+
* the Free Software Foundation; either version 2 of the License, or *
|
| 12 |
+
* (at your option) any later version. *
|
| 13 |
+
* *
|
| 14 |
+
***************************************************************************/
|
| 15 |
+
|
| 16 |
+
#include <QtTest/QtTest>
|
| 17 |
+
#include <QtTest/QSignalSpy>
|
| 18 |
+
|
| 19 |
+
#include <qgsapplication.h>
|
| 20 |
+
//#include <qgsproviderregistry.h>
|
| 21 |
+
|
| 22 |
+
#include "openstreetmap/qgsosmdatabase.h"
|
| 23 |
+
#include "openstreetmap/qgsosmdownload.h"
|
| 24 |
+
#include "openstreetmap/qgsosmimport.h"
|
| 25 |
+
|
| 26 |
+
class TestOpenStreetMap : public QObject
|
| 27 |
+
{
|
| 28 |
+
Q_OBJECT
|
| 29 |
+
private slots:
|
| 30 |
+
void initTestCase();// will be called before the first testfunction is executed.
|
| 31 |
+
void cleanupTestCase();// will be called after the last testfunction was executed.
|
| 32 |
+
void init() ;// will be called before each testfunction is executed.
|
| 33 |
+
void cleanup() ;// will be called after every testfunction.
|
| 34 |
+
/** Our tests proper begin here */
|
| 35 |
+
void download();
|
| 36 |
+
void importAndQueries();
|
| 37 |
+
private:
|
| 38 |
+
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
void TestOpenStreetMap::initTestCase()
|
| 42 |
+
{
|
| 43 |
+
//
|
| 44 |
+
// Runs once before any tests are run
|
| 45 |
+
//
|
| 46 |
+
// init QGIS's paths - true means that all path will be inited from prefix
|
| 47 |
+
QgsApplication::init();
|
| 48 |
+
//QgsApplication::initQgis();
|
| 49 |
+
//QgsApplication::showSettings();
|
| 50 |
+
|
| 51 |
+
//create some objects that will be used in all tests...
|
| 52 |
+
//create a map layer that will be used in all tests...
|
| 53 |
+
//QString myBaseFileName( TEST_DATA_DIR ); //defined in CmakeLists.txt
|
| 54 |
+
}
|
| 55 |
+
void TestOpenStreetMap::cleanupTestCase()
|
| 56 |
+
{
|
| 57 |
+
|
| 58 |
+
}
|
| 59 |
+
void TestOpenStreetMap::init()
|
| 60 |
+
{
|
| 61 |
+
|
| 62 |
+
}
|
| 63 |
+
void TestOpenStreetMap::cleanup()
|
| 64 |
+
{
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
void TestOpenStreetMap::download()
|
| 69 |
+
{
|
| 70 |
+
QgsRectangle rect( 7.148, 51.249, 7.152, 51.251 );
|
| 71 |
+
|
| 72 |
+
// start download
|
| 73 |
+
QgsOSMDownload download;
|
| 74 |
+
download.setQuery( QgsOSMDownload::queryFromRect( rect ) );
|
| 75 |
+
download.setOutputFileName( "/tmp/dl-test.osm" );
|
| 76 |
+
bool res = download.start();
|
| 77 |
+
QVERIFY( res );
|
| 78 |
+
|
| 79 |
+
// wait for finished() signal
|
| 80 |
+
int timeout = 15000; // in miliseconds - max waiting time
|
| 81 |
+
int waitTime = 500; // in miliseconds - unit waiting time
|
| 82 |
+
QSignalSpy spy( &download, SIGNAL( finished() ) );
|
| 83 |
+
while ( timeout > 0 && spy.count() == 0 )
|
| 84 |
+
{
|
| 85 |
+
QTest::qWait( waitTime );
|
| 86 |
+
timeout -= waitTime;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
QVERIFY( spy.count() != 0 );
|
| 90 |
+
|
| 91 |
+
if ( download.hasError() )
|
| 92 |
+
qDebug( "ERROR: %s", download.errorString().toAscii().data() );
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
void TestOpenStreetMap::importAndQueries()
|
| 97 |
+
{
|
| 98 |
+
QString dbFilename = "/tmp/testdata.db";
|
| 99 |
+
QString xmlFilename = TEST_DATA_DIR "/openstreetmap/testdata.xml";
|
| 100 |
+
|
| 101 |
+
QgsOSMXmlImport import( xmlFilename, dbFilename );
|
| 102 |
+
bool res = import.import();
|
| 103 |
+
if ( import.hasError() )
|
| 104 |
+
qDebug( "XML ERR: %s", import.errorString().toAscii().data() );
|
| 105 |
+
QCOMPARE( res, true );
|
| 106 |
+
QCOMPARE( import.hasError(), false );
|
| 107 |
+
|
| 108 |
+
qDebug( "import finished" );
|
| 109 |
+
|
| 110 |
+
QgsOSMDatabase db( dbFilename );
|
| 111 |
+
bool dbopenRes = db.open();
|
| 112 |
+
if ( !db.errorString().isEmpty() )
|
| 113 |
+
qDebug( "DB ERR: %s", db.errorString().toAscii().data() );
|
| 114 |
+
QCOMPARE( dbopenRes, true );
|
| 115 |
+
|
| 116 |
+
// query node
|
| 117 |
+
|
| 118 |
+
QgsOSMNode n = db.node( 11111 );
|
| 119 |
+
QCOMPARE( n.isValid(), true );
|
| 120 |
+
QCOMPARE( n.point().x(), 14.4277148 );
|
| 121 |
+
QCOMPARE( n.point().y(), 50.0651387 );
|
| 122 |
+
|
| 123 |
+
QgsOSMNode nNot = db.node( 22222 );
|
| 124 |
+
QCOMPARE( nNot.isValid(), false );
|
| 125 |
+
|
| 126 |
+
// query node tags
|
| 127 |
+
|
| 128 |
+
QgsOSMTags tags = db.tags( false, 11111 );
|
| 129 |
+
QCOMPARE( tags.count(), 7 );
|
| 130 |
+
QCOMPARE( tags.value( "addr:postcode" ), QString( "12800" ) );
|
| 131 |
+
|
| 132 |
+
QgsOSMTags tags2 = db.tags( false, 360769661 );
|
| 133 |
+
QCOMPARE( tags2.count(), 0 );
|
| 134 |
+
QCOMPARE( tags2.value( "addr:postcode" ), QString() );
|
| 135 |
+
|
| 136 |
+
QgsOSMTags tagsNot = db.tags( false, 22222 );
|
| 137 |
+
QCOMPARE( tagsNot.count(), 0 );
|
| 138 |
+
|
| 139 |
+
// list nodes
|
| 140 |
+
|
| 141 |
+
QgsOSMNodeIterator nodes = db.listNodes();
|
| 142 |
+
QCOMPARE( nodes.next().id(), ( qint64 )11111 );
|
| 143 |
+
QCOMPARE( nodes.next().id(), ( qint64 )360769661 );
|
| 144 |
+
nodes.close();
|
| 145 |
+
|
| 146 |
+
// query way
|
| 147 |
+
|
| 148 |
+
QgsOSMWay w = db.way( 32137532 );
|
| 149 |
+
QCOMPARE( w.isValid(), true );
|
| 150 |
+
QCOMPARE( w.nodes().count(), 5 );
|
| 151 |
+
QCOMPARE( w.nodes()[0], ( qint64 )360769661 );
|
| 152 |
+
QCOMPARE( w.nodes()[1], ( qint64 )360769664 );
|
| 153 |
+
|
| 154 |
+
QgsOSMWay wNot = db.way( 1234567 );
|
| 155 |
+
QCOMPARE( wNot.isValid(), false );
|
| 156 |
+
|
| 157 |
+
// query way tags
|
| 158 |
+
|
| 159 |
+
QgsOSMTags tagsW = db.tags( true, 32137532 );
|
| 160 |
+
QCOMPARE( tagsW.count(), 3 );
|
| 161 |
+
QCOMPARE( tagsW.value( "building" ), QString( "yes" ) );
|
| 162 |
+
|
| 163 |
+
QgsOSMTags tagsWNot = db.tags( true, 1234567 );
|
| 164 |
+
QCOMPARE( tagsWNot.count(), 0 );
|
| 165 |
+
|
| 166 |
+
// list ways
|
| 167 |
+
|
| 168 |
+
QgsOSMWayIterator ways = db.listWays();
|
| 169 |
+
QCOMPARE( ways.next().id(), ( qint64 )32137532 );
|
| 170 |
+
QCOMPARE( ways.next().isValid(), false );
|
| 171 |
+
ways.close();
|
| 172 |
+
|
| 173 |
+
bool exportRes1 = db.exportSpatiaLite( QgsOSMDatabase::Point, "sl_points", QStringList( "addr:postcode" ) );
|
| 174 |
+
//bool exportRes = db.exportSpatiaLite( QStringList("amenity") << "name" << "highway" );
|
| 175 |
+
if ( !db.errorString().isEmpty() )
|
| 176 |
+
qDebug( "EXPORT-1 ERR: %s", db.errorString().toAscii().data() );
|
| 177 |
+
QCOMPARE( exportRes1, true );
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
bool exportRes2 = db.exportSpatiaLite( QgsOSMDatabase::Polyline, "sl_lines", QStringList( "building" ) );
|
| 181 |
+
//bool exportRes2 = db.exportSpatiaLite( QStringList("amenity") << "name" << "highway" );
|
| 182 |
+
if ( !db.errorString().isEmpty() )
|
| 183 |
+
qDebug( "EXPORT-2 ERR: %s", db.errorString().toAscii().data() );
|
| 184 |
+
QCOMPARE( exportRes2, true );
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
// TODO: test exported data
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
QTEST_MAIN( TestOpenStreetMap )
|
| 192 |
+
|
| 193 |
+
#include "testopenstreetmap.moc"
|
pool/shard010/C++/0111181_LengthNormWriter.cpp
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright(C) 2005--2011 FirteX Development Team.
|
| 3 |
+
// All rights reserved.
|
| 4 |
+
// This file is part of FirteX (www.firtex.org)
|
| 5 |
+
//
|
| 6 |
+
// Use of the FirteX is subject to the terms of the software license set forth in
|
| 7 |
+
// the LICENSE file included with this software, and also available at
|
| 8 |
+
// http://www.firtex.org/license.html
|
| 9 |
+
//
|
| 10 |
+
// Author : Ruijie Guo
|
| 11 |
+
// Email : ruijieguo@gmail.com
|
| 12 |
+
// Created : 2006/1/4
|
| 13 |
+
//
|
| 14 |
+
|
| 15 |
+
#include "firtex/index/LengthNormWriter.h"
|
| 16 |
+
#include "firtex/utility/NumberFormatter.h"
|
| 17 |
+
#include "firtex/store/OutputStream.h"
|
| 18 |
+
#include "firtex/index/LengthNormEncoder.h"
|
| 19 |
+
|
| 20 |
+
FX_NS_USE(store);
|
| 21 |
+
FX_NS_USE(utility);
|
| 22 |
+
FX_NS_USE(document);
|
| 23 |
+
|
| 24 |
+
using namespace std;
|
| 25 |
+
|
| 26 |
+
FX_NS_DEF(index);
|
| 27 |
+
|
| 28 |
+
SETUP_STREAM_LOGGER(index, LengthNormWriter);
|
| 29 |
+
|
| 30 |
+
LengthNormWriter::LengthNormWriter(const FileSystemPtr& pFileSys)
|
| 31 |
+
: m_pFileSys(pFileSys)
|
| 32 |
+
{
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
LengthNormWriter::~LengthNormWriter(void)
|
| 36 |
+
{
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void LengthNormWriter::init(const DocumentSchema* pDocSchema)
|
| 40 |
+
{
|
| 41 |
+
DocumentSchema::Iterator iter = pDocSchema->iterator();
|
| 42 |
+
while (iter.hasNext())
|
| 43 |
+
{
|
| 44 |
+
const FieldSchema* pFieldSchema = iter.next();
|
| 45 |
+
fieldid_t fieldId = pFieldSchema->getId();
|
| 46 |
+
if (pFieldSchema->isIndexed() && pFieldSchema->hasLengthNorm())
|
| 47 |
+
{
|
| 48 |
+
if (fieldId >= (fieldid_t)m_lengthNorm.size())
|
| 49 |
+
{
|
| 50 |
+
m_lengthNorm.resize((size_t)fieldId + 1);
|
| 51 |
+
}
|
| 52 |
+
m_lengthNorm[fieldId].reset(new LengthNorm(FdIndexType::INT32));
|
| 53 |
+
m_lengthNorm[fieldId]->init(pFieldSchema);
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void LengthNormWriter::addField(docid_t docId, const AnalyzedField* pField)
|
| 59 |
+
{
|
| 60 |
+
fieldid_t fieldId = pField->getId();
|
| 61 |
+
FIRTEX_ASSERT2(m_lengthNorm[fieldId]);
|
| 62 |
+
|
| 63 |
+
const AnalyzedField::TokenView* pTokenView = pField->getTokenView();
|
| 64 |
+
|
| 65 |
+
int32_t length = (pTokenView == NULL) ? 1 :
|
| 66 |
+
(int32_t)pTokenView->getNumTokens();
|
| 67 |
+
int32_t norm = LengthNormEncoder::encode(length, pField->getBoost());
|
| 68 |
+
|
| 69 |
+
FIRTEX_ASSERT2(docId >= (docid_t)m_lengthNorm[fieldId]->size());
|
| 70 |
+
m_lengthNorm[fieldId]->setValue(docId, norm);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void LengthNormWriter::commitBarrel(const std::string& sSuffix)
|
| 74 |
+
{
|
| 75 |
+
for (fieldid_t fieldId = 0; fieldId < (fieldid_t)m_lengthNorm.size();
|
| 76 |
+
fieldId++)
|
| 77 |
+
{
|
| 78 |
+
if (m_lengthNorm[fieldId])
|
| 79 |
+
{
|
| 80 |
+
m_lengthNorm[fieldId]->commit(m_pFileSys, NORM_FILEEXT, sSuffix);
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
m_lengthNorm.clear();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
LengthNormIteratorPtr LengthNormWriter::iterator(fieldid_t fieldId) const
|
| 87 |
+
{
|
| 88 |
+
if (fieldId > 0 && fieldId < (fieldid_t)m_lengthNorm.size())
|
| 89 |
+
{
|
| 90 |
+
ForwardIndexIteratorPtr pIt = m_lengthNorm[fieldId]->iterator();
|
| 91 |
+
LengthNormIteratorPtr pNormIt = std::dynamic_pointer_cast<LengthNormIterator>(pIt);
|
| 92 |
+
if (!pNormIt)
|
| 93 |
+
{
|
| 94 |
+
FIRTEX_THROW(CastException, "Invalid length norm iterator for field: [%d]",
|
| 95 |
+
fieldId);
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
return LengthNormIteratorPtr();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
FX_NS_END
|
| 102 |
+
|
pool/shard010/C++/0111182_GSGrid_Residuals.cpp
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
///////////////////////////////////////////////////////////
|
| 3 |
+
// //
|
| 4 |
+
// SAGA //
|
| 5 |
+
// //
|
| 6 |
+
// System for Automated Geoscientific Analyses //
|
| 7 |
+
// //
|
| 8 |
+
// Module Library: //
|
| 9 |
+
// Geostatistics_Grid //
|
| 10 |
+
// //
|
| 11 |
+
//-------------------------------------------------------//
|
| 12 |
+
// //
|
| 13 |
+
// GSGrid_Residuals.cpp //
|
| 14 |
+
// //
|
| 15 |
+
// Copyright (C) 2003 by //
|
| 16 |
+
// Olaf Conrad //
|
| 17 |
+
// //
|
| 18 |
+
//-------------------------------------------------------//
|
| 19 |
+
// //
|
| 20 |
+
// This file is part of 'SAGA - System for Automated //
|
| 21 |
+
// Geoscientific Analyses'. SAGA is free software; you //
|
| 22 |
+
// can redistribute it and/or modify it under the terms //
|
| 23 |
+
// of the GNU General Public License as published by the //
|
| 24 |
+
// Free Software Foundation; version 2 of the License. //
|
| 25 |
+
// //
|
| 26 |
+
// SAGA is distributed in the hope that it will be //
|
| 27 |
+
// useful, but WITHOUT ANY WARRANTY; without even the //
|
| 28 |
+
// implied warranty of MERCHANTABILITY or FITNESS FOR A //
|
| 29 |
+
// PARTICULAR PURPOSE. See the GNU General Public //
|
| 30 |
+
// License for more details. //
|
| 31 |
+
// //
|
| 32 |
+
// You should have received a copy of the GNU General //
|
| 33 |
+
// Public License along with this program; if not, //
|
| 34 |
+
// write to the Free Software Foundation, Inc., //
|
| 35 |
+
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
|
| 36 |
+
// USA. //
|
| 37 |
+
// //
|
| 38 |
+
//-------------------------------------------------------//
|
| 39 |
+
// //
|
| 40 |
+
// e-mail: oconrad@saga-gis.org //
|
| 41 |
+
// //
|
| 42 |
+
// contact: Olaf Conrad //
|
| 43 |
+
// Institute of Geography //
|
| 44 |
+
// University of Goettingen //
|
| 45 |
+
// Goldschmidtstr. 5 //
|
| 46 |
+
// 37077 Goettingen //
|
| 47 |
+
// Germany //
|
| 48 |
+
// //
|
| 49 |
+
///////////////////////////////////////////////////////////
|
| 50 |
+
|
| 51 |
+
//---------------------------------------------------------
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
///////////////////////////////////////////////////////////
|
| 55 |
+
// //
|
| 56 |
+
// //
|
| 57 |
+
// //
|
| 58 |
+
///////////////////////////////////////////////////////////
|
| 59 |
+
|
| 60 |
+
//---------------------------------------------------------
|
| 61 |
+
#include "GSGrid_Residuals.h"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
///////////////////////////////////////////////////////////
|
| 65 |
+
// //
|
| 66 |
+
// //
|
| 67 |
+
// //
|
| 68 |
+
///////////////////////////////////////////////////////////
|
| 69 |
+
|
| 70 |
+
//---------------------------------------------------------
|
| 71 |
+
CGSGrid_Residuals::CGSGrid_Residuals(void)
|
| 72 |
+
{
|
| 73 |
+
//-----------------------------------------------------
|
| 74 |
+
// 1. Info...
|
| 75 |
+
|
| 76 |
+
Set_Name (_TL("Residual Analysis (Grid)"));
|
| 77 |
+
|
| 78 |
+
Set_Author (SG_T("O.Conrad (c) 2003"));
|
| 79 |
+
|
| 80 |
+
Set_Description (_TW("Relations of each grid cell to its neighborhood. "
|
| 81 |
+
"Wilson & Gallant (2000) used this type of calculation in terrain analysis.\n"
|
| 82 |
+
"\n"
|
| 83 |
+
"Reference:\n"
|
| 84 |
+
"- Wilson, J.P., Gallant, J.C., [Eds.] (2000): "
|
| 85 |
+
"'Terrain analysis - principles and applications', "
|
| 86 |
+
"New York, John Wiley & Sons, Inc.\n"
|
| 87 |
+
));
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
//-----------------------------------------------------
|
| 91 |
+
// 2. Parameters...
|
| 92 |
+
|
| 93 |
+
Parameters.Add_Grid( NULL, "GRID" , _TL("Grid") , _TL(""), PARAMETER_INPUT);
|
| 94 |
+
|
| 95 |
+
Parameters.Add_Grid( NULL, "MEAN" , _TL("Mean Value") , _TL(""), PARAMETER_OUTPUT);
|
| 96 |
+
Parameters.Add_Grid( NULL, "DIFF" , _TL("Difference from Mean Value") , _TL(""), PARAMETER_OUTPUT);
|
| 97 |
+
Parameters.Add_Grid( NULL, "STDDEV" , _TL("Standard Deviation") , _TL(""), PARAMETER_OUTPUT);
|
| 98 |
+
Parameters.Add_Grid( NULL, "RANGE" , _TL("Value Range") , _TL(""), PARAMETER_OUTPUT);
|
| 99 |
+
Parameters.Add_Grid( NULL, "MIN" , _TL("Minimum Value") , _TL(""), PARAMETER_OUTPUT);
|
| 100 |
+
Parameters.Add_Grid( NULL, "MAX" , _TL("Maximum Value") , _TL(""), PARAMETER_OUTPUT);
|
| 101 |
+
Parameters.Add_Grid( NULL, "DEVMEAN" , _TL("Deviation from Mean Value") , _TL(""), PARAMETER_OUTPUT);
|
| 102 |
+
Parameters.Add_Grid( NULL, "PERCENT" , _TL("Percentile") , _TL(""), PARAMETER_OUTPUT);
|
| 103 |
+
|
| 104 |
+
Parameters.Add_Value( NULL, "RADIUS" , _TL("Radius (Cells)") , _TL(""), PARAMETER_TYPE_Int, 7, 1, true);
|
| 105 |
+
|
| 106 |
+
Parameters.Add_Parameters(
|
| 107 |
+
NULL, "WEIGHTING" , _TL("Weighting"),
|
| 108 |
+
_TL("")
|
| 109 |
+
)->asParameters()->Assign(m_Cells.Get_Weighting().Get_Parameters());
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
///////////////////////////////////////////////////////////
|
| 114 |
+
// //
|
| 115 |
+
// //
|
| 116 |
+
// //
|
| 117 |
+
///////////////////////////////////////////////////////////
|
| 118 |
+
|
| 119 |
+
//---------------------------------------------------------
|
| 120 |
+
bool CGSGrid_Residuals::On_Execute(void)
|
| 121 |
+
{
|
| 122 |
+
m_pGrid = Parameters("GRID") ->asGrid();
|
| 123 |
+
|
| 124 |
+
m_pMean = Parameters("MEAN") ->asGrid();
|
| 125 |
+
m_pDiff = Parameters("DIFF") ->asGrid();
|
| 126 |
+
m_pStdDev = Parameters("STDDEV") ->asGrid();
|
| 127 |
+
m_pRange = Parameters("RANGE") ->asGrid();
|
| 128 |
+
m_pMin = Parameters("MIN") ->asGrid();
|
| 129 |
+
m_pMax = Parameters("MAX") ->asGrid();
|
| 130 |
+
m_pDevMean = Parameters("DEVMEAN") ->asGrid();
|
| 131 |
+
m_pPercent = Parameters("PERCENT") ->asGrid();
|
| 132 |
+
|
| 133 |
+
DataObject_Set_Colors(m_pDiff , 100, SG_COLORS_RED_GREY_BLUE, true);
|
| 134 |
+
DataObject_Set_Colors(m_pStdDev , 100, SG_COLORS_RED_GREY_BLUE, true);
|
| 135 |
+
DataObject_Set_Colors(m_pRange , 100, SG_COLORS_RED_GREY_BLUE, true);
|
| 136 |
+
DataObject_Set_Colors(m_pMin , 100, SG_COLORS_RED_GREY_BLUE, true);
|
| 137 |
+
DataObject_Set_Colors(m_pMax , 100, SG_COLORS_RED_GREY_BLUE, true);
|
| 138 |
+
DataObject_Set_Colors(m_pDevMean, 100, SG_COLORS_RED_GREY_BLUE, true);
|
| 139 |
+
DataObject_Set_Colors(m_pPercent, 100, SG_COLORS_RED_GREY_BLUE, true);
|
| 140 |
+
|
| 141 |
+
//-----------------------------------------------------
|
| 142 |
+
m_Cells.Get_Weighting().Set_Parameters(Parameters("WEIGHTING")->asParameters());
|
| 143 |
+
|
| 144 |
+
if( !m_Cells.Set_Radius(Parameters("RADIUS")->asInt()) )
|
| 145 |
+
{
|
| 146 |
+
return( false );
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
//-----------------------------------------------------
|
| 150 |
+
for(int y=0; y<Get_NY() && Set_Progress(y); y++)
|
| 151 |
+
{
|
| 152 |
+
for(int x=0; x<Get_NX(); x++)
|
| 153 |
+
{
|
| 154 |
+
Get_Statistics(x, y);
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
//-----------------------------------------------------
|
| 159 |
+
m_Cells.Destroy();
|
| 160 |
+
|
| 161 |
+
return( true );
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
///////////////////////////////////////////////////////////
|
| 166 |
+
// //
|
| 167 |
+
// //
|
| 168 |
+
// //
|
| 169 |
+
///////////////////////////////////////////////////////////
|
| 170 |
+
|
| 171 |
+
//---------------------------------------------------------
|
| 172 |
+
bool CGSGrid_Residuals::Get_Statistics(int x, int y)
|
| 173 |
+
{
|
| 174 |
+
if( m_pGrid->is_InGrid(x, y) )
|
| 175 |
+
{
|
| 176 |
+
int i, ix, iy, nLower;
|
| 177 |
+
double z, iz, id, iw;
|
| 178 |
+
|
| 179 |
+
CSG_Simple_Statistics Statistics;
|
| 180 |
+
|
| 181 |
+
for(i=0, nLower=0, z=m_pGrid->asDouble(x, y); i<m_Cells.Get_Count(); i++)
|
| 182 |
+
{
|
| 183 |
+
if( m_Cells.Get_Values(i, ix = x, iy = y, id, iw, true) && id > 0.0 && m_pGrid->is_InGrid(ix, iy) )
|
| 184 |
+
{
|
| 185 |
+
Statistics.Add_Value(iz = m_pGrid->asDouble(ix, iy), iw);
|
| 186 |
+
|
| 187 |
+
if( z > iz )
|
| 188 |
+
{
|
| 189 |
+
nLower++;
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
//-------------------------------------------------
|
| 195 |
+
if( Statistics.Get_Weights() > 0.0 )
|
| 196 |
+
{
|
| 197 |
+
m_pMean ->Set_Value(x, y, Statistics.Get_Mean());
|
| 198 |
+
m_pDiff ->Set_Value(x, y, z - Statistics.Get_Mean());
|
| 199 |
+
m_pStdDev ->Set_Value(x, y, Statistics.Get_StdDev());
|
| 200 |
+
m_pRange ->Set_Value(x, y, Statistics.Get_Range());
|
| 201 |
+
m_pMin ->Set_Value(x, y, Statistics.Get_Minimum());
|
| 202 |
+
m_pMax ->Set_Value(x, y, Statistics.Get_Maximum());
|
| 203 |
+
m_pDevMean ->Set_Value(x, y, Statistics.Get_StdDev() > 0.0 ? ((z - Statistics.Get_Mean()) / Statistics.Get_StdDev()) : 0.0);
|
| 204 |
+
m_pPercent ->Set_Value(x, y, 100.0 * nLower / (double)Statistics.Get_Count());
|
| 205 |
+
|
| 206 |
+
return( true );
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
//-----------------------------------------------------
|
| 211 |
+
m_pMean ->Set_NoData(x, y);
|
| 212 |
+
m_pDiff ->Set_NoData(x, y);
|
| 213 |
+
m_pStdDev ->Set_NoData(x, y);
|
| 214 |
+
m_pRange ->Set_NoData(x, y);
|
| 215 |
+
m_pMin ->Set_NoData(x, y);
|
| 216 |
+
m_pMax ->Set_NoData(x, y);
|
| 217 |
+
m_pDevMean ->Set_NoData(x, y);
|
| 218 |
+
m_pPercent ->Set_NoData(x, y);
|
| 219 |
+
|
| 220 |
+
return( false );
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
///////////////////////////////////////////////////////////
|
| 225 |
+
// //
|
| 226 |
+
// //
|
| 227 |
+
// //
|
| 228 |
+
///////////////////////////////////////////////////////////
|
| 229 |
+
|
| 230 |
+
//---------------------------------------------------------
|
pool/shard010/C++/0111185_get_reference_vreg_jni.cc
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2015 The Android Open Source Project
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include "arch/context.h"
|
| 18 |
+
#include "art_method-inl.h"
|
| 19 |
+
#include "jni.h"
|
| 20 |
+
#include "scoped_thread_state_change.h"
|
| 21 |
+
#include "stack.h"
|
| 22 |
+
#include "thread.h"
|
| 23 |
+
|
| 24 |
+
namespace art {
|
| 25 |
+
|
| 26 |
+
namespace {
|
| 27 |
+
|
| 28 |
+
class TestVisitor : public StackVisitor {
|
| 29 |
+
public:
|
| 30 |
+
TestVisitor(Thread* thread, Context* context, mirror::Object* this_value)
|
| 31 |
+
SHARED_REQUIRES(Locks::mutator_lock_)
|
| 32 |
+
: StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
|
| 33 |
+
this_value_(this_value),
|
| 34 |
+
found_method_index_(0) {}
|
| 35 |
+
|
| 36 |
+
bool VisitFrame() SHARED_REQUIRES(Locks::mutator_lock_) {
|
| 37 |
+
ArtMethod* m = GetMethod();
|
| 38 |
+
std::string m_name(m->GetName());
|
| 39 |
+
|
| 40 |
+
if (m_name.compare("testThisWithInstanceCall") == 0) {
|
| 41 |
+
found_method_index_ = 1;
|
| 42 |
+
uint32_t value = 0;
|
| 43 |
+
CHECK(GetVReg(m, 1, kReferenceVReg, &value));
|
| 44 |
+
CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
|
| 45 |
+
CHECK_EQ(GetThisObject(), this_value_);
|
| 46 |
+
} else if (m_name.compare("testThisWithStaticCall") == 0) {
|
| 47 |
+
found_method_index_ = 2;
|
| 48 |
+
uint32_t value = 0;
|
| 49 |
+
CHECK(GetVReg(m, 1, kReferenceVReg, &value));
|
| 50 |
+
} else if (m_name.compare("testParameter") == 0) {
|
| 51 |
+
found_method_index_ = 3;
|
| 52 |
+
uint32_t value = 0;
|
| 53 |
+
CHECK(GetVReg(m, 1, kReferenceVReg, &value));
|
| 54 |
+
} else if (m_name.compare("testObjectInScope") == 0) {
|
| 55 |
+
found_method_index_ = 4;
|
| 56 |
+
uint32_t value = 0;
|
| 57 |
+
CHECK(GetVReg(m, 0, kReferenceVReg, &value));
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
return true;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
mirror::Object* this_value_;
|
| 64 |
+
|
| 65 |
+
// Value returned to Java to ensure the methods testSimpleVReg and testPairVReg
|
| 66 |
+
// have been found and tested.
|
| 67 |
+
jint found_method_index_;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCallRef(JNIEnv*, jobject value) {
|
| 71 |
+
ScopedObjectAccess soa(Thread::Current());
|
| 72 |
+
std::unique_ptr<Context> context(Context::Create());
|
| 73 |
+
TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object*>(value));
|
| 74 |
+
visitor.WalkStack();
|
| 75 |
+
return visitor.found_method_index_;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
extern "C" JNIEXPORT jint JNICALL Java_Main_doStaticNativeCallRef(JNIEnv*, jclass) {
|
| 79 |
+
ScopedObjectAccess soa(Thread::Current());
|
| 80 |
+
std::unique_ptr<Context> context(Context::Create());
|
| 81 |
+
TestVisitor visitor(soa.Self(), context.get(), nullptr);
|
| 82 |
+
visitor.WalkStack();
|
| 83 |
+
return visitor.found_method_index_;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
} // namespace
|
| 87 |
+
|
| 88 |
+
} // namespace art
|
pool/shard010/C++/0111194_editaddressdialog.cpp
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "editaddressdialog.h"
|
| 2 |
+
#include "ui_editaddressdialog.h"
|
| 3 |
+
|
| 4 |
+
#include "addresstablemodel.h"
|
| 5 |
+
#include "guiutil.h"
|
| 6 |
+
|
| 7 |
+
#include <QDataWidgetMapper>
|
| 8 |
+
#include <QMessageBox>
|
| 9 |
+
|
| 10 |
+
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
|
| 11 |
+
QDialog(parent),
|
| 12 |
+
ui(new Ui::EditAddressDialog), mapper(0), mode(mode), model(0)
|
| 13 |
+
{
|
| 14 |
+
ui->setupUi(this);
|
| 15 |
+
|
| 16 |
+
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
| 17 |
+
|
| 18 |
+
switch(mode)
|
| 19 |
+
{
|
| 20 |
+
case NewReceivingAddress:
|
| 21 |
+
setWindowTitle(tr("New receiving address"));
|
| 22 |
+
ui->addressEdit->setEnabled(false);
|
| 23 |
+
break;
|
| 24 |
+
case NewSendingAddress:
|
| 25 |
+
setWindowTitle(tr("New sending address"));
|
| 26 |
+
break;
|
| 27 |
+
case EditReceivingAddress:
|
| 28 |
+
setWindowTitle(tr("Edit receiving address"));
|
| 29 |
+
ui->addressEdit->setEnabled(false);
|
| 30 |
+
break;
|
| 31 |
+
case EditSendingAddress:
|
| 32 |
+
setWindowTitle(tr("Edit sending address"));
|
| 33 |
+
break;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
mapper = new QDataWidgetMapper(this);
|
| 37 |
+
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
EditAddressDialog::~EditAddressDialog()
|
| 41 |
+
{
|
| 42 |
+
delete ui;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void EditAddressDialog::setModel(AddressTableModel *model)
|
| 46 |
+
{
|
| 47 |
+
this->model = model;
|
| 48 |
+
if(!model)
|
| 49 |
+
return;
|
| 50 |
+
|
| 51 |
+
mapper->setModel(model);
|
| 52 |
+
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
|
| 53 |
+
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void EditAddressDialog::loadRow(int row)
|
| 57 |
+
{
|
| 58 |
+
mapper->setCurrentIndex(row);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
bool EditAddressDialog::saveCurrentRow()
|
| 62 |
+
{
|
| 63 |
+
if(!model)
|
| 64 |
+
return false;
|
| 65 |
+
|
| 66 |
+
switch(mode)
|
| 67 |
+
{
|
| 68 |
+
case NewReceivingAddress:
|
| 69 |
+
case NewSendingAddress:
|
| 70 |
+
address = model->addRow(
|
| 71 |
+
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
|
| 72 |
+
ui->labelEdit->text(),
|
| 73 |
+
ui->addressEdit->text());
|
| 74 |
+
break;
|
| 75 |
+
case EditReceivingAddress:
|
| 76 |
+
case EditSendingAddress:
|
| 77 |
+
if(mapper->submit())
|
| 78 |
+
{
|
| 79 |
+
address = ui->addressEdit->text();
|
| 80 |
+
}
|
| 81 |
+
break;
|
| 82 |
+
}
|
| 83 |
+
return !address.isEmpty();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void EditAddressDialog::accept()
|
| 87 |
+
{
|
| 88 |
+
if(!model)
|
| 89 |
+
return;
|
| 90 |
+
|
| 91 |
+
if(!saveCurrentRow())
|
| 92 |
+
{
|
| 93 |
+
switch(model->getEditStatus())
|
| 94 |
+
{
|
| 95 |
+
case AddressTableModel::OK:
|
| 96 |
+
// Failed with unknown reason. Just reject.
|
| 97 |
+
break;
|
| 98 |
+
case AddressTableModel::NO_CHANGES:
|
| 99 |
+
// No changes were made during edit operation. Just reject.
|
| 100 |
+
break;
|
| 101 |
+
case AddressTableModel::INVALID_ADDRESS:
|
| 102 |
+
QMessageBox::warning(this, windowTitle(),
|
| 103 |
+
tr("The entered address \"%1\" is not a valid Syscoin address.").arg(ui->addressEdit->text()),
|
| 104 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 105 |
+
break;
|
| 106 |
+
case AddressTableModel::DUPLICATE_ADDRESS:
|
| 107 |
+
QMessageBox::warning(this, windowTitle(),
|
| 108 |
+
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
|
| 109 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 110 |
+
break;
|
| 111 |
+
case AddressTableModel::WALLET_UNLOCK_FAILURE:
|
| 112 |
+
QMessageBox::critical(this, windowTitle(),
|
| 113 |
+
tr("Could not unlock wallet."),
|
| 114 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 115 |
+
break;
|
| 116 |
+
case AddressTableModel::KEY_GENERATION_FAILURE:
|
| 117 |
+
QMessageBox::critical(this, windowTitle(),
|
| 118 |
+
tr("New key generation failed."),
|
| 119 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 120 |
+
break;
|
| 121 |
+
|
| 122 |
+
}
|
| 123 |
+
return;
|
| 124 |
+
}
|
| 125 |
+
QDialog::accept();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
QString EditAddressDialog::getAddress() const
|
| 129 |
+
{
|
| 130 |
+
return address;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
void EditAddressDialog::setAddress(const QString &address)
|
| 134 |
+
{
|
| 135 |
+
this->address = address;
|
| 136 |
+
ui->addressEdit->setText(address);
|
| 137 |
+
}
|
pool/shard010/C++/0111200_HardwareTimer.cpp
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************************
|
| 2 |
+
* The MIT License
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2010 Bryan Newbold.
|
| 5 |
+
*
|
| 6 |
+
* Permission is hereby granted, free of charge, to any person
|
| 7 |
+
* obtaining a copy of this software and associated documentation
|
| 8 |
+
* files (the "Software"), to deal in the Software without
|
| 9 |
+
* restriction, including without limitation the rights to use, copy,
|
| 10 |
+
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
| 11 |
+
* of the Software, and to permit persons to whom the Software is
|
| 12 |
+
* furnished to do so, subject to the following conditions:
|
| 13 |
+
*
|
| 14 |
+
* The above copyright notice and this permission notice shall be
|
| 15 |
+
* included in all copies or substantial portions of the Software.
|
| 16 |
+
*
|
| 17 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 18 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 19 |
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 20 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
| 21 |
+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
| 22 |
+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 23 |
+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 24 |
+
* SOFTWARE.
|
| 25 |
+
*****************************************************************************/
|
| 26 |
+
|
| 27 |
+
#include <wirish/HardwareTimer.h>
|
| 28 |
+
|
| 29 |
+
#include <libmaple/rcc.h>
|
| 30 |
+
#include <wirish/ext_interrupts.h> // for noInterrupts(), interrupts()
|
| 31 |
+
#include <wirish/wirish_math.h>
|
| 32 |
+
#include <board/board.h> // for CYCLES_PER_MICROSECOND
|
| 33 |
+
|
| 34 |
+
// TODO [0.1.0] Remove deprecated pieces
|
| 35 |
+
|
| 36 |
+
/*
|
| 37 |
+
* Evil hack to infer this->dev from timerNum in the HardwareTimer
|
| 38 |
+
* constructor. See:
|
| 39 |
+
*
|
| 40 |
+
* http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.2
|
| 41 |
+
* http://yosefk.com/c++fqa/function.html#fqa-33.2
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
extern "C" {
|
| 45 |
+
static timer_dev **this_devp;
|
| 46 |
+
static rcc_clk_id this_id;
|
| 47 |
+
static void set_this_dev(timer_dev *dev) {
|
| 48 |
+
if (dev->clk_id == this_id) {
|
| 49 |
+
*this_devp = dev;
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/*
|
| 55 |
+
* HardwareTimer routines
|
| 56 |
+
*/
|
| 57 |
+
|
| 58 |
+
HardwareTimer::HardwareTimer(uint8 timerNum) {
|
| 59 |
+
rcc_clk_id timerID = (rcc_clk_id)(RCC_TIMER1 + (timerNum - 1));
|
| 60 |
+
this->dev = NULL;
|
| 61 |
+
noInterrupts(); // Hack to ensure we're the only ones using
|
| 62 |
+
// set_this_dev() and friends. TODO: use a lock.
|
| 63 |
+
this_id = timerID;
|
| 64 |
+
this_devp = &this->dev;
|
| 65 |
+
timer_foreach(set_this_dev);
|
| 66 |
+
interrupts();
|
| 67 |
+
ASSERT(this->dev != NULL);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void HardwareTimer::pause(void) {
|
| 71 |
+
timer_pause(this->dev);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
void HardwareTimer::resume(void) {
|
| 75 |
+
timer_resume(this->dev);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
uint32 HardwareTimer::getPrescaleFactor(void) {
|
| 79 |
+
return timer_get_prescaler(this->dev) + 1;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void HardwareTimer::setPrescaleFactor(uint32 factor) {
|
| 83 |
+
timer_set_prescaler(this->dev, (uint16)(factor - 1));
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
uint16 HardwareTimer::getOverflow() {
|
| 87 |
+
return timer_get_reload(this->dev);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void HardwareTimer::setOverflow(uint16 val) {
|
| 91 |
+
timer_set_reload(this->dev, val);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
uint16 HardwareTimer::getCount(void) {
|
| 95 |
+
return timer_get_count(this->dev);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void HardwareTimer::setCount(uint16 val) {
|
| 99 |
+
uint16 ovf = this->getOverflow();
|
| 100 |
+
timer_set_count(this->dev, min(val, ovf));
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
#define MAX_RELOAD ((1 << 16) - 1)
|
| 104 |
+
uint16 HardwareTimer::setPeriod(uint32 microseconds) {
|
| 105 |
+
// Not the best way to handle this edge case?
|
| 106 |
+
if (!microseconds) {
|
| 107 |
+
this->setPrescaleFactor(1);
|
| 108 |
+
this->setOverflow(1);
|
| 109 |
+
return this->getOverflow();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
uint32 period_cyc = microseconds * CYCLES_PER_MICROSECOND;
|
| 113 |
+
uint16 prescaler = (uint16)(period_cyc / MAX_RELOAD + 1);
|
| 114 |
+
uint16 overflow = (uint16)((period_cyc + (prescaler / 2)) / prescaler);
|
| 115 |
+
this->setPrescaleFactor(prescaler);
|
| 116 |
+
this->setOverflow(overflow);
|
| 117 |
+
return overflow;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
void HardwareTimer::setMode(int channel, timer_mode mode) {
|
| 121 |
+
timer_set_mode(this->dev, (uint8)channel, (timer_mode)mode);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
uint16 HardwareTimer::getCompare(int channel) {
|
| 125 |
+
return timer_get_compare(this->dev, (uint8)channel);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
void HardwareTimer::setCompare(int channel, uint16 val) {
|
| 129 |
+
uint16 ovf = this->getOverflow();
|
| 130 |
+
timer_set_compare(this->dev, (uint8)channel, min(val, ovf));
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
void HardwareTimer::attachInterrupt(int channel, voidFuncPtr handler) {
|
| 134 |
+
timer_attach_interrupt(this->dev, (uint8)channel, handler);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
void HardwareTimer::detachInterrupt(int channel) {
|
| 138 |
+
timer_detach_interrupt(this->dev, (uint8)channel);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
void HardwareTimer::refresh(void) {
|
| 142 |
+
timer_generate_update(this->dev);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* -- Deprecated predefined instances -------------------------------------- */
|
| 146 |
+
|
| 147 |
+
HardwareTimer Timer1(1);
|
| 148 |
+
HardwareTimer Timer2(2);
|
| 149 |
+
HardwareTimer Timer3(3);
|
| 150 |
+
HardwareTimer Timer4(4);
|
| 151 |
+
#ifdef STM32_HIGH_DENSITY
|
| 152 |
+
HardwareTimer Timer5(5);
|
| 153 |
+
HardwareTimer Timer6(6);
|
| 154 |
+
HardwareTimer Timer7(7);
|
| 155 |
+
HardwareTimer Timer8(8);
|
| 156 |
+
#endif
|
pool/shard010/C++/0111202_LinkerObject.cpp
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
This file is part of solidity.
|
| 3 |
+
|
| 4 |
+
solidity is free software: you can redistribute it and/or modify
|
| 5 |
+
it under the terms of the GNU General Public License as published by
|
| 6 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 7 |
+
(at your option) any later version.
|
| 8 |
+
|
| 9 |
+
solidity is distributed in the hope that it will be useful,
|
| 10 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
GNU General Public License for more details.
|
| 13 |
+
|
| 14 |
+
You should have received a copy of the GNU General Public License
|
| 15 |
+
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
/** @file LinkerObject.cpp
|
| 18 |
+
* @author Christian R <c@ethdev.com>
|
| 19 |
+
* @date 2015
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <libevmasm/LinkerObject.h>
|
| 23 |
+
#include <libdevcore/CommonData.h>
|
| 24 |
+
|
| 25 |
+
using namespace dev;
|
| 26 |
+
using namespace dev::eth;
|
| 27 |
+
using namespace std;
|
| 28 |
+
|
| 29 |
+
void LinkerObject::append(LinkerObject const& _other)
|
| 30 |
+
{
|
| 31 |
+
for (auto const& ref: _other.linkReferences)
|
| 32 |
+
linkReferences[ref.first + bytecode.size()] = ref.second;
|
| 33 |
+
bytecode += _other.bytecode;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
void LinkerObject::link(map<string, h160> const& _libraryAddresses)
|
| 37 |
+
{
|
| 38 |
+
std::map<size_t, std::string> remainingRefs;
|
| 39 |
+
for (auto const& linkRef: linkReferences)
|
| 40 |
+
if (h160 const* address = matchLibrary(linkRef.second, _libraryAddresses))
|
| 41 |
+
copy(address->data(), address->data() + 20, bytecode.begin() + linkRef.first);
|
| 42 |
+
else
|
| 43 |
+
remainingRefs.insert(linkRef);
|
| 44 |
+
linkReferences.swap(remainingRefs);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
string LinkerObject::toHex() const
|
| 48 |
+
{
|
| 49 |
+
string hex = dev::toHex(bytecode);
|
| 50 |
+
for (auto const& ref: linkReferences)
|
| 51 |
+
{
|
| 52 |
+
size_t pos = ref.first * 2;
|
| 53 |
+
string const& name = ref.second;
|
| 54 |
+
hex[pos] = hex[pos + 1] = hex[pos + 38] = hex[pos + 39] = '_';
|
| 55 |
+
for (size_t i = 0; i < 36; ++i)
|
| 56 |
+
hex[pos + 2 + i] = i < name.size() ? name[i] : '_';
|
| 57 |
+
}
|
| 58 |
+
return hex;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
h160 const*
|
| 62 |
+
LinkerObject::matchLibrary(
|
| 63 |
+
string const& _linkRefName,
|
| 64 |
+
map<string, h160> const& _libraryAddresses
|
| 65 |
+
)
|
| 66 |
+
{
|
| 67 |
+
auto it = _libraryAddresses.find(_linkRefName);
|
| 68 |
+
if (it != _libraryAddresses.end())
|
| 69 |
+
return &it->second;
|
| 70 |
+
// If the user did not supply a fully qualified library name,
|
| 71 |
+
// try to match only the simple libary name
|
| 72 |
+
size_t colon = _linkRefName.find(':');
|
| 73 |
+
if (colon == string::npos)
|
| 74 |
+
return nullptr;
|
| 75 |
+
it = _libraryAddresses.find(_linkRefName.substr(colon + 1));
|
| 76 |
+
if (it != _libraryAddresses.end())
|
| 77 |
+
return &it->second;
|
| 78 |
+
return nullptr;
|
| 79 |
+
}
|
pool/shard010/C++/0111204_VRMarker.cpp
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "modules/vr/VRMarker.h"
|
| 6 |
+
|
| 7 |
+
namespace blink {
|
| 8 |
+
|
| 9 |
+
VRMarker::VRMarker(): m_type(0), m_id(0)
|
| 10 |
+
{
|
| 11 |
+
m_position = DOMFloat32Array::create(3);
|
| 12 |
+
m_orientation = DOMFloat32Array::create(4);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
unsigned VRMarker::type() const
|
| 16 |
+
{
|
| 17 |
+
return m_type;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
unsigned VRMarker::id() const
|
| 21 |
+
{
|
| 22 |
+
return m_id;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
String VRMarker::content() const
|
| 26 |
+
{
|
| 27 |
+
return m_content;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
DOMFloat32Array* VRMarker::position() const
|
| 31 |
+
{
|
| 32 |
+
return m_position;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
DOMFloat32Array* VRMarker::orientation() const
|
| 36 |
+
{
|
| 37 |
+
return m_orientation;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void VRMarker::setMarker(const device::mojom::blink::VRMarkerPtr& markerPtr)
|
| 41 |
+
{
|
| 42 |
+
m_type = markerPtr->type;
|
| 43 |
+
m_id = markerPtr->id;
|
| 44 |
+
m_content = markerPtr->content;
|
| 45 |
+
memcpy(m_position->data(), &(markerPtr->position.front()), 3 * sizeof(float));
|
| 46 |
+
memcpy(m_orientation->data(), &(markerPtr->orientation.front()), 4 * sizeof(float));
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
DEFINE_TRACE(VRMarker)
|
| 50 |
+
{
|
| 51 |
+
visitor->trace(m_position);
|
| 52 |
+
visitor->trace(m_orientation);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
} // namespace blink
|
pool/shard010/C++/0111207_EnhancedPositionClient.cpp
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (C) 2014 Mentor Graphics
|
| 2 |
+
* Author: Marco Residori(marco_residori@mentor.com)
|
| 3 |
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
| 4 |
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
| 5 |
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
| 6 |
+
|
| 7 |
+
#include <CommonAPI/CommonAPI.h>
|
| 8 |
+
#include <org/genivi/EnhancedPositionService/EnhancedPositionProxy.h>
|
| 9 |
+
#include "log.h"
|
| 10 |
+
|
| 11 |
+
DLT_DECLARE_CONTEXT(gCtx);
|
| 12 |
+
|
| 13 |
+
using namespace org::genivi::EnhancedPositionService;
|
| 14 |
+
using namespace org::genivi::EnhancedPositionService::EnhancedPositionServiceTypes;
|
| 15 |
+
|
| 16 |
+
void getPositionInfoAsyncCallback(const CommonAPI::CallStatus& callStatus, const EnhancedPositionServiceTypes::Timestamp& timestamp, const EnhancedPositionServiceTypes::PositionInfo& posInfo)
|
| 17 |
+
{
|
| 18 |
+
if (callStatus != CommonAPI::CallStatus::SUCCESS) {
|
| 19 |
+
LOG_ERROR_MSG(gCtx,"Remote call failed!\n");
|
| 20 |
+
return;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
for ( auto it = posInfo.begin(); it != posInfo.end(); ++it ) {
|
| 24 |
+
if (it->first == PositionInfoKey::LATITUDE)
|
| 25 |
+
{
|
| 26 |
+
LOG_INFO(gCtx,"LAT=%lf", it->second.get<double>());
|
| 27 |
+
}
|
| 28 |
+
if (it->first == PositionInfoKey::LONGITUDE)
|
| 29 |
+
{
|
| 30 |
+
LOG_INFO(gCtx,"LON=%lf", it->second.get<double>());
|
| 31 |
+
}
|
| 32 |
+
if (it->first == PositionInfoKey::ALTITUDE)
|
| 33 |
+
{
|
| 34 |
+
LOG_INFO(gCtx,"ALT=%lf", it->second.get<float>());
|
| 35 |
+
}
|
| 36 |
+
if (it->first == PositionInfoKey::SPEED)
|
| 37 |
+
{
|
| 38 |
+
LOG_INFO(gCtx,"SPEED=%lf", it->second.get<float>());
|
| 39 |
+
}
|
| 40 |
+
if (it->first == PositionInfoKey::CLIMB)
|
| 41 |
+
{
|
| 42 |
+
LOG_INFO(gCtx,"CLIMB=%lf", it->second.get<float>());
|
| 43 |
+
}
|
| 44 |
+
if (it->first == PositionInfoKey::HEADING)
|
| 45 |
+
{
|
| 46 |
+
LOG_INFO(gCtx,"HEADING=%lf", it->second.get<float>());
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
void positionUpdate(std::shared_ptr<EnhancedPositionProxyDefault> proxy, const EnhancedPositionServiceTypes::Bitmask& changedValues)
|
| 52 |
+
{
|
| 53 |
+
LOG_INFO_MSG(gCtx,"Position Update");
|
| 54 |
+
|
| 55 |
+
if(proxy == NULL)
|
| 56 |
+
{
|
| 57 |
+
LOG_ERROR_MSG(gCtx,"Null pointer!");
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
std::function<void(const CommonAPI::CallStatus&,
|
| 62 |
+
const EnhancedPositionServiceTypes::Timestamp&,
|
| 63 |
+
const EnhancedPositionServiceTypes::PositionInfo&)> fcb = getPositionInfoAsyncCallback;
|
| 64 |
+
|
| 65 |
+
proxy->GetPositionInfoAsync(changedValues,getPositionInfoAsyncCallback);
|
| 66 |
+
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
int main() {
|
| 70 |
+
|
| 71 |
+
DLT_REGISTER_APP("ENHC","ENHANCED-POSITION-CLIENT");
|
| 72 |
+
DLT_REGISTER_CONTEXT(gCtx,"ENHC","Global Context");
|
| 73 |
+
|
| 74 |
+
std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::load();
|
| 75 |
+
std::shared_ptr < CommonAPI::Factory > factory = runtime->createFactory();
|
| 76 |
+
|
| 77 |
+
const std::string& serviceAddress = "local:org.genivi.positioning.EnhancedPosition:org.genivi.positioning.EnhancedPosition";
|
| 78 |
+
std::shared_ptr<EnhancedPositionProxyDefault> myProxy = factory->buildProxy<EnhancedPositionProxy>(serviceAddress);
|
| 79 |
+
|
| 80 |
+
LOG_INFO_MSG(gCtx,"EnhancedPositionClient");
|
| 81 |
+
|
| 82 |
+
while (!myProxy->isAvailable()) {
|
| 83 |
+
usleep(10);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
myProxy->getPositionUpdateEvent().subscribe([&](const EnhancedPositionServiceTypes::Bitmask& changedValues) {
|
| 87 |
+
positionUpdate(myProxy, changedValues);
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
+
while (true) {
|
| 91 |
+
std::this_thread::sleep_for(std::chrono::seconds(5));
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
return 0;
|
| 95 |
+
}
|
pool/shard010/C++/0111208_CWE23_Relative_Path_Traversal__wchar_t_listen_socket_fopen_45.cpp
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE23_Relative_Path_Traversal__wchar_t_listen_socket_fopen_45.cpp
|
| 3 |
+
Label Definition File: CWE23_Relative_Path_Traversal.label.xml
|
| 4 |
+
Template File: sources-sink-45.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 23 Relative Path Traversal
|
| 9 |
+
* BadSource: listen_socket Read data using a listen socket (server side)
|
| 10 |
+
* GoodSource: Use a fixed file name
|
| 11 |
+
* Sinks: fopen
|
| 12 |
+
* BadSink : Open the file named in data using fopen()
|
| 13 |
+
* Flow Variant: 45 Data flow: data passed as a static global variable from one function to another in the same source file
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
|
| 19 |
+
#ifdef _WIN32
|
| 20 |
+
#define BASEPATH L"c:\\temp\\"
|
| 21 |
+
#else
|
| 22 |
+
#include <wchar.h>
|
| 23 |
+
#define BASEPATH L"/tmp/"
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
#ifdef _WIN32
|
| 27 |
+
#include <winsock2.h>
|
| 28 |
+
#include <windows.h>
|
| 29 |
+
#include <direct.h>
|
| 30 |
+
#pragma comment(lib, "ws2_32") /* include ws2_32.lib when linking */
|
| 31 |
+
#define CLOSE_SOCKET closesocket
|
| 32 |
+
#else
|
| 33 |
+
#include <sys/types.h>
|
| 34 |
+
#include <sys/socket.h>
|
| 35 |
+
#include <netinet/in.h>
|
| 36 |
+
#include <arpa/inet.h>
|
| 37 |
+
#include <unistd.h>
|
| 38 |
+
#define INVALID_SOCKET -1
|
| 39 |
+
#define SOCKET_ERROR -1
|
| 40 |
+
#define CLOSE_SOCKET close
|
| 41 |
+
#define SOCKET int
|
| 42 |
+
#endif
|
| 43 |
+
|
| 44 |
+
#define TCP_PORT 27015
|
| 45 |
+
#define LISTEN_BACKLOG 5
|
| 46 |
+
|
| 47 |
+
#ifdef _WIN32
|
| 48 |
+
#define FOPEN _wfopen
|
| 49 |
+
#else
|
| 50 |
+
#define FOPEN fopen
|
| 51 |
+
#endif
|
| 52 |
+
|
| 53 |
+
namespace CWE23_Relative_Path_Traversal__wchar_t_listen_socket_fopen_45
|
| 54 |
+
{
|
| 55 |
+
|
| 56 |
+
static wchar_t * badData;
|
| 57 |
+
static wchar_t * goodG2BData;
|
| 58 |
+
|
| 59 |
+
#ifndef OMITBAD
|
| 60 |
+
|
| 61 |
+
static void badSink()
|
| 62 |
+
{
|
| 63 |
+
wchar_t * data = badData;
|
| 64 |
+
{
|
| 65 |
+
FILE *pFile = NULL;
|
| 66 |
+
/* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
|
| 67 |
+
pFile = FOPEN(data, L"wb+");
|
| 68 |
+
if (pFile != NULL)
|
| 69 |
+
{
|
| 70 |
+
fclose(pFile);
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
void bad()
|
| 76 |
+
{
|
| 77 |
+
wchar_t * data;
|
| 78 |
+
wchar_t dataBuffer[FILENAME_MAX] = BASEPATH;
|
| 79 |
+
data = dataBuffer;
|
| 80 |
+
{
|
| 81 |
+
#ifdef _WIN32
|
| 82 |
+
WSADATA wsaData;
|
| 83 |
+
int wsaDataInit = 0;
|
| 84 |
+
#endif
|
| 85 |
+
int recvResult;
|
| 86 |
+
struct sockaddr_in service;
|
| 87 |
+
wchar_t *replace;
|
| 88 |
+
SOCKET listenSocket = INVALID_SOCKET;
|
| 89 |
+
SOCKET acceptSocket = INVALID_SOCKET;
|
| 90 |
+
size_t dataLen = wcslen(data);
|
| 91 |
+
do
|
| 92 |
+
{
|
| 93 |
+
#ifdef _WIN32
|
| 94 |
+
if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR)
|
| 95 |
+
{
|
| 96 |
+
break;
|
| 97 |
+
}
|
| 98 |
+
wsaDataInit = 1;
|
| 99 |
+
#endif
|
| 100 |
+
/* POTENTIAL FLAW: Read data using a listen socket */
|
| 101 |
+
listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
| 102 |
+
if (listenSocket == INVALID_SOCKET)
|
| 103 |
+
{
|
| 104 |
+
break;
|
| 105 |
+
}
|
| 106 |
+
memset(&service, 0, sizeof(service));
|
| 107 |
+
service.sin_family = AF_INET;
|
| 108 |
+
service.sin_addr.s_addr = INADDR_ANY;
|
| 109 |
+
service.sin_port = htons(TCP_PORT);
|
| 110 |
+
if (bind(listenSocket, (struct sockaddr*)&service, sizeof(service)) == SOCKET_ERROR)
|
| 111 |
+
{
|
| 112 |
+
break;
|
| 113 |
+
}
|
| 114 |
+
if (listen(listenSocket, LISTEN_BACKLOG) == SOCKET_ERROR)
|
| 115 |
+
{
|
| 116 |
+
break;
|
| 117 |
+
}
|
| 118 |
+
acceptSocket = accept(listenSocket, NULL, NULL);
|
| 119 |
+
if (acceptSocket == SOCKET_ERROR)
|
| 120 |
+
{
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
/* Abort on error or the connection was closed */
|
| 124 |
+
recvResult = recv(acceptSocket, (char *)(data + dataLen), sizeof(wchar_t) * (FILENAME_MAX - dataLen - 1), 0);
|
| 125 |
+
if (recvResult == SOCKET_ERROR || recvResult == 0)
|
| 126 |
+
{
|
| 127 |
+
break;
|
| 128 |
+
}
|
| 129 |
+
/* Append null terminator */
|
| 130 |
+
data[dataLen + recvResult / sizeof(wchar_t)] = L'\0';
|
| 131 |
+
/* Eliminate CRLF */
|
| 132 |
+
replace = wcschr(data, L'\r');
|
| 133 |
+
if (replace)
|
| 134 |
+
{
|
| 135 |
+
*replace = L'\0';
|
| 136 |
+
}
|
| 137 |
+
replace = wcschr(data, L'\n');
|
| 138 |
+
if (replace)
|
| 139 |
+
{
|
| 140 |
+
*replace = L'\0';
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
while (0);
|
| 144 |
+
if (listenSocket != INVALID_SOCKET)
|
| 145 |
+
{
|
| 146 |
+
CLOSE_SOCKET(listenSocket);
|
| 147 |
+
}
|
| 148 |
+
if (acceptSocket != INVALID_SOCKET)
|
| 149 |
+
{
|
| 150 |
+
CLOSE_SOCKET(acceptSocket);
|
| 151 |
+
}
|
| 152 |
+
#ifdef _WIN32
|
| 153 |
+
if (wsaDataInit)
|
| 154 |
+
{
|
| 155 |
+
WSACleanup();
|
| 156 |
+
}
|
| 157 |
+
#endif
|
| 158 |
+
}
|
| 159 |
+
badData = data;
|
| 160 |
+
badSink();
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
#endif /* OMITBAD */
|
| 164 |
+
|
| 165 |
+
#ifndef OMITGOOD
|
| 166 |
+
|
| 167 |
+
/* goodG2B() uses the GoodSource with the BadSink */
|
| 168 |
+
static void goodG2BSink()
|
| 169 |
+
{
|
| 170 |
+
wchar_t * data = goodG2BData;
|
| 171 |
+
{
|
| 172 |
+
FILE *pFile = NULL;
|
| 173 |
+
/* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
|
| 174 |
+
pFile = FOPEN(data, L"wb+");
|
| 175 |
+
if (pFile != NULL)
|
| 176 |
+
{
|
| 177 |
+
fclose(pFile);
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
static void goodG2B()
|
| 183 |
+
{
|
| 184 |
+
wchar_t * data;
|
| 185 |
+
wchar_t dataBuffer[FILENAME_MAX] = BASEPATH;
|
| 186 |
+
data = dataBuffer;
|
| 187 |
+
/* FIX: Use a fixed file name */
|
| 188 |
+
wcscat(data, L"file.txt");
|
| 189 |
+
goodG2BData = data;
|
| 190 |
+
goodG2BSink();
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
void good()
|
| 194 |
+
{
|
| 195 |
+
goodG2B();
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
#endif /* OMITGOOD */
|
| 199 |
+
|
| 200 |
+
} /* close namespace */
|
| 201 |
+
|
| 202 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 203 |
+
its own for testing or for building a binary to use in testing binary
|
| 204 |
+
analysis tools. It is not used when compiling all the testcases as one
|
| 205 |
+
application, which is how source code analysis tools are tested. */
|
| 206 |
+
|
| 207 |
+
#ifdef INCLUDEMAIN
|
| 208 |
+
|
| 209 |
+
using namespace CWE23_Relative_Path_Traversal__wchar_t_listen_socket_fopen_45; /* so that we can use good and bad easily */
|
| 210 |
+
|
| 211 |
+
int main(int argc, char * argv[])
|
| 212 |
+
{
|
| 213 |
+
/* seed randomness */
|
| 214 |
+
srand( (unsigned)time(NULL) );
|
| 215 |
+
#ifndef OMITGOOD
|
| 216 |
+
printLine("Calling good()...");
|
| 217 |
+
good();
|
| 218 |
+
printLine("Finished good()");
|
| 219 |
+
#endif /* OMITGOOD */
|
| 220 |
+
#ifndef OMITBAD
|
| 221 |
+
printLine("Calling bad()...");
|
| 222 |
+
bad();
|
| 223 |
+
printLine("Finished bad()");
|
| 224 |
+
#endif /* OMITBAD */
|
| 225 |
+
return 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
#endif
|
pool/shard010/C++/0111210_catalog_proxy.cpp
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===----------------------------------------------------------------------===//
|
| 2 |
+
//
|
| 3 |
+
// Peloton
|
| 4 |
+
//
|
| 5 |
+
// catalog_proxy.cpp
|
| 6 |
+
//
|
| 7 |
+
// Identification: src/codegen/proxy/catalog_proxy.cpp
|
| 8 |
+
//
|
| 9 |
+
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#include "codegen/proxy/catalog_proxy.h"
|
| 14 |
+
|
| 15 |
+
#include "codegen/proxy/data_table_proxy.h"
|
| 16 |
+
#include "storage/storage_manager.h"
|
| 17 |
+
|
| 18 |
+
namespace peloton {
|
| 19 |
+
namespace codegen {
|
| 20 |
+
|
| 21 |
+
//===----------------------------------------------------------------------===//
|
| 22 |
+
// Return the LLVM type that matches the memory layout of our Database class
|
| 23 |
+
//===----------------------------------------------------------------------===//
|
| 24 |
+
llvm::Type* CatalogProxy::GetType(CodeGen& codegen) {
|
| 25 |
+
static const std::string kCatalogTypeName =
|
| 26 |
+
"peloton::storage::StorageManager";
|
| 27 |
+
// Check if the type is already registered in the module, if so return it
|
| 28 |
+
auto* catalog_type = codegen.LookupTypeByName(kCatalogTypeName);
|
| 29 |
+
if (catalog_type != nullptr) {
|
| 30 |
+
return catalog_type;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// Right now we don't need to define each individual field of storage::Catalog
|
| 34 |
+
// since we only invoke functions on the class.
|
| 35 |
+
static constexpr uint64_t catalog_obj_size =
|
| 36 |
+
sizeof(storage::StorageManager);
|
| 37 |
+
/*
|
| 38 |
+
static constexpr uint64_t catalog_obj_size = sizeof(std::atomic<oid_t>) +
|
| 39 |
+
sizeof(lookup_dir) +
|
| 40 |
+
sizeof(std::mutex) +
|
| 41 |
+
sizeof(std::vector<storage::Database*>) +
|
| 42 |
+
sizeof(std::mutex);
|
| 43 |
+
static_assert(
|
| 44 |
+
catalog_obj_size == sizeof(catalog::Catalog),
|
| 45 |
+
"LLVM memory layout of catalog::Catalog doesn't match precompiled"
|
| 46 |
+
"version. Did you forget to update codegen/catalog_proxy.h?");
|
| 47 |
+
*/
|
| 48 |
+
auto* byte_arr_type =
|
| 49 |
+
llvm::ArrayType::get(codegen.Int8Type(), catalog_obj_size);
|
| 50 |
+
catalog_type = llvm::StructType::create(codegen.GetContext(), {byte_arr_type},
|
| 51 |
+
kCatalogTypeName);
|
| 52 |
+
return catalog_type;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
//===----------------------------------------------------------------------===//
|
| 56 |
+
// Return the symbol of the Catalog::GetTableWithOid() function
|
| 57 |
+
//===----------------------------------------------------------------------===//
|
| 58 |
+
const std::string& CatalogProxy::_GetTableWithOid::GetFunctionName() {
|
| 59 |
+
static const std::string kGetTableByIdFnName =
|
| 60 |
+
#ifdef __APPLE__
|
| 61 |
+
"_ZNK7peloton7storage14StorageManager15GetTableWithOidEjj";
|
| 62 |
+
#else
|
| 63 |
+
"_ZNK7peloton7storage14StorageManager15GetTableWithOidEjj";
|
| 64 |
+
#endif
|
| 65 |
+
return kGetTableByIdFnName;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
//===----------------------------------------------------------------------===//
|
| 69 |
+
// Return the LLVM function definition for Catalog::GetTableWithOid()
|
| 70 |
+
//===----------------------------------------------------------------------===//
|
| 71 |
+
llvm::Function* CatalogProxy::_GetTableWithOid::GetFunction(CodeGen& codegen) {
|
| 72 |
+
const std::string& fn_name = GetFunctionName();
|
| 73 |
+
|
| 74 |
+
// Has the function already been registered?
|
| 75 |
+
llvm::Function* llvm_fn = codegen.LookupFunction(fn_name);
|
| 76 |
+
if (llvm_fn != nullptr) {
|
| 77 |
+
return llvm_fn;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// The function hasn't been registered, let's do it now
|
| 81 |
+
llvm::Type* catalog_type = CatalogProxy::GetType(codegen);
|
| 82 |
+
llvm::Type* table_type = DataTableProxy::GetType(codegen);
|
| 83 |
+
std::vector<llvm::Type*> fn_args{catalog_type->getPointerTo(),
|
| 84 |
+
codegen.Int32Type(), // database id
|
| 85 |
+
codegen.Int32Type()}; // table id
|
| 86 |
+
llvm::FunctionType* fn_type =
|
| 87 |
+
llvm::FunctionType::get(table_type->getPointerTo(), fn_args, false);
|
| 88 |
+
return codegen.RegisterFunction(fn_name, fn_type);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
} // namespace codegen
|
| 92 |
+
} // namespace peloton
|
pool/shard010/C++/0111212_helpers.cpp
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "helpers.h"
|
| 2 |
+
#include <boost/algorithm/string.hpp> // trim()
|
| 3 |
+
#include <sstream>
|
| 4 |
+
|
| 5 |
+
/***************************** LOCAL FUNCTIONS *******************************/
|
| 6 |
+
|
| 7 |
+
/******************************************************************************
|
| 8 |
+
* http://stackoverflow.com/questions/236129/how-to-split-a-string-in-c
|
| 9 |
+
******************************************************************************/
|
| 10 |
+
std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems)
|
| 11 |
+
{
|
| 12 |
+
std::stringstream ss(s);
|
| 13 |
+
std::string item;
|
| 14 |
+
while (std::getline(ss, item, delim))
|
| 15 |
+
if (!item.empty()) // don't add ""
|
| 16 |
+
elems.push_back(item);
|
| 17 |
+
|
| 18 |
+
return elems;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
/*************************** HELPERS.H FUNCTIONS *****************************/
|
| 22 |
+
|
| 23 |
+
// use boost for trimming...
|
| 24 |
+
void trim(std::string& str)
|
| 25 |
+
{
|
| 26 |
+
boost::trim(str);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/******************************************************************************
|
| 30 |
+
* split()
|
| 31 |
+
* http://stackoverflow.com/questions/236129/how-to-split-a-string-in-c
|
| 32 |
+
******************************************************************************/
|
| 33 |
+
std::vector<std::string> split(const std::string& s, char delim)
|
| 34 |
+
{
|
| 35 |
+
std::vector<std::string> elems;
|
| 36 |
+
split(s, delim, elems);
|
| 37 |
+
return elems;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/******************************************************************************
|
| 41 |
+
* shortName()
|
| 42 |
+
* - returns the short version of the given filename
|
| 43 |
+
* - example: "./plugins/hello.so" => "hello"
|
| 44 |
+
******************************************************************************/
|
| 45 |
+
std::string shortName(const std::string& filename)
|
| 46 |
+
{
|
| 47 |
+
std::string result = filename;
|
| 48 |
+
std::string::size_type pos = result.find_last_of("/") + 1; // strip leading dirs
|
| 49 |
+
result = result.substr(pos);
|
| 50 |
+
std::string extension = ".so"; // strip .so extension (if any)
|
| 51 |
+
pos = result.find(extension);
|
| 52 |
+
if (pos != std::string::npos)
|
| 53 |
+
result = result.substr(0, pos);
|
| 54 |
+
extension = ".dll"; // strip .dll extension (if any)
|
| 55 |
+
pos = result.find(extension);
|
| 56 |
+
if (pos != std::string::npos)
|
| 57 |
+
result = result.substr(0, pos);
|
| 58 |
+
return result;
|
| 59 |
+
}
|
pool/shard010/C++/0111214_DWARFDebugArangeSet.cpp
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- DWARFDebugArangeSet.cpp ---------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// The LLVM Compiler Infrastructure
|
| 4 |
+
//
|
| 5 |
+
// This file is distributed under the University of Illinois Open Source
|
| 6 |
+
// License. See LICENSE.TXT for details.
|
| 7 |
+
//
|
| 8 |
+
//===----------------------------------------------------------------------===//
|
| 9 |
+
|
| 10 |
+
#include "DWARFDebugArangeSet.h"
|
| 11 |
+
|
| 12 |
+
#include <assert.h>
|
| 13 |
+
#include "lldb/Core/Stream.h"
|
| 14 |
+
#include "SymbolFileDWARF.h"
|
| 15 |
+
|
| 16 |
+
using namespace lldb_private;
|
| 17 |
+
|
| 18 |
+
DWARFDebugArangeSet::DWARFDebugArangeSet() :
|
| 19 |
+
m_offset(DW_INVALID_OFFSET),
|
| 20 |
+
m_header(),
|
| 21 |
+
m_arange_descriptors()
|
| 22 |
+
{
|
| 23 |
+
m_header.length = 0;
|
| 24 |
+
m_header.version = 0;
|
| 25 |
+
m_header.cu_offset = 0;
|
| 26 |
+
m_header.addr_size = 0;
|
| 27 |
+
m_header.seg_size = 0;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void
|
| 31 |
+
DWARFDebugArangeSet::Clear()
|
| 32 |
+
{
|
| 33 |
+
m_offset = DW_INVALID_OFFSET;
|
| 34 |
+
m_header.length = 0;
|
| 35 |
+
m_header.version = 0;
|
| 36 |
+
m_header.cu_offset = 0;
|
| 37 |
+
m_header.addr_size = 0;
|
| 38 |
+
m_header.seg_size = 0;
|
| 39 |
+
m_arange_descriptors.clear();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
void
|
| 43 |
+
DWARFDebugArangeSet::SetHeader
|
| 44 |
+
(
|
| 45 |
+
uint16_t version,
|
| 46 |
+
uint32_t cu_offset,
|
| 47 |
+
uint8_t addr_size,
|
| 48 |
+
uint8_t seg_size
|
| 49 |
+
)
|
| 50 |
+
{
|
| 51 |
+
m_header.version = version;
|
| 52 |
+
m_header.cu_offset = cu_offset;
|
| 53 |
+
m_header.addr_size = addr_size;
|
| 54 |
+
m_header.seg_size = seg_size;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void
|
| 58 |
+
DWARFDebugArangeSet::Compact()
|
| 59 |
+
{
|
| 60 |
+
if (m_arange_descriptors.empty())
|
| 61 |
+
return;
|
| 62 |
+
|
| 63 |
+
// Iterate through all arange descriptors and combine any ranges that
|
| 64 |
+
// overlap or have matching boundaries. The m_arange_descriptors are assumed
|
| 65 |
+
// to be in ascending order after being built by adding descriptors
|
| 66 |
+
// using the AddDescriptor method.
|
| 67 |
+
uint32_t i = 0;
|
| 68 |
+
while (i + 1 < m_arange_descriptors.size())
|
| 69 |
+
{
|
| 70 |
+
if (m_arange_descriptors[i].end_address() >= m_arange_descriptors[i+1].address)
|
| 71 |
+
{
|
| 72 |
+
// The current range ends at or exceeds the start of the next address range.
|
| 73 |
+
// Compute the max end address between the two and use that to make the new
|
| 74 |
+
// length.
|
| 75 |
+
const dw_addr_t max_end_addr = std::max(m_arange_descriptors[i].end_address(), m_arange_descriptors[i+1].end_address());
|
| 76 |
+
m_arange_descriptors[i].length = max_end_addr - m_arange_descriptors[i].address;
|
| 77 |
+
// Now remove the next entry as it was just combined with the previous one.
|
| 78 |
+
m_arange_descriptors.erase(m_arange_descriptors.begin()+i+1);
|
| 79 |
+
}
|
| 80 |
+
else
|
| 81 |
+
{
|
| 82 |
+
// Discontiguous address range, just proceed to the next one.
|
| 83 |
+
++i;
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
//----------------------------------------------------------------------
|
| 88 |
+
// Compare function DWARFDebugArangeSet::Descriptor structures
|
| 89 |
+
//----------------------------------------------------------------------
|
| 90 |
+
static bool DescriptorLessThan (const DWARFDebugArangeSet::Descriptor& range1, const DWARFDebugArangeSet::Descriptor& range2)
|
| 91 |
+
{
|
| 92 |
+
return range1.address < range2.address;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
//----------------------------------------------------------------------
|
| 96 |
+
// Add a range descriptor and keep things sorted so we can easily
|
| 97 |
+
// compact the ranges before being saved or used.
|
| 98 |
+
//----------------------------------------------------------------------
|
| 99 |
+
void
|
| 100 |
+
DWARFDebugArangeSet::AddDescriptor(const DWARFDebugArangeSet::Descriptor& range)
|
| 101 |
+
{
|
| 102 |
+
if (m_arange_descriptors.empty())
|
| 103 |
+
{
|
| 104 |
+
m_arange_descriptors.push_back(range);
|
| 105 |
+
return;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
DescriptorIter end = m_arange_descriptors.end();
|
| 109 |
+
DescriptorIter pos = lower_bound(m_arange_descriptors.begin(), end, range, DescriptorLessThan);
|
| 110 |
+
const dw_addr_t range_end_addr = range.end_address();
|
| 111 |
+
if (pos != end)
|
| 112 |
+
{
|
| 113 |
+
const dw_addr_t found_end_addr = pos->end_address();
|
| 114 |
+
if (range.address < pos->address)
|
| 115 |
+
{
|
| 116 |
+
if (range_end_addr < pos->address)
|
| 117 |
+
{
|
| 118 |
+
// Non-contiguous entries, add this one before the found entry
|
| 119 |
+
m_arange_descriptors.insert(pos, range);
|
| 120 |
+
}
|
| 121 |
+
else if (range_end_addr == pos->address)
|
| 122 |
+
{
|
| 123 |
+
// The top end of 'range' is the lower end of the entry
|
| 124 |
+
// pointed to by 'pos'. We can combine range with the
|
| 125 |
+
// entry we found by setting the starting address and
|
| 126 |
+
// increasing the length since they don't overlap.
|
| 127 |
+
pos->address = range.address;
|
| 128 |
+
pos->length += range.length;
|
| 129 |
+
}
|
| 130 |
+
else
|
| 131 |
+
{
|
| 132 |
+
// We can combine these two and make sure the largest end
|
| 133 |
+
// address is used to make end address.
|
| 134 |
+
pos->address = range.address;
|
| 135 |
+
pos->length = std::max(found_end_addr, range_end_addr) - pos->address;
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
else if (range.address == pos->address)
|
| 139 |
+
{
|
| 140 |
+
pos->length = std::max(pos->length, range.length);
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
else
|
| 144 |
+
{
|
| 145 |
+
// NOTE: 'pos' points to entry past the end which is ok for insert,
|
| 146 |
+
// don't use otherwise!!!
|
| 147 |
+
const dw_addr_t max_addr = m_arange_descriptors.back().end_address();
|
| 148 |
+
if (max_addr < range.address)
|
| 149 |
+
{
|
| 150 |
+
// Non-contiguous entries, add this one before the found entry
|
| 151 |
+
m_arange_descriptors.insert(pos, range);
|
| 152 |
+
}
|
| 153 |
+
else if (max_addr == range.address)
|
| 154 |
+
{
|
| 155 |
+
m_arange_descriptors.back().length += range.length;
|
| 156 |
+
}
|
| 157 |
+
else
|
| 158 |
+
{
|
| 159 |
+
m_arange_descriptors.back().length = std::max(max_addr, range_end_addr) - m_arange_descriptors.back().address;
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
bool
|
| 165 |
+
DWARFDebugArangeSet::Extract(const DataExtractor &data, lldb::offset_t *offset_ptr)
|
| 166 |
+
{
|
| 167 |
+
if (data.ValidOffset(*offset_ptr))
|
| 168 |
+
{
|
| 169 |
+
m_arange_descriptors.clear();
|
| 170 |
+
m_offset = *offset_ptr;
|
| 171 |
+
|
| 172 |
+
// 7.20 Address Range Table
|
| 173 |
+
//
|
| 174 |
+
// Each set of entries in the table of address ranges contained in
|
| 175 |
+
// the .debug_aranges section begins with a header consisting of: a
|
| 176 |
+
// 4-byte length containing the length of the set of entries for this
|
| 177 |
+
// compilation unit, not including the length field itself; a 2-byte
|
| 178 |
+
// version identifier containing the value 2 for DWARF Version 2; a
|
| 179 |
+
// 4-byte offset into the.debug_infosection; a 1-byte unsigned integer
|
| 180 |
+
// containing the size in bytes of an address (or the offset portion of
|
| 181 |
+
// an address for segmented addressing) on the target system; and a
|
| 182 |
+
// 1-byte unsigned integer containing the size in bytes of a segment
|
| 183 |
+
// descriptor on the target system. This header is followed by a series
|
| 184 |
+
// of tuples. Each tuple consists of an address and a length, each in
|
| 185 |
+
// the size appropriate for an address on the target architecture.
|
| 186 |
+
m_header.length = data.GetU32(offset_ptr);
|
| 187 |
+
m_header.version = data.GetU16(offset_ptr);
|
| 188 |
+
m_header.cu_offset = data.GetU32(offset_ptr);
|
| 189 |
+
m_header.addr_size = data.GetU8(offset_ptr);
|
| 190 |
+
m_header.seg_size = data.GetU8(offset_ptr);
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
// The first tuple following the header in each set begins at an offset
|
| 194 |
+
// that is a multiple of the size of a single tuple (that is, twice the
|
| 195 |
+
// size of an address). The header is padded, if necessary, to the
|
| 196 |
+
// appropriate boundary.
|
| 197 |
+
const uint32_t header_size = *offset_ptr - m_offset;
|
| 198 |
+
const uint32_t tuple_size = m_header.addr_size << 1;
|
| 199 |
+
uint32_t first_tuple_offset = 0;
|
| 200 |
+
while (first_tuple_offset < header_size)
|
| 201 |
+
first_tuple_offset += tuple_size;
|
| 202 |
+
|
| 203 |
+
*offset_ptr = m_offset + first_tuple_offset;
|
| 204 |
+
|
| 205 |
+
Descriptor arangeDescriptor;
|
| 206 |
+
|
| 207 |
+
assert(sizeof(arangeDescriptor.address) == sizeof(arangeDescriptor.length));
|
| 208 |
+
assert(sizeof(arangeDescriptor.address) >= m_header.addr_size);
|
| 209 |
+
|
| 210 |
+
while (data.ValidOffset(*offset_ptr))
|
| 211 |
+
{
|
| 212 |
+
arangeDescriptor.address = data.GetMaxU64(offset_ptr, m_header.addr_size);
|
| 213 |
+
arangeDescriptor.length = data.GetMaxU64(offset_ptr, m_header.addr_size);
|
| 214 |
+
|
| 215 |
+
// Each set of tuples is terminated by a 0 for the address and 0
|
| 216 |
+
// for the length.
|
| 217 |
+
if (arangeDescriptor.address || arangeDescriptor.length)
|
| 218 |
+
m_arange_descriptors.push_back(arangeDescriptor);
|
| 219 |
+
else
|
| 220 |
+
break; // We are done if we get a zero address and length
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
return !m_arange_descriptors.empty();
|
| 224 |
+
}
|
| 225 |
+
return false;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
dw_offset_t
|
| 230 |
+
DWARFDebugArangeSet::GetOffsetOfNextEntry() const
|
| 231 |
+
{
|
| 232 |
+
return m_offset + m_header.length + 4;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
void
|
| 237 |
+
DWARFDebugArangeSet::Dump(Stream *s) const
|
| 238 |
+
{
|
| 239 |
+
s->Printf("Address Range Header: length = 0x%8.8x, version = 0x%4.4x, cu_offset = 0x%8.8x, addr_size = 0x%2.2x, seg_size = 0x%2.2x\n",
|
| 240 |
+
m_header.length ,m_header.version, m_header.cu_offset, m_header.addr_size, m_header.seg_size);
|
| 241 |
+
|
| 242 |
+
const uint32_t hex_width = m_header.addr_size * 2;
|
| 243 |
+
DescriptorConstIter pos;
|
| 244 |
+
DescriptorConstIter end = m_arange_descriptors.end();
|
| 245 |
+
for (pos = m_arange_descriptors.begin(); pos != end; ++pos)
|
| 246 |
+
s->Printf("[0x%*.*" PRIx64 " - 0x%*.*" PRIx64 ")\n",
|
| 247 |
+
hex_width, hex_width, pos->address,
|
| 248 |
+
hex_width, hex_width, pos->end_address());
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
class DescriptorContainsAddress
|
| 253 |
+
{
|
| 254 |
+
public:
|
| 255 |
+
DescriptorContainsAddress (dw_addr_t address) : m_address(address) {}
|
| 256 |
+
bool operator() (const DWARFDebugArangeSet::Descriptor& desc) const
|
| 257 |
+
{
|
| 258 |
+
return (m_address >= desc.address) && (m_address < (desc.address + desc.length));
|
| 259 |
+
}
|
| 260 |
+
private:
|
| 261 |
+
const dw_addr_t m_address;
|
| 262 |
+
};
|
| 263 |
+
|
| 264 |
+
dw_offset_t
|
| 265 |
+
DWARFDebugArangeSet::FindAddress(dw_addr_t address) const
|
| 266 |
+
{
|
| 267 |
+
DescriptorConstIter end = m_arange_descriptors.end();
|
| 268 |
+
DescriptorConstIter pos = std::find_if( m_arange_descriptors.begin(), end, // Range
|
| 269 |
+
DescriptorContainsAddress(address));// Predicate
|
| 270 |
+
if (pos != end)
|
| 271 |
+
return m_header.cu_offset;
|
| 272 |
+
|
| 273 |
+
return DW_INVALID_OFFSET;
|
| 274 |
+
}
|
pool/shard010/C++/0111216_lru.cc
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* \brief Least-recently-used cache replacement strategy
|
| 3 |
+
* \author Stefan Kalkowski
|
| 4 |
+
* \date 2013-12-05
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* Copyright (C) 2013 Genode Labs GmbH
|
| 9 |
+
*
|
| 10 |
+
* This file is part of the Genode OS framework, which is distributed
|
| 11 |
+
* under the terms of the GNU General Public License version 2.
|
| 12 |
+
*/
|
| 13 |
+
#include <base/printf.h>
|
| 14 |
+
#include "lru.h"
|
| 15 |
+
#include "driver.h"
|
| 16 |
+
|
| 17 |
+
typedef Driver<Lru_policy>::Chunk_level_4 Chunk;
|
| 18 |
+
|
| 19 |
+
static const Lru_policy::Element *lru = 0;
|
| 20 |
+
static Genode::List<Lru_policy::Element> lru_list;
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
static void lru_access(const Lru_policy::Element *e)
|
| 24 |
+
{
|
| 25 |
+
if (e == lru) return;
|
| 26 |
+
|
| 27 |
+
if (e->next()) lru_list.remove(e);
|
| 28 |
+
|
| 29 |
+
lru_list.insert(e, lru);
|
| 30 |
+
lru = e;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
void Lru_policy::read(const Lru_policy::Element *e) {
|
| 35 |
+
lru_access(e); }
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
void Lru_policy::write(const Lru_policy::Element *e) {
|
| 39 |
+
lru_access(e); }
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
void Lru_policy::flush(Cache::size_t size)
|
| 43 |
+
{
|
| 44 |
+
Cache::size_t s = 0;
|
| 45 |
+
for (Lru_policy::Element *e = lru_list.first();
|
| 46 |
+
e && ((size == 0) || (s < size));
|
| 47 |
+
e = lru_list.first(), s += sizeof(Chunk)) {
|
| 48 |
+
Chunk *cb = static_cast<Chunk*>(e);
|
| 49 |
+
e = e->next();
|
| 50 |
+
try {
|
| 51 |
+
cb->free(Driver<Lru_policy>::CACHE_BLK_SIZE,
|
| 52 |
+
cb->base_offset());
|
| 53 |
+
lru_list.remove(cb);
|
| 54 |
+
} catch(Chunk::Dirty_chunk &e) {
|
| 55 |
+
cb->sync(e.size, e.off);
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (!lru_list.first()) lru = 0;
|
| 60 |
+
|
| 61 |
+
if (s < size) throw Block::Driver::Request_congestion();
|
| 62 |
+
}
|
pool/shard010/C++/0111221_mirror_layer_impl.cc
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2019 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "cc/layers/mirror_layer_impl.h"
|
| 6 |
+
|
| 7 |
+
#include <memory>
|
| 8 |
+
|
| 9 |
+
#include "cc/trees/effect_node.h"
|
| 10 |
+
#include "cc/trees/layer_tree_impl.h"
|
| 11 |
+
#include "cc/trees/occlusion.h"
|
| 12 |
+
#include "components/viz/common/quads/compositor_render_pass_draw_quad.h"
|
| 13 |
+
|
| 14 |
+
namespace cc {
|
| 15 |
+
|
| 16 |
+
MirrorLayerImpl::MirrorLayerImpl(LayerTreeImpl* tree_impl, int id)
|
| 17 |
+
: LayerImpl(tree_impl, id) {}
|
| 18 |
+
|
| 19 |
+
MirrorLayerImpl::~MirrorLayerImpl() = default;
|
| 20 |
+
|
| 21 |
+
std::unique_ptr<LayerImpl> MirrorLayerImpl::CreateLayerImpl(
|
| 22 |
+
LayerTreeImpl* tree_impl) {
|
| 23 |
+
return MirrorLayerImpl::Create(tree_impl, id());
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
void MirrorLayerImpl::AppendQuads(viz::CompositorRenderPass* render_pass,
|
| 27 |
+
AppendQuadsData* append_quads_data) {
|
| 28 |
+
// TODO(mohsen): Currently, effects on the mirrored layer (e.g mask and
|
| 29 |
+
// opacity) are ignored. Consider applying them here.
|
| 30 |
+
|
| 31 |
+
auto* mirrored_layer = layer_tree_impl()->LayerById(mirrored_layer_id_);
|
| 32 |
+
auto* mirrored_render_surface =
|
| 33 |
+
GetEffectTree().GetRenderSurface(mirrored_layer->effect_tree_index());
|
| 34 |
+
gfx::Rect content_rect = mirrored_render_surface->content_rect();
|
| 35 |
+
|
| 36 |
+
gfx::Rect unoccluded_content_rect =
|
| 37 |
+
draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
|
| 38 |
+
content_rect);
|
| 39 |
+
if (unoccluded_content_rect.IsEmpty())
|
| 40 |
+
return;
|
| 41 |
+
|
| 42 |
+
const bool contents_opaque = false;
|
| 43 |
+
viz::SharedQuadState* shared_quad_state =
|
| 44 |
+
render_pass->CreateAndAppendSharedQuadState();
|
| 45 |
+
// TODO(crbug.com/1196414): Support 2D scales in mirror layers.
|
| 46 |
+
PopulateScaledSharedQuadStateWithContentRects(
|
| 47 |
+
shared_quad_state, mirrored_layer->GetIdealContentsScaleKey(),
|
| 48 |
+
content_rect, content_rect, contents_opaque);
|
| 49 |
+
|
| 50 |
+
AppendDebugBorderQuad(render_pass, content_rect, shared_quad_state,
|
| 51 |
+
append_quads_data);
|
| 52 |
+
|
| 53 |
+
viz::ResourceId mask_resource_id = viz::kInvalidResourceId;
|
| 54 |
+
gfx::RectF mask_uv_rect;
|
| 55 |
+
gfx::Size mask_texture_size;
|
| 56 |
+
|
| 57 |
+
auto* mirrored_effect_node = mirrored_render_surface->OwningEffectNode();
|
| 58 |
+
auto* quad =
|
| 59 |
+
render_pass->CreateAndAppendDrawQuad<viz::CompositorRenderPassDrawQuad>();
|
| 60 |
+
quad->SetNew(shared_quad_state, content_rect, unoccluded_content_rect,
|
| 61 |
+
mirrored_layer_render_pass_id(), mask_resource_id, mask_uv_rect,
|
| 62 |
+
mask_texture_size, mirrored_effect_node->surface_contents_scale,
|
| 63 |
+
gfx::PointF(), gfx::RectF(gfx::Rect(content_rect.size())),
|
| 64 |
+
!layer_tree_impl()->settings().enable_edge_anti_aliasing, 0.f);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
void MirrorLayerImpl::PushPropertiesTo(LayerImpl* layer) {
|
| 68 |
+
LayerImpl::PushPropertiesTo(layer);
|
| 69 |
+
|
| 70 |
+
auto* mirror_layer = static_cast<MirrorLayerImpl*>(layer);
|
| 71 |
+
mirror_layer->SetMirroredLayerId(mirrored_layer_id_);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
gfx::Rect MirrorLayerImpl::GetDamageRect() const {
|
| 75 |
+
// TOOD(mohsen): Currently, the whole layer is marked as damaged. We should
|
| 76 |
+
// only consider the damage from the mirrored layer.
|
| 77 |
+
return gfx::Rect(bounds());
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
gfx::Rect MirrorLayerImpl::GetEnclosingVisibleRectInTargetSpace() const {
|
| 81 |
+
const LayerImpl* mirrored_layer =
|
| 82 |
+
layer_tree_impl()->LayerById(mirrored_layer_id_);
|
| 83 |
+
return GetScaledEnclosingVisibleRectInTargetSpace(
|
| 84 |
+
mirrored_layer->GetIdealContentsScaleKey());
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
const char* MirrorLayerImpl::LayerTypeAsString() const {
|
| 88 |
+
return "cc::MirrorLayerImpl";
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
} // namespace cc
|
pool/shard010/C++/0111222_switch.cc
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*// us file is part of NOX.
|
| 2 |
+
*
|
| 3 |
+
* NOX is free software: you can redistribute it and/or modify
|
| 4 |
+
* it under the terms of the GNU General Public License as published by
|
| 5 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 6 |
+
* (at your option) any later version.
|
| 7 |
+
*
|
| 8 |
+
* NOX is distributed in the hope that it will be useful,
|
| 9 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 10 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 11 |
+
* GNU General Public License for more details.
|
| 12 |
+
*
|
| 13 |
+
* You should have received a copy of the GNU General Public License
|
| 14 |
+
* along with NOX. If not, see <http://www.gnu.org/licenses/>.
|
| 15 |
+
*/
|
| 16 |
+
#include <boost/bind.hpp>
|
| 17 |
+
#include <boost/foreach.hpp>
|
| 18 |
+
#include <boost/shared_array.hpp>
|
| 19 |
+
#include <cstring>
|
| 20 |
+
#include <netinet/in.h>
|
| 21 |
+
#include <stdexcept>
|
| 22 |
+
#include <stdint.h>
|
| 23 |
+
|
| 24 |
+
#include "openflow-default.hh"
|
| 25 |
+
#include "assert.hh"
|
| 26 |
+
#include "component.hh"
|
| 27 |
+
#include "flow.hh"
|
| 28 |
+
#include "fnv_hash.hh"
|
| 29 |
+
#include "hash_set.hh"
|
| 30 |
+
#include "ofp-msg-event.hh"
|
| 31 |
+
#include "vlog.hh"
|
| 32 |
+
#include "flowmod.hh"
|
| 33 |
+
#include "datapath-join.hh"
|
| 34 |
+
#include <stdio.h>
|
| 35 |
+
|
| 36 |
+
#include <stdio.h>
|
| 37 |
+
#include "netinet++/ethernetaddr.hh"
|
| 38 |
+
#include "netinet++/ethernet.hh"
|
| 39 |
+
|
| 40 |
+
#include "../../../oflib/ofl-actions.h"
|
| 41 |
+
#include "../../../oflib/ofl-messages.h"
|
| 42 |
+
|
| 43 |
+
using namespace vigil;
|
| 44 |
+
using namespace vigil::container;
|
| 45 |
+
using namespace std;
|
| 46 |
+
|
| 47 |
+
namespace {
|
| 48 |
+
|
| 49 |
+
struct Mac_source
|
| 50 |
+
{
|
| 51 |
+
/* Key. */
|
| 52 |
+
datapathid datapath_id; /* Switch. */
|
| 53 |
+
ethernetaddr mac; /* Source MAC. */
|
| 54 |
+
|
| 55 |
+
/* Value. */
|
| 56 |
+
mutable int port; /* Port where packets from 'mac' were seen. */
|
| 57 |
+
|
| 58 |
+
Mac_source() : port(-1) { }
|
| 59 |
+
Mac_source(datapathid datapath_id_, ethernetaddr mac_)
|
| 60 |
+
: datapath_id(datapath_id_), mac(mac_), port(-1)
|
| 61 |
+
{ }
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
bool operator==(const Mac_source& a, const Mac_source& b)
|
| 65 |
+
{
|
| 66 |
+
return a.datapath_id == b.datapath_id && a.mac == b.mac;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
bool operator!=(const Mac_source& a, const Mac_source& b)
|
| 70 |
+
{
|
| 71 |
+
return !(a == b);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
struct Hash_mac_source
|
| 75 |
+
{
|
| 76 |
+
std::size_t operator()(const Mac_source& val) const {
|
| 77 |
+
uint32_t x;
|
| 78 |
+
x = vigil::fnv_hash(&val.datapath_id, sizeof val.datapath_id);
|
| 79 |
+
x = vigil::fnv_hash(val.mac.octet, sizeof val.mac.octet, x);
|
| 80 |
+
return x;
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
Vlog_module log("switch");
|
| 85 |
+
|
| 86 |
+
class Switch
|
| 87 |
+
: public Component
|
| 88 |
+
{
|
| 89 |
+
public:
|
| 90 |
+
Switch(const Context* c,
|
| 91 |
+
const json_object*)
|
| 92 |
+
: Component(c) { }
|
| 93 |
+
|
| 94 |
+
void configure(const Configuration*);
|
| 95 |
+
|
| 96 |
+
void install();
|
| 97 |
+
|
| 98 |
+
Disposition handle(const Event&);
|
| 99 |
+
//Disposition handle_dp_join(const Event& e);
|
| 100 |
+
private:
|
| 101 |
+
typedef hash_set<Mac_source, Hash_mac_source> Source_table;
|
| 102 |
+
Source_table sources;
|
| 103 |
+
|
| 104 |
+
/* Set up a flow when we know the destination of a packet? This should
|
| 105 |
+
* ordinarily be true; it is only usefully false for debugging purposes. */
|
| 106 |
+
bool setup_flows;
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
void
|
| 110 |
+
Switch::configure(const Configuration* conf) {
|
| 111 |
+
setup_flows = true; // default value
|
| 112 |
+
BOOST_FOREACH (const std::string& arg, conf->get_arguments()) {
|
| 113 |
+
if (arg == "noflow") {
|
| 114 |
+
setup_flows = false;
|
| 115 |
+
} else {
|
| 116 |
+
VLOG_WARN(log, "argument \"%s\" not supported", arg.c_str());
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
register_handler(Ofp_msg_event::get_name(OFPT_PACKET_IN), boost::bind(&Switch::handle, this, _1));
|
| 121 |
+
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
void
|
| 125 |
+
Switch::install() {
|
| 126 |
+
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
Disposition
|
| 130 |
+
Switch::handle(const Event& e)
|
| 131 |
+
{
|
| 132 |
+
const Ofp_msg_event& pi = assert_cast<const Ofp_msg_event&>(e);
|
| 133 |
+
|
| 134 |
+
struct ofl_msg_packet_in *in = (struct ofl_msg_packet_in *)**pi.msg;
|
| 135 |
+
Flow *flow = new Flow((struct ofl_match*) in->match);
|
| 136 |
+
|
| 137 |
+
/* drop all LLDP packets */
|
| 138 |
+
uint16_t dl_type;
|
| 139 |
+
flow->get_Field<uint16_t>("eth_type",&dl_type);
|
| 140 |
+
if (dl_type == ethernet::LLDP){
|
| 141 |
+
return CONTINUE;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
uint32_t in_port;
|
| 145 |
+
flow->get_Field<uint32_t>("in_port", &in_port);
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
/* Learn the source. */
|
| 149 |
+
uint8_t eth_src[6];
|
| 150 |
+
flow->get_Field("eth_src", eth_src);
|
| 151 |
+
ethernetaddr dl_src(eth_src);
|
| 152 |
+
if (!dl_src.is_multicast()) {
|
| 153 |
+
Mac_source src(pi.dpid, dl_src);
|
| 154 |
+
Source_table::iterator i = sources.insert(src).first;
|
| 155 |
+
|
| 156 |
+
if (i->port != in_port) {
|
| 157 |
+
i->port = in_port;
|
| 158 |
+
VLOG_DBG(log, "learned that "EA_FMT" is on datapath %s port %d",
|
| 159 |
+
EA_ARGS(&dl_src), pi.dpid.string().c_str(),
|
| 160 |
+
(int) in_port);
|
| 161 |
+
}
|
| 162 |
+
} else {
|
| 163 |
+
VLOG_DBG(log, "multicast packet source "EA_FMT, EA_ARGS(&dl_src));
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/* Figure out the destination. */
|
| 167 |
+
int out_port = -1; /* Flood by default. */
|
| 168 |
+
uint8_t eth_dst[6];
|
| 169 |
+
flow->get_Field("eth_dst", eth_dst);
|
| 170 |
+
ethernetaddr dl_dst(eth_dst);
|
| 171 |
+
if (!dl_dst.is_multicast()) {
|
| 172 |
+
Mac_source dst(pi.dpid, dl_dst);
|
| 173 |
+
Source_table::iterator i(sources.find(dst));
|
| 174 |
+
if (i != sources.end()) {
|
| 175 |
+
out_port = i->port;
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/* Set up a flow if the output port is known. */
|
| 180 |
+
if (setup_flows && out_port != -1) {
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
Flow f;
|
| 184 |
+
f.Add_Field("in_port", in_port);
|
| 185 |
+
f.Add_Field("eth_src", eth_src);
|
| 186 |
+
f.Add_Field("eth_dst",eth_dst);
|
| 187 |
+
Actions *acts = new Actions();
|
| 188 |
+
acts->CreateOutput(out_port);
|
| 189 |
+
Instruction *inst = new Instruction();
|
| 190 |
+
inst->CreateApply(acts);
|
| 191 |
+
FlowMod *mod = new FlowMod(0x00ULL,0x00ULL, 0,OFPFC_ADD, 1, OFP_FLOW_PERMANENT, OFP_DEFAULT_PRIORITY,in->buffer_id,
|
| 192 |
+
OFPP_ANY, OFPG_ANY, ofd_flow_mod_flags());
|
| 193 |
+
mod->AddMatch(&f.match);
|
| 194 |
+
mod->AddInstructions(inst);
|
| 195 |
+
send_openflow_msg(pi.dpid, (struct ofl_msg_header *)&mod->fm_msg, 0/*xid*/, true/*block*/);
|
| 196 |
+
}
|
| 197 |
+
/* Send out packet if necessary. */
|
| 198 |
+
if (!setup_flows || out_port == -1 || in->buffer_id == UINT32_MAX) {
|
| 199 |
+
if (in->buffer_id == UINT32_MAX) {
|
| 200 |
+
if (in->total_len != in->data_length) {
|
| 201 |
+
/* Control path didn't buffer the packet and didn't send us
|
| 202 |
+
* the whole thing--what gives? */
|
| 203 |
+
VLOG_DBG(log, "total_len=%"PRIu16" data_len=%zu\n",
|
| 204 |
+
in->total_len, in->data_length);
|
| 205 |
+
return CONTINUE;
|
| 206 |
+
}
|
| 207 |
+
send_openflow_pkt(pi.dpid, Nonowning_buffer(in->data, in->data_length), in_port, out_port == -1 ? OFPP_FLOOD : out_port, true/*block*/);
|
| 208 |
+
} else {
|
| 209 |
+
send_openflow_pkt(pi.dpid, in->buffer_id, in_port, out_port == -1 ? OFPP_FLOOD : out_port, true/*block*/);
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
return CONTINUE;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
REGISTER_COMPONENT(container::Simple_component_factory<Switch>, Switch);
|
| 216 |
+
|
| 217 |
+
} // unnamed namespacennamed namespace
|
pool/shard010/C++/0111225_bitcoind.cpp
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
| 2 |
+
// Copyright (c) 2009-2012 The Bitcoin developers
|
| 3 |
+
// Distributed under the MIT/X11 software license, see the accompanying
|
| 4 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
+
|
| 6 |
+
#include "init.h"
|
| 7 |
+
#include "bitcoinrpc.h"
|
| 8 |
+
#include <boost/algorithm/string/predicate.hpp>
|
| 9 |
+
|
| 10 |
+
void DetectShutdownThread(boost::thread_group* threadGroup)
|
| 11 |
+
{
|
| 12 |
+
bool shutdown = ShutdownRequested();
|
| 13 |
+
// Tell the main threads to shutdown.
|
| 14 |
+
while (!shutdown)
|
| 15 |
+
{
|
| 16 |
+
MilliSleep(200);
|
| 17 |
+
shutdown = ShutdownRequested();
|
| 18 |
+
}
|
| 19 |
+
if (threadGroup)
|
| 20 |
+
threadGroup->interrupt_all();
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 24 |
+
//
|
| 25 |
+
// Start
|
| 26 |
+
//
|
| 27 |
+
bool AppInit(int argc, char* argv[])
|
| 28 |
+
{
|
| 29 |
+
boost::thread_group threadGroup;
|
| 30 |
+
boost::thread* detectShutdownThread = NULL;
|
| 31 |
+
|
| 32 |
+
bool fRet = false;
|
| 33 |
+
try
|
| 34 |
+
{
|
| 35 |
+
//
|
| 36 |
+
// Parameters
|
| 37 |
+
//
|
| 38 |
+
// If Qt is used, parameters/fireflycoin.conf are parsed in qt/bitcoin.cpp's main()
|
| 39 |
+
ParseParameters(argc, argv);
|
| 40 |
+
if (!boost::filesystem::is_directory(GetDataDir(false)))
|
| 41 |
+
{
|
| 42 |
+
fprintf(stderr, "Error: Specified directory does not exist\n");
|
| 43 |
+
Shutdown();
|
| 44 |
+
}
|
| 45 |
+
ReadConfigFile(mapArgs, mapMultiArgs);
|
| 46 |
+
|
| 47 |
+
if (mapArgs.count("-?") || mapArgs.count("--help"))
|
| 48 |
+
{
|
| 49 |
+
// First part of help message is specific to fireflycoind / RPC client
|
| 50 |
+
std::string strUsage = _("FireFlyCoin version") + " " + FormatFullVersion() + "\n\n" +
|
| 51 |
+
_("Usage:") + "\n" +
|
| 52 |
+
" fireflycoind [options] " + "\n" +
|
| 53 |
+
" fireflycoind [options] <command> [params] " + _("Send command to -server or fireflycoind") + "\n" +
|
| 54 |
+
" fireflycoind [options] help " + _("List commands") + "\n" +
|
| 55 |
+
" fireflycoind [options] help <command> " + _("Get help for a command") + "\n";
|
| 56 |
+
|
| 57 |
+
strUsage += "\n" + HelpMessage();
|
| 58 |
+
|
| 59 |
+
fprintf(stdout, "%s", strUsage.c_str());
|
| 60 |
+
return false;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Command-line RPC
|
| 64 |
+
for (int i = 1; i < argc; i++)
|
| 65 |
+
if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "fireflycoin:"))
|
| 66 |
+
fCommandLine = true;
|
| 67 |
+
|
| 68 |
+
if (fCommandLine)
|
| 69 |
+
{
|
| 70 |
+
if (!SelectParamsFromCommandLine()) {
|
| 71 |
+
fprintf(stderr, "Error: invalid combination of -regtest and -testnet.\n");
|
| 72 |
+
return false;
|
| 73 |
+
}
|
| 74 |
+
int ret = CommandLineRPC(argc, argv);
|
| 75 |
+
exit(ret);
|
| 76 |
+
}
|
| 77 |
+
#if !defined(WIN32)
|
| 78 |
+
fDaemon = GetBoolArg("-daemon", false);
|
| 79 |
+
if (fDaemon)
|
| 80 |
+
{
|
| 81 |
+
// Daemonize
|
| 82 |
+
pid_t pid = fork();
|
| 83 |
+
if (pid < 0)
|
| 84 |
+
{
|
| 85 |
+
fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
|
| 86 |
+
return false;
|
| 87 |
+
}
|
| 88 |
+
if (pid > 0) // Parent process, pid is child process id
|
| 89 |
+
{
|
| 90 |
+
CreatePidFile(GetPidFile(), pid);
|
| 91 |
+
return true;
|
| 92 |
+
}
|
| 93 |
+
// Child process falls through to rest of initialization
|
| 94 |
+
|
| 95 |
+
pid_t sid = setsid();
|
| 96 |
+
if (sid < 0)
|
| 97 |
+
fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
|
| 98 |
+
}
|
| 99 |
+
#endif
|
| 100 |
+
|
| 101 |
+
detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup));
|
| 102 |
+
fRet = AppInit2(threadGroup);
|
| 103 |
+
}
|
| 104 |
+
catch (std::exception& e) {
|
| 105 |
+
PrintExceptionContinue(&e, "AppInit()");
|
| 106 |
+
} catch (...) {
|
| 107 |
+
PrintExceptionContinue(NULL, "AppInit()");
|
| 108 |
+
}
|
| 109 |
+
if (!fRet) {
|
| 110 |
+
if (detectShutdownThread)
|
| 111 |
+
detectShutdownThread->interrupt();
|
| 112 |
+
threadGroup.interrupt_all();
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
if (detectShutdownThread)
|
| 116 |
+
{
|
| 117 |
+
detectShutdownThread->join();
|
| 118 |
+
delete detectShutdownThread;
|
| 119 |
+
detectShutdownThread = NULL;
|
| 120 |
+
}
|
| 121 |
+
Shutdown();
|
| 122 |
+
|
| 123 |
+
return fRet;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
extern void noui_connect();
|
| 127 |
+
int main(int argc, char* argv[])
|
| 128 |
+
{
|
| 129 |
+
bool fRet = false;
|
| 130 |
+
fHaveGUI = false;
|
| 131 |
+
|
| 132 |
+
// Connect fireflycoind signal handlers
|
| 133 |
+
noui_connect();
|
| 134 |
+
|
| 135 |
+
fRet = AppInit(argc, argv);
|
| 136 |
+
|
| 137 |
+
if (fRet && fDaemon)
|
| 138 |
+
return 0;
|
| 139 |
+
|
| 140 |
+
return (fRet ? 0 : 1);
|
| 141 |
+
}
|
pool/shard010/C++/0111231_chapter24_ex10.cpp
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Chapter 24, exercise 10: test rand(); write a program that takes two integers
|
| 2 |
+
// n and d and calls randint(n) d times; output the number of draws for each
|
| 3 |
+
// [0:n) and see if there are any obvious biases
|
| 4 |
+
|
| 5 |
+
#include<iostream>
|
| 6 |
+
#include<iomanip>
|
| 7 |
+
#include<cstdlib>
|
| 8 |
+
#include<ctime>
|
| 9 |
+
#include<map>
|
| 10 |
+
|
| 11 |
+
using namespace std;
|
| 12 |
+
|
| 13 |
+
inline int randint(int max) { return rand()%max; }
|
| 14 |
+
|
| 15 |
+
inline int randint(int min, int max) { return randint(max-min)+min; }
|
| 16 |
+
|
| 17 |
+
int main()
|
| 18 |
+
try
|
| 19 |
+
{
|
| 20 |
+
while (true) {
|
| 21 |
+
cout << "Enter biggest number: ";
|
| 22 |
+
int n;
|
| 23 |
+
cin >> n;
|
| 24 |
+
cout << "Enter number of draws (0 to exit): ";
|
| 25 |
+
int d;
|
| 26 |
+
cin >> d;
|
| 27 |
+
if (d==0) break;
|
| 28 |
+
srand(time(0));
|
| 29 |
+
|
| 30 |
+
int r = 0;
|
| 31 |
+
map<int,int> histo;
|
| 32 |
+
for (int i = 0; i<d; ++i)
|
| 33 |
+
++histo[randint(n)];
|
| 34 |
+
|
| 35 |
+
for (int i= 0; i<n; ++i) {
|
| 36 |
+
cout << setw(2) << i << ": ";
|
| 37 |
+
for (int j = 0; j<histo[i]; ++j)
|
| 38 |
+
cout << '*';
|
| 39 |
+
cout << '\n';
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
catch (exception& e) {
|
| 44 |
+
cerr << "Exception: " << e.what() << '\n';
|
| 45 |
+
}
|
| 46 |
+
catch (...) {
|
| 47 |
+
cerr << "Exception\n";
|
| 48 |
+
}
|
pool/shard010/C++/0111233_c_net_engine.cpp
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Czech_mate by Daniel
|
| 3 |
+
This file is part of Czech_mate.
|
| 4 |
+
|
| 5 |
+
Czech_mate is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU General Public License Version 2 as published by
|
| 7 |
+
the Free Software Foundation,
|
| 8 |
+
|
| 9 |
+
Czech_mate is distributed in the hope that it will be useful,
|
| 10 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
GNU General Public License for more details.
|
| 13 |
+
|
| 14 |
+
You should have received a copy of the GNU General Public License
|
| 15 |
+
along with Czech_mate. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
#include "../loop/loop_main.h"
|
| 18 |
+
#include "../class/class_main.h"
|
| 19 |
+
#include "../net/net_main.h"
|
| 20 |
+
#include "../client/c_main.h"
|
| 21 |
+
#include "../net/net_const.h"
|
| 22 |
+
#include "c_net_engine.h"
|
| 23 |
+
|
| 24 |
+
extern bool once_per_second;
|
| 25 |
+
extern bool terminate;
|
| 26 |
+
|
| 27 |
+
array_id_t host_info_id = 0;
|
| 28 |
+
array_id_t self_info_id = 0;
|
| 29 |
+
extern array_id_t self_id;
|
| 30 |
+
|
| 31 |
+
extern int_ argc_;
|
| 32 |
+
extern char **argv_;
|
| 33 |
+
|
| 34 |
+
net_t *net = nullptr;
|
| 35 |
+
|
| 36 |
+
static loop_t *net_loop_mt;
|
| 37 |
+
|
| 38 |
+
static void net_module_loop(){
|
| 39 |
+
net->loop();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
static void net_connect_send(){
|
| 43 |
+
((net_ip_connection_info_t*)find_pointer(host_info_id, "net_ip_connection_info_t"))->array.print();
|
| 44 |
+
std::string packet = ((net_ip_connection_info_t*)find_pointer(self_info_id, "net_ip_connection_info_t"))->array.gen_updated_string(INT_MAX) + NET_JOIN;
|
| 45 |
+
net->write(packet, 0, host_info_id);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
static void net_connect_receive(std::string connecting_packet){
|
| 49 |
+
if(connecting_packet != ""){
|
| 50 |
+
connecting_packet.erase(connecting_packet.begin()+connecting_packet.find_first_of(NET_JOIN));
|
| 51 |
+
self_id = std::stoi(connecting_packet);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
static void net_receive_engine(){
|
| 56 |
+
for(int_ i = 0;i < 512;i++){
|
| 57 |
+
std::string a = net->read();
|
| 58 |
+
if(a.find_first_of(NET_JOIN) != std::string::npos){
|
| 59 |
+
printf_("DEBUG: Received the NET_JOIN packet\n", PRINTF_DEBUG);
|
| 60 |
+
net_connect_receive(a);
|
| 61 |
+
}else if(a != ""){
|
| 62 |
+
update_class_data(a, ~0);
|
| 63 |
+
}else{
|
| 64 |
+
break;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
static void net_send_engine(){
|
| 70 |
+
try{
|
| 71 |
+
client_t *client_tmp = (client_t*)find_pointer(self_id, "client_t");
|
| 72 |
+
throw_if_nullptr(client_tmp);
|
| 73 |
+
client_tmp->array.data_lock.lock();
|
| 74 |
+
int_ what_to_update;
|
| 75 |
+
if(likely(once_per_second == false)){
|
| 76 |
+
client_tmp->array.updated(&what_to_update);
|
| 77 |
+
}else{
|
| 78 |
+
what_to_update = INT_MIN;
|
| 79 |
+
}
|
| 80 |
+
std::string data = client_tmp->array.gen_updated_string(what_to_update);
|
| 81 |
+
client_tmp->array.data_lock.unlock();
|
| 82 |
+
net->write(data.c_str(), 0, host_info_id);
|
| 83 |
+
}catch(const std::logic_error &e){
|
| 84 |
+
printf_("WARNING: self_id isn't valid, this should pass\n", PRINTF_UNLIKELY_WARN);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
void net_init(){
|
| 89 |
+
loop_add(loop, loop_generate_entry(0, "net_engine", net_engine));
|
| 90 |
+
net_loop_mt = new loop_t;
|
| 91 |
+
loop_add(net_loop_mt, loop_generate_entry(LOOP_CODE_PARTIAL_MT, "net_module_loop", net_module_loop));
|
| 92 |
+
loop_add(net_loop_mt, loop_generate_entry(LOOP_CODE_PARTIAL_MT, "net_receive_engine", net_receive_engine));
|
| 93 |
+
loop_add(net_loop_mt, loop_generate_entry(LOOP_CODE_PARTIAL_MT, "net_send_engine", net_send_engine));
|
| 94 |
+
net_ip_connection_info_t *self_info = new net_ip_connection_info_t;
|
| 95 |
+
net_ip_connection_info_t *host_info = new net_ip_connection_info_t;
|
| 96 |
+
self_info->array.data_lock.lock();
|
| 97 |
+
host_info->array.data_lock.lock();
|
| 98 |
+
host_info_id = host_info->array.id;
|
| 99 |
+
self_info_id = self_info->array.id;
|
| 100 |
+
host_info->ip = "127.0.0.1"; // don't delete the host
|
| 101 |
+
self_info->ip = "127.0.0.1"; // the IP address that the server should be sending data to
|
| 102 |
+
host_info->port = NET_SERVER_PORT;
|
| 103 |
+
self_info->port = NET_CLIENT_PORT;
|
| 104 |
+
self_info->array.data_lock.unlock();
|
| 105 |
+
host_info->array.data_lock.unlock();
|
| 106 |
+
bool force_ip = false;
|
| 107 |
+
for(int_ i = 0;i < argc_;i++){
|
| 108 |
+
std::string next_item;
|
| 109 |
+
if(i+1 < argc_){
|
| 110 |
+
next_item = argv_[i+1];
|
| 111 |
+
}else{
|
| 112 |
+
next_item = "";
|
| 113 |
+
}
|
| 114 |
+
if(strcmp(argv_[i], (char*)"--net-ip-server-ip") == 0){
|
| 115 |
+
host_info->ip = (std::string)argv_[i+1];
|
| 116 |
+
}else if(strcmp(argv_[i], (char*)"--net-ip-server-port") == 0){
|
| 117 |
+
host_info->port = atoi((char*)argv_[i+1]);
|
| 118 |
+
}else if(strcmp(argv_[i], (char*)"--net-ip-client-ip") == 0){
|
| 119 |
+
if(next_item != ""){
|
| 120 |
+
force_ip = true;
|
| 121 |
+
self_info->ip = next_item.c_str();
|
| 122 |
+
}
|
| 123 |
+
}else if(strcmp(argv_[i], (char*)"--net-ip-client-port") == 0){
|
| 124 |
+
if(next_item != ""){
|
| 125 |
+
self_info->port = atoi(next_item.c_str());
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
if(next_item == ""){
|
| 129 |
+
printf("There is no next object\n");
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
if(force_ip == false){
|
| 133 |
+
self_info->array.data_lock.lock();
|
| 134 |
+
self_info->ip = net_gen_ip_address(host_info->ip);
|
| 135 |
+
self_info->array.data_lock.unlock();
|
| 136 |
+
}
|
| 137 |
+
net = new net_t();
|
| 138 |
+
net->set_inbound_info(self_info_id);
|
| 139 |
+
net_connect_send();
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
void net_engine(){
|
| 143 |
+
loop_run(net_loop_mt);
|
| 144 |
+
/*
|
| 145 |
+
net_connect_receive is called from inside this loop.
|
| 146 |
+
there is no need for first-run code or anything like it
|
| 147 |
+
*/
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
void net_close(){
|
| 151 |
+
if(likely(net != nullptr)){
|
| 152 |
+
delete net;
|
| 153 |
+
net = nullptr;
|
| 154 |
+
}
|
| 155 |
+
loop_del(net_loop_mt, net_module_loop);
|
| 156 |
+
loop_del(net_loop_mt, net_send_engine);
|
| 157 |
+
loop_del(net_loop_mt, net_receive_engine);
|
| 158 |
+
loop_del(loop, net_engine);
|
| 159 |
+
}
|
pool/shard010/C++/0111234_print_preview_data_source.cc
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "chrome/browser/ui/webui/print_preview/print_preview_data_source.h"
|
| 6 |
+
|
| 7 |
+
#include <algorithm>
|
| 8 |
+
#include <vector>
|
| 9 |
+
|
| 10 |
+
#include "base/message_loop.h"
|
| 11 |
+
#include "base/string_number_conversions.h"
|
| 12 |
+
#include "base/string_piece.h"
|
| 13 |
+
#include "base/string_split.h"
|
| 14 |
+
#include "base/string_util.h"
|
| 15 |
+
#include "base/utf_string_conversions.h"
|
| 16 |
+
#include "base/values.h"
|
| 17 |
+
#include "chrome/browser/printing/print_preview_data_service.h"
|
| 18 |
+
#include "chrome/common/url_constants.h"
|
| 19 |
+
#include "grit/browser_resources.h"
|
| 20 |
+
#include "grit/chromium_strings.h"
|
| 21 |
+
#include "grit/generated_resources.h"
|
| 22 |
+
#include "grit/google_chrome_strings.h"
|
| 23 |
+
#include "ui/base/l10n/l10n_util.h"
|
| 24 |
+
#include "ui/base/resource/resource_bundle.h"
|
| 25 |
+
|
| 26 |
+
namespace {
|
| 27 |
+
|
| 28 |
+
#if defined(OS_MACOSX)
|
| 29 |
+
// U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8
|
| 30 |
+
const char kAdvancedPrintShortcut[] = "\x28\xE2\x8c\xA5\xE2\x8C\x98\x50\x29";
|
| 31 |
+
#elif defined(OS_WIN)
|
| 32 |
+
const char kAdvancedPrintShortcut[] = "(Ctrl+Shift+P)";
|
| 33 |
+
#else
|
| 34 |
+
const char kAdvancedPrintShortcut[] = "(Shift+Ctrl+P)";
|
| 35 |
+
#endif
|
| 36 |
+
|
| 37 |
+
}; // namespace
|
| 38 |
+
|
| 39 |
+
PrintPreviewDataSource::PrintPreviewDataSource(bool is_dummy)
|
| 40 |
+
: ChromeWebUIDataSource(chrome::kChromeUIPrintHost) {
|
| 41 |
+
Init(is_dummy);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void PrintPreviewDataSource::Init(bool is_dummy) {
|
| 45 |
+
if (is_dummy) {
|
| 46 |
+
AddLocalizedString("intentionallyBlankText",
|
| 47 |
+
IDS_PRINT_PREVIEW_INTENTIONALLY_BLANK);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
AddLocalizedString("title", IDS_PRINT_PREVIEW_TITLE);
|
| 51 |
+
AddLocalizedString("loading", IDS_PRINT_PREVIEW_LOADING);
|
| 52 |
+
AddLocalizedString("noPlugin", IDS_PRINT_PREVIEW_NO_PLUGIN);
|
| 53 |
+
AddLocalizedString("launchNativeDialog", IDS_PRINT_PREVIEW_NATIVE_DIALOG);
|
| 54 |
+
AddLocalizedString("previewFailed", IDS_PRINT_PREVIEW_FAILED);
|
| 55 |
+
AddLocalizedString("invalidPrinterSettings",
|
| 56 |
+
IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS);
|
| 57 |
+
AddLocalizedString("printButton", IDS_PRINT_PREVIEW_PRINT_BUTTON);
|
| 58 |
+
AddLocalizedString("saveButton", IDS_PRINT_PREVIEW_SAVE_BUTTON);
|
| 59 |
+
AddLocalizedString("cancelButton", IDS_PRINT_PREVIEW_CANCEL_BUTTON);
|
| 60 |
+
AddLocalizedString("printing", IDS_PRINT_PREVIEW_PRINTING);
|
| 61 |
+
AddLocalizedString("printingToPDFInProgress",
|
| 62 |
+
IDS_PRINT_PREVIEW_PRINTING_TO_PDF_IN_PROGRESS);
|
| 63 |
+
#if defined(OS_MACOSX)
|
| 64 |
+
AddLocalizedString("openingPDFInPreview",
|
| 65 |
+
IDS_PRINT_PREVIEW_OPENING_PDF_IN_PREVIEW);
|
| 66 |
+
#endif
|
| 67 |
+
AddLocalizedString("destinationLabel", IDS_PRINT_PREVIEW_DESTINATION_LABEL);
|
| 68 |
+
AddLocalizedString("copiesLabel", IDS_PRINT_PREVIEW_COPIES_LABEL);
|
| 69 |
+
AddLocalizedString("examplePageRangeText",
|
| 70 |
+
IDS_PRINT_PREVIEW_EXAMPLE_PAGE_RANGE_TEXT);
|
| 71 |
+
AddLocalizedString("layoutLabel", IDS_PRINT_PREVIEW_LAYOUT_LABEL);
|
| 72 |
+
AddLocalizedString("optionAllPages", IDS_PRINT_PREVIEW_OPTION_ALL_PAGES);
|
| 73 |
+
AddLocalizedString("optionBw", IDS_PRINT_PREVIEW_OPTION_BW);
|
| 74 |
+
AddLocalizedString("optionCollate", IDS_PRINT_PREVIEW_OPTION_COLLATE);
|
| 75 |
+
AddLocalizedString("optionColor", IDS_PRINT_PREVIEW_OPTION_COLOR);
|
| 76 |
+
AddLocalizedString("optionLandscape", IDS_PRINT_PREVIEW_OPTION_LANDSCAPE);
|
| 77 |
+
AddLocalizedString("optionPortrait", IDS_PRINT_PREVIEW_OPTION_PORTRAIT);
|
| 78 |
+
AddLocalizedString("optionTwoSided", IDS_PRINT_PREVIEW_OPTION_TWO_SIDED);
|
| 79 |
+
AddLocalizedString("pagesLabel", IDS_PRINT_PREVIEW_PAGES_LABEL);
|
| 80 |
+
AddLocalizedString("pageRangeTextBox", IDS_PRINT_PREVIEW_PAGE_RANGE_TEXT);
|
| 81 |
+
AddLocalizedString("pageRangeRadio", IDS_PRINT_PREVIEW_PAGE_RANGE_RADIO);
|
| 82 |
+
AddLocalizedString("printToPDF", IDS_PRINT_PREVIEW_PRINT_TO_PDF);
|
| 83 |
+
AddLocalizedString("printPreviewTitleFormat", IDS_PRINT_PREVIEW_TITLE_FORMAT);
|
| 84 |
+
AddLocalizedString("printPreviewSummaryFormatShort",
|
| 85 |
+
IDS_PRINT_PREVIEW_SUMMARY_FORMAT_SHORT);
|
| 86 |
+
AddLocalizedString("printPreviewSummaryFormatLong",
|
| 87 |
+
IDS_PRINT_PREVIEW_SUMMARY_FORMAT_LONG);
|
| 88 |
+
AddLocalizedString("printPreviewSheetsLabelSingular",
|
| 89 |
+
IDS_PRINT_PREVIEW_SHEETS_LABEL_SINGULAR);
|
| 90 |
+
AddLocalizedString("printPreviewSheetsLabelPlural",
|
| 91 |
+
IDS_PRINT_PREVIEW_SHEETS_LABEL_PLURAL);
|
| 92 |
+
AddLocalizedString("printPreviewPageLabelSingular",
|
| 93 |
+
IDS_PRINT_PREVIEW_PAGE_LABEL_SINGULAR);
|
| 94 |
+
AddLocalizedString("printPreviewPageLabelPlural",
|
| 95 |
+
IDS_PRINT_PREVIEW_PAGE_LABEL_PLURAL);
|
| 96 |
+
const string16 shortcut_text(UTF8ToUTF16(kAdvancedPrintShortcut));
|
| 97 |
+
#if defined(OS_CHROMEOS)
|
| 98 |
+
AddString("cloudPrintDialogOption", l10n_util::GetStringFUTF16(
|
| 99 |
+
IDS_PRINT_PREVIEW_CLOUD_DIALOG_OPTION,
|
| 100 |
+
l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT),
|
| 101 |
+
shortcut_text));
|
| 102 |
+
AddLocalizedString("printWithCloudPrint",
|
| 103 |
+
IDS_PRINT_PREVIEW_MORE_PRINTERS);
|
| 104 |
+
#else
|
| 105 |
+
AddString("systemDialogOption", l10n_util::GetStringFUTF16(
|
| 106 |
+
IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION,
|
| 107 |
+
shortcut_text));
|
| 108 |
+
AddString("printWithCloudPrint", l10n_util::GetStringFUTF16(
|
| 109 |
+
IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT,
|
| 110 |
+
l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
|
| 111 |
+
#endif
|
| 112 |
+
#if defined(OS_MACOSX)
|
| 113 |
+
AddLocalizedString("openPdfInPreviewOption",
|
| 114 |
+
IDS_PRINT_PREVIEW_OPEN_PDF_IN_PREVIEW_APP);
|
| 115 |
+
#endif
|
| 116 |
+
AddString("printWithCloudPrintWait", l10n_util::GetStringFUTF16(
|
| 117 |
+
IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT_WAIT,
|
| 118 |
+
l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
|
| 119 |
+
AddLocalizedString("pageRangeInstruction",
|
| 120 |
+
IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION);
|
| 121 |
+
AddLocalizedString("copiesInstruction", IDS_PRINT_PREVIEW_COPIES_INSTRUCTION);
|
| 122 |
+
AddLocalizedString("signIn", IDS_PRINT_PREVIEW_SIGN_IN);
|
| 123 |
+
AddLocalizedString("managePrinters", IDS_PRINT_PREVIEW_MANAGE_PRINTERS);
|
| 124 |
+
AddLocalizedString("incrementTitle", IDS_PRINT_PREVIEW_INCREMENT_TITLE);
|
| 125 |
+
AddLocalizedString("decrementTitle", IDS_PRINT_PREVIEW_DECREMENT_TITLE);
|
| 126 |
+
AddLocalizedString("printPagesLabel", IDS_PRINT_PREVIEW_PRINT_PAGES_LABEL);
|
| 127 |
+
AddLocalizedString("optionsLabel", IDS_PRINT_PREVIEW_OPTIONS_LABEL);
|
| 128 |
+
AddLocalizedString("optionHeaderFooter",
|
| 129 |
+
IDS_PRINT_PREVIEW_OPTION_HEADER_FOOTER);
|
| 130 |
+
AddLocalizedString("marginsLabel", IDS_PRINT_PREVIEW_MARGINS_LABEL);
|
| 131 |
+
AddLocalizedString("defaultMargins", IDS_PRINT_PREVIEW_DEFAULT_MARGINS);
|
| 132 |
+
AddLocalizedString("noMargins", IDS_PRINT_PREVIEW_NO_MARGINS);
|
| 133 |
+
AddLocalizedString("customMargins", IDS_PRINT_PREVIEW_CUSTOM_MARGINS);
|
| 134 |
+
AddLocalizedString("minimumMargins", IDS_PRINT_PREVIEW_MINIMUM_MARGINS);
|
| 135 |
+
AddLocalizedString("top", IDS_PRINT_PREVIEW_TOP_MARGIN_LABEL);
|
| 136 |
+
AddLocalizedString("bottom", IDS_PRINT_PREVIEW_BOTTOM_MARGIN_LABEL);
|
| 137 |
+
AddLocalizedString("left", IDS_PRINT_PREVIEW_LEFT_MARGIN_LABEL);
|
| 138 |
+
AddLocalizedString("right", IDS_PRINT_PREVIEW_RIGHT_MARGIN_LABEL);
|
| 139 |
+
|
| 140 |
+
set_json_path("strings.js");
|
| 141 |
+
if (is_dummy) {
|
| 142 |
+
add_resource_path("print_preview_dummy.js", IDR_PRINT_PREVIEW_DUMMY_JS);
|
| 143 |
+
set_default_resource(IDR_PRINT_PREVIEW_DUMMY_HTML);
|
| 144 |
+
} else {
|
| 145 |
+
add_resource_path("print_preview.js", IDR_PRINT_PREVIEW_JS);
|
| 146 |
+
set_default_resource(IDR_PRINT_PREVIEW_HTML);
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
PrintPreviewDataSource::~PrintPreviewDataSource() {
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
void PrintPreviewDataSource::StartDataRequest(const std::string& path,
|
| 154 |
+
bool is_incognito,
|
| 155 |
+
int request_id) {
|
| 156 |
+
// Parent class handles most requests except for the print preview data.
|
| 157 |
+
if (!EndsWith(path, "/print.pdf", true)) {
|
| 158 |
+
ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id);
|
| 159 |
+
return;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
// Print Preview data.
|
| 163 |
+
scoped_refptr<RefCountedBytes> data;
|
| 164 |
+
std::vector<std::string> url_substr;
|
| 165 |
+
base::SplitString(path, '/', &url_substr);
|
| 166 |
+
int page_index = 0;
|
| 167 |
+
if (url_substr.size() == 3 && base::StringToInt(url_substr[1], &page_index)) {
|
| 168 |
+
PrintPreviewDataService::GetInstance()->GetDataEntry(
|
| 169 |
+
url_substr[0], page_index, &data);
|
| 170 |
+
}
|
| 171 |
+
if (data.get()) {
|
| 172 |
+
SendResponse(request_id, data);
|
| 173 |
+
return;
|
| 174 |
+
}
|
| 175 |
+
// Invalid request.
|
| 176 |
+
scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
|
| 177 |
+
SendResponse(request_id, empty_bytes);
|
| 178 |
+
}
|
pool/shard010/C++/0111244_CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82a.cpp
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82a.cpp
|
| 3 |
+
Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE193.label.xml
|
| 4 |
+
Template File: sources-sink-82a.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 121 Stack Based Buffer Overflow
|
| 9 |
+
* BadSource: Point data to a buffer that does not have space for a NULL terminator
|
| 10 |
+
* GoodSource: Point data to a buffer that includes space for a NULL terminator
|
| 11 |
+
* Sinks: loop
|
| 12 |
+
* BadSink : Copy array to data using a loop
|
| 13 |
+
* Flow Variant: 82 Data flow: data passed in a parameter to an virtual method called via a pointer
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
#include "CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82.h"
|
| 19 |
+
|
| 20 |
+
namespace CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82
|
| 21 |
+
{
|
| 22 |
+
|
| 23 |
+
#ifndef OMITBAD
|
| 24 |
+
|
| 25 |
+
void bad()
|
| 26 |
+
{
|
| 27 |
+
wchar_t * data;
|
| 28 |
+
wchar_t dataBadBuffer[10];
|
| 29 |
+
wchar_t dataGoodBuffer[10+1];
|
| 30 |
+
/* FLAW: Set a pointer to a buffer that does not leave room for a NULL terminator when performing
|
| 31 |
+
* string copies in the sinks */
|
| 32 |
+
data = dataBadBuffer;
|
| 33 |
+
data[0] = L'\0'; /* null terminate */
|
| 34 |
+
CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82_base* baseObject = new CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82_bad;
|
| 35 |
+
baseObject->action(data);
|
| 36 |
+
delete baseObject;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
#endif /* OMITBAD */
|
| 40 |
+
|
| 41 |
+
#ifndef OMITGOOD
|
| 42 |
+
|
| 43 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 44 |
+
static void goodG2B()
|
| 45 |
+
{
|
| 46 |
+
wchar_t * data;
|
| 47 |
+
wchar_t dataBadBuffer[10];
|
| 48 |
+
wchar_t dataGoodBuffer[10+1];
|
| 49 |
+
/* FIX: Set a pointer to a buffer that leaves room for a NULL terminator when performing
|
| 50 |
+
* string copies in the sinks */
|
| 51 |
+
data = dataGoodBuffer;
|
| 52 |
+
data[0] = L'\0'; /* null terminate */
|
| 53 |
+
CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82_base* baseObject = new CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82_goodG2B;
|
| 54 |
+
baseObject->action(data);
|
| 55 |
+
delete baseObject;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void good()
|
| 59 |
+
{
|
| 60 |
+
goodG2B();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
#endif /* OMITGOOD */
|
| 64 |
+
|
| 65 |
+
} /* close namespace */
|
| 66 |
+
|
| 67 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 68 |
+
* its own for testing or for building a binary to use in testing binary
|
| 69 |
+
* analysis tools. It is not used when compiling all the testcases as one
|
| 70 |
+
* application, which is how source code analysis tools are tested.
|
| 71 |
+
*/
|
| 72 |
+
|
| 73 |
+
#ifdef INCLUDEMAIN
|
| 74 |
+
|
| 75 |
+
using namespace CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_declare_loop_82; /* so that we can use good and bad easily */
|
| 76 |
+
|
| 77 |
+
int main(int argc, char * argv[])
|
| 78 |
+
{
|
| 79 |
+
/* seed randomness */
|
| 80 |
+
srand( (unsigned)time(NULL) );
|
| 81 |
+
#ifndef OMITGOOD
|
| 82 |
+
printLine("Calling good()...");
|
| 83 |
+
good();
|
| 84 |
+
printLine("Finished good()");
|
| 85 |
+
#endif /* OMITGOOD */
|
| 86 |
+
#ifndef OMITBAD
|
| 87 |
+
printLine("Calling bad()...");
|
| 88 |
+
bad();
|
| 89 |
+
printLine("Finished bad()");
|
| 90 |
+
#endif /* OMITBAD */
|
| 91 |
+
return 0;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#endif
|
pool/shard010/C++/0111246_call_combiner.cc
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
*
|
| 3 |
+
* Copyright 2017 gRPC authors.
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
* you may not use this file except in compliance with the License.
|
| 7 |
+
* You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
#include "src/core/lib/iomgr/call_combiner.h"
|
| 20 |
+
|
| 21 |
+
#include <inttypes.h>
|
| 22 |
+
|
| 23 |
+
#include <grpc/support/log.h>
|
| 24 |
+
#include "src/core/lib/debug/stats.h"
|
| 25 |
+
#include "src/core/lib/profiling/timers.h"
|
| 26 |
+
|
| 27 |
+
grpc_core::TraceFlag grpc_call_combiner_trace(false, "call_combiner");
|
| 28 |
+
|
| 29 |
+
static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) {
|
| 30 |
+
if (cancel_state & 1) {
|
| 31 |
+
return (grpc_error*)(cancel_state & ~(gpr_atm)1);
|
| 32 |
+
}
|
| 33 |
+
return GRPC_ERROR_NONE;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
static gpr_atm encode_cancel_state_error(grpc_error* error) {
|
| 37 |
+
return (gpr_atm)1 | (gpr_atm)error;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void grpc_call_combiner_init(grpc_call_combiner* call_combiner) {
|
| 41 |
+
gpr_mpscq_init(&call_combiner->queue);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void grpc_call_combiner_destroy(grpc_call_combiner* call_combiner) {
|
| 45 |
+
gpr_mpscq_destroy(&call_combiner->queue);
|
| 46 |
+
GRPC_ERROR_UNREF(decode_cancel_state_error(call_combiner->cancel_state));
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#ifndef NDEBUG
|
| 50 |
+
#define DEBUG_ARGS , const char *file, int line
|
| 51 |
+
#define DEBUG_FMT_STR "%s:%d: "
|
| 52 |
+
#define DEBUG_FMT_ARGS , file, line
|
| 53 |
+
#else
|
| 54 |
+
#define DEBUG_ARGS
|
| 55 |
+
#define DEBUG_FMT_STR
|
| 56 |
+
#define DEBUG_FMT_ARGS
|
| 57 |
+
#endif
|
| 58 |
+
|
| 59 |
+
void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx,
|
| 60 |
+
grpc_call_combiner* call_combiner,
|
| 61 |
+
grpc_closure* closure,
|
| 62 |
+
grpc_error* error DEBUG_ARGS,
|
| 63 |
+
const char* reason) {
|
| 64 |
+
GPR_TIMER_BEGIN("call_combiner_start", 0);
|
| 65 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 66 |
+
gpr_log(GPR_DEBUG,
|
| 67 |
+
"==> grpc_call_combiner_start() [%p] closure=%p [" DEBUG_FMT_STR
|
| 68 |
+
"%s] error=%s",
|
| 69 |
+
call_combiner, closure DEBUG_FMT_ARGS, reason,
|
| 70 |
+
grpc_error_string(error));
|
| 71 |
+
}
|
| 72 |
+
size_t prev_size =
|
| 73 |
+
(size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1);
|
| 74 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 75 |
+
gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
|
| 76 |
+
prev_size + 1);
|
| 77 |
+
}
|
| 78 |
+
GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx);
|
| 79 |
+
if (prev_size == 0) {
|
| 80 |
+
GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx);
|
| 81 |
+
GPR_TIMER_MARK("call_combiner_initiate", 0);
|
| 82 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 83 |
+
gpr_log(GPR_DEBUG, " EXECUTING IMMEDIATELY");
|
| 84 |
+
}
|
| 85 |
+
// Queue was empty, so execute this closure immediately.
|
| 86 |
+
GRPC_CLOSURE_SCHED(exec_ctx, closure, error);
|
| 87 |
+
} else {
|
| 88 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 89 |
+
gpr_log(GPR_INFO, " QUEUING");
|
| 90 |
+
}
|
| 91 |
+
// Queue was not empty, so add closure to queue.
|
| 92 |
+
closure->error_data.error = error;
|
| 93 |
+
gpr_mpscq_push(&call_combiner->queue, (gpr_mpscq_node*)closure);
|
| 94 |
+
}
|
| 95 |
+
GPR_TIMER_END("call_combiner_start", 0);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx,
|
| 99 |
+
grpc_call_combiner* call_combiner DEBUG_ARGS,
|
| 100 |
+
const char* reason) {
|
| 101 |
+
GPR_TIMER_BEGIN("call_combiner_stop", 0);
|
| 102 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 103 |
+
gpr_log(GPR_DEBUG,
|
| 104 |
+
"==> grpc_call_combiner_stop() [%p] [" DEBUG_FMT_STR "%s]",
|
| 105 |
+
call_combiner DEBUG_FMT_ARGS, reason);
|
| 106 |
+
}
|
| 107 |
+
size_t prev_size =
|
| 108 |
+
(size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1);
|
| 109 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 110 |
+
gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
|
| 111 |
+
prev_size - 1);
|
| 112 |
+
}
|
| 113 |
+
GPR_ASSERT(prev_size >= 1);
|
| 114 |
+
if (prev_size > 1) {
|
| 115 |
+
while (true) {
|
| 116 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 117 |
+
gpr_log(GPR_DEBUG, " checking queue");
|
| 118 |
+
}
|
| 119 |
+
bool empty;
|
| 120 |
+
grpc_closure* closure = (grpc_closure*)gpr_mpscq_pop_and_check_end(
|
| 121 |
+
&call_combiner->queue, &empty);
|
| 122 |
+
if (closure == nullptr) {
|
| 123 |
+
// This can happen either due to a race condition within the mpscq
|
| 124 |
+
// code or because of a race with grpc_call_combiner_start().
|
| 125 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 126 |
+
gpr_log(GPR_DEBUG, " queue returned no result; checking again");
|
| 127 |
+
}
|
| 128 |
+
continue;
|
| 129 |
+
}
|
| 130 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 131 |
+
gpr_log(GPR_DEBUG, " EXECUTING FROM QUEUE: closure=%p error=%s",
|
| 132 |
+
closure, grpc_error_string(closure->error_data.error));
|
| 133 |
+
}
|
| 134 |
+
GRPC_CLOSURE_SCHED(exec_ctx, closure, closure->error_data.error);
|
| 135 |
+
break;
|
| 136 |
+
}
|
| 137 |
+
} else if (grpc_call_combiner_trace.enabled()) {
|
| 138 |
+
gpr_log(GPR_DEBUG, " queue empty");
|
| 139 |
+
}
|
| 140 |
+
GPR_TIMER_END("call_combiner_stop", 0);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx,
|
| 144 |
+
grpc_call_combiner* call_combiner,
|
| 145 |
+
grpc_closure* closure) {
|
| 146 |
+
GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL(exec_ctx);
|
| 147 |
+
while (true) {
|
| 148 |
+
// Decode original state.
|
| 149 |
+
gpr_atm original_state = gpr_atm_acq_load(&call_combiner->cancel_state);
|
| 150 |
+
grpc_error* original_error = decode_cancel_state_error(original_state);
|
| 151 |
+
// If error is set, invoke the cancellation closure immediately.
|
| 152 |
+
// Otherwise, store the new closure.
|
| 153 |
+
if (original_error != GRPC_ERROR_NONE) {
|
| 154 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 155 |
+
gpr_log(GPR_DEBUG,
|
| 156 |
+
"call_combiner=%p: scheduling notify_on_cancel callback=%p "
|
| 157 |
+
"for pre-existing cancellation",
|
| 158 |
+
call_combiner, closure);
|
| 159 |
+
}
|
| 160 |
+
GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_REF(original_error));
|
| 161 |
+
break;
|
| 162 |
+
} else {
|
| 163 |
+
if (gpr_atm_full_cas(&call_combiner->cancel_state, original_state,
|
| 164 |
+
(gpr_atm)closure)) {
|
| 165 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 166 |
+
gpr_log(GPR_DEBUG, "call_combiner=%p: setting notify_on_cancel=%p",
|
| 167 |
+
call_combiner, closure);
|
| 168 |
+
}
|
| 169 |
+
// If we replaced an earlier closure, invoke the original
|
| 170 |
+
// closure with GRPC_ERROR_NONE. This allows callers to clean
|
| 171 |
+
// up any resources they may be holding for the callback.
|
| 172 |
+
if (original_state != 0) {
|
| 173 |
+
closure = (grpc_closure*)original_state;
|
| 174 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 175 |
+
gpr_log(GPR_DEBUG,
|
| 176 |
+
"call_combiner=%p: scheduling old cancel callback=%p",
|
| 177 |
+
call_combiner, closure);
|
| 178 |
+
}
|
| 179 |
+
GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE);
|
| 180 |
+
}
|
| 181 |
+
break;
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
// cas failed, try again.
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx,
|
| 189 |
+
grpc_call_combiner* call_combiner,
|
| 190 |
+
grpc_error* error) {
|
| 191 |
+
GRPC_STATS_INC_CALL_COMBINER_CANCELLED(exec_ctx);
|
| 192 |
+
while (true) {
|
| 193 |
+
gpr_atm original_state = gpr_atm_acq_load(&call_combiner->cancel_state);
|
| 194 |
+
grpc_error* original_error = decode_cancel_state_error(original_state);
|
| 195 |
+
if (original_error != GRPC_ERROR_NONE) {
|
| 196 |
+
GRPC_ERROR_UNREF(error);
|
| 197 |
+
break;
|
| 198 |
+
}
|
| 199 |
+
if (gpr_atm_full_cas(&call_combiner->cancel_state, original_state,
|
| 200 |
+
encode_cancel_state_error(error))) {
|
| 201 |
+
if (original_state != 0) {
|
| 202 |
+
grpc_closure* notify_on_cancel = (grpc_closure*)original_state;
|
| 203 |
+
if (grpc_call_combiner_trace.enabled()) {
|
| 204 |
+
gpr_log(GPR_DEBUG,
|
| 205 |
+
"call_combiner=%p: scheduling notify_on_cancel callback=%p",
|
| 206 |
+
call_combiner, notify_on_cancel);
|
| 207 |
+
}
|
| 208 |
+
GRPC_CLOSURE_SCHED(exec_ctx, notify_on_cancel, GRPC_ERROR_REF(error));
|
| 209 |
+
}
|
| 210 |
+
break;
|
| 211 |
+
}
|
| 212 |
+
// cas failed, try again.
|
| 213 |
+
}
|
| 214 |
+
}
|
pool/shard010/C++/0111247_Settings.cpp
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <Arduino.h>
|
| 2 |
+
#include <EEPROM.h>
|
| 3 |
+
|
| 4 |
+
#if defined(ESP8266)
|
| 5 |
+
#include <ESP8266WiFi.h>
|
| 6 |
+
#endif
|
| 7 |
+
|
| 8 |
+
#include "Settings.h"
|
| 9 |
+
|
| 10 |
+
SettingsClass Settings;
|
| 11 |
+
|
| 12 |
+
static const size_t EEPROM_SIZE = 512;
|
| 13 |
+
|
| 14 |
+
void SettingsClass::begin() {
|
| 15 |
+
#if defined(ESP8266)
|
| 16 |
+
EEPROM.begin(EEPROM_SIZE);
|
| 17 |
+
#else
|
| 18 |
+
EEPROM.begin();
|
| 19 |
+
#endif
|
| 20 |
+
EEPROM.get(0, *this);
|
| 21 |
+
|
| 22 |
+
// Populate defaults if flash magic is unexpected
|
| 23 |
+
if (magic != FLASH_MAGIC) {
|
| 24 |
+
if (magic != FLASH_MAGIC_R2) {
|
| 25 |
+
if (magic != FLASH_MAGIC_R1) {
|
| 26 |
+
bzero(this, sizeof(*this));
|
| 27 |
+
#if defined(ESP8266)
|
| 28 |
+
uint8_t mac[WL_MAC_ADDR_LENGTH];
|
| 29 |
+
WiFi.macAddress(mac);
|
| 30 |
+
sprintf(hostname, "espclock%02x", mac[WL_MAC_ADDR_LENGTH-1]);
|
| 31 |
+
#else
|
| 32 |
+
strcpy(hostname, "espclock");
|
| 33 |
+
#endif
|
| 34 |
+
strcpy(ntp_hostname, "us.pool.ntp.org");
|
| 35 |
+
}
|
| 36 |
+
memset(preset_r, 0xff, sizeof(preset_r));
|
| 37 |
+
memset(preset_g, 0xff, sizeof(preset_g));
|
| 38 |
+
memset(preset_b, 0xff, sizeof(preset_b));
|
| 39 |
+
memset(preset_w, 0xff, sizeof(preset_w));
|
| 40 |
+
}
|
| 41 |
+
bzero(owm_apikey, sizeof(owm_apikey));
|
| 42 |
+
|
| 43 |
+
magic = FLASH_MAGIC;
|
| 44 |
+
save(); // Is this really necessary?
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void SettingsClass::save() {
|
| 49 |
+
EEPROM.put(0, *this);
|
| 50 |
+
#if defined(ESP8266)
|
| 51 |
+
EEPROM.commit();
|
| 52 |
+
#endif
|
| 53 |
+
}
|
| 54 |
+
|
pool/shard010/C++/0111251_platform.cpp
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "platform.h"
|
| 2 |
+
#include <allegro5/allegro_primitives.h>
|
| 3 |
+
#include <iostream>
|
| 4 |
+
#include <cmath>
|
| 5 |
+
|
| 6 |
+
Platform::Platform()
|
| 7 |
+
{
|
| 8 |
+
collision_loop = false;
|
| 9 |
+
position.x = 0;
|
| 10 |
+
position.y = 0;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
void Platform::Draw(Vector2 camera, ALLEGRO_COLOR c)
|
| 14 |
+
{
|
| 15 |
+
int np = collision_vertices.size();
|
| 16 |
+
if(np == 0)
|
| 17 |
+
{
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
Vector2 pn = collision_vertices[0];
|
| 21 |
+
Vector2 ps, pe;
|
| 22 |
+
float angle = 0;
|
| 23 |
+
ps.x = cos(angle)*pn.x - sin(angle)*pn.y;
|
| 24 |
+
ps.y = sin(angle)*pn.x + cos(angle)*pn.y;
|
| 25 |
+
for(int i=1; i<np; ++i)
|
| 26 |
+
{
|
| 27 |
+
pn = collision_vertices[i];
|
| 28 |
+
pe.x = cos(angle)*pn.x - sin(angle)*pn.y;
|
| 29 |
+
pe.y = sin(angle)*pn.x + cos(angle)*pn.y;
|
| 30 |
+
al_draw_line(ps.x - camera.x, ps.y - camera.y, pe.x - camera.x, pe.y - camera.y, c, 0);
|
| 31 |
+
|
| 32 |
+
Vector2 middle = (pe+ps)/2-camera;
|
| 33 |
+
float a = (pe-ps).Angle()-M_PI/2;
|
| 34 |
+
al_draw_line(middle.x, middle.y, middle.x+cos(a)*5, middle.y+sin(a)*5, c, 0);
|
| 35 |
+
|
| 36 |
+
ps = pe;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void Platform::Add_collision_vertex(Vector2 v)
|
| 41 |
+
{
|
| 42 |
+
collision_vertices.push_back(v);
|
| 43 |
+
position = Vector2(0, 0);
|
| 44 |
+
for(Vertices::iterator i = collision_vertices.begin(); i!=collision_vertices.end(); ++i)
|
| 45 |
+
position+=*i;
|
| 46 |
+
position.x = position.x/collision_vertices.size();
|
| 47 |
+
position.y = position.y/collision_vertices.size();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
void Platform::Insert_collision_vertex(Vector2 v)
|
| 51 |
+
{
|
| 52 |
+
int n = Nearest_vertex(v);
|
| 53 |
+
if(n == 0)
|
| 54 |
+
{
|
| 55 |
+
collision_vertices.insert(collision_vertices.begin()+1, v);
|
| 56 |
+
return;
|
| 57 |
+
}
|
| 58 |
+
if(n == collision_vertices.size()-1)
|
| 59 |
+
{
|
| 60 |
+
collision_vertices.insert(collision_vertices.begin()+n, v);
|
| 61 |
+
return;
|
| 62 |
+
}
|
| 63 |
+
Vector2 db = v-collision_vertices[n-1];
|
| 64 |
+
Vector2 da = v-collision_vertices[n+1];
|
| 65 |
+
if(db.Length_squared() < da.Length_squared())
|
| 66 |
+
collision_vertices.insert(collision_vertices.begin()+n, v);
|
| 67 |
+
else
|
| 68 |
+
collision_vertices.insert(collision_vertices.begin()+(n+1), v);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void Platform::Move_collision_vertex(Vector2 v)
|
| 72 |
+
{
|
| 73 |
+
collision_vertices[Nearest_vertex(v)] = v;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void Platform::Remove_collision_vertex(Vector2 v)
|
| 77 |
+
{
|
| 78 |
+
collision_vertices.erase(collision_vertices.begin()+Nearest_vertex(v));
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void Platform::Set_collision_loop(bool loop)
|
| 82 |
+
{
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void Platform::Set_collision_scale(float s)
|
| 86 |
+
{
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
Vector2 Platform::Get_vertex(Vector2 v)
|
| 90 |
+
{
|
| 91 |
+
return collision_vertices[Nearest_vertex(v)];
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
int Platform::Nearest_vertex(Vector2 v)
|
| 95 |
+
{
|
| 96 |
+
Vector2 r(*collision_vertices.begin());
|
| 97 |
+
int index = 0;
|
| 98 |
+
int n = 0;
|
| 99 |
+
for(Vertices::iterator i = collision_vertices.begin(); i!=collision_vertices.end(); ++i, ++n)
|
| 100 |
+
{
|
| 101 |
+
if( (r-v).Length_squared() > ((*i)-v).Length_squared() )
|
| 102 |
+
{
|
| 103 |
+
r = *i;
|
| 104 |
+
index = n;
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
return index;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
Vertices& Platform::Get_vertices()
|
| 111 |
+
{
|
| 112 |
+
return collision_vertices;
|
| 113 |
+
}
|
pool/shard010/C++/0111256_main.cpp
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include <vector>
|
| 3 |
+
#include <utility>
|
| 4 |
+
#include <string>
|
| 5 |
+
using namespace std;
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* Approaches:
|
| 9 |
+
*
|
| 10 |
+
* 1) While we loop over the string, keep track of the starting and ending positions of groups of repeating characters.
|
| 11 |
+
* After we reach the end of the repeating group of characters, if the length is greater than or equal to the length
|
| 12 |
+
* which qualifies as a large group, then add the starting and ending indices to our result list (vector<vector<int>> result).
|
| 13 |
+
* Return our result list.
|
| 14 |
+
*
|
| 15 |
+
* Time complexity: O(n) [where n is the length of the input string, S]
|
| 16 |
+
* Space complexity: O(1)
|
| 17 |
+
*
|
| 18 |
+
* 2) Same logic as the first solution just using more explicit vector initialization when we are inserting our
|
| 19 |
+
* vectors containing the starting and ending indices of large group of repeating characters.
|
| 20 |
+
*
|
| 21 |
+
* Time complexity: O(n) [where n is the length of the input string, S]
|
| 22 |
+
* Space complexity: O(1)
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
vector<vector<int>> largeGroupPositions(string S)
|
| 26 |
+
{
|
| 27 |
+
vector<vector<int>> result;
|
| 28 |
+
|
| 29 |
+
if(S.empty())
|
| 30 |
+
{
|
| 31 |
+
return result;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
int n=int(S.size());
|
| 35 |
+
|
| 36 |
+
int groupSize=3;
|
| 37 |
+
|
| 38 |
+
for(int index=0;index<n;)
|
| 39 |
+
{
|
| 40 |
+
char current=S[index];
|
| 41 |
+
|
| 42 |
+
pair<int, int> startAndEnd(index, -1);
|
| 43 |
+
|
| 44 |
+
while(S[index]==current)
|
| 45 |
+
{
|
| 46 |
+
startAndEnd.second=index;
|
| 47 |
+
|
| 48 |
+
index++;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
if((startAndEnd.second - startAndEnd.first) + 1 >= groupSize)
|
| 52 |
+
{
|
| 53 |
+
result.push_back({{startAndEnd.first, startAndEnd.second}});
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
return result;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
vector<vector<int>> largeGroupPositions(string S)
|
| 61 |
+
{
|
| 62 |
+
vector<vector<int>> result;
|
| 63 |
+
|
| 64 |
+
if(S.empty())
|
| 65 |
+
{
|
| 66 |
+
return result;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
int n=int(S.size());
|
| 70 |
+
|
| 71 |
+
int groupSize=3;
|
| 72 |
+
|
| 73 |
+
for(int index=0;index<n;)
|
| 74 |
+
{
|
| 75 |
+
char current=S[index];
|
| 76 |
+
|
| 77 |
+
pair<int, int> startAndEnd(index, -1);
|
| 78 |
+
|
| 79 |
+
while(S[index]==current)
|
| 80 |
+
{
|
| 81 |
+
startAndEnd.second=index;
|
| 82 |
+
|
| 83 |
+
index++;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if((startAndEnd.second - startAndEnd.first) + 1 >= groupSize)
|
| 87 |
+
{
|
| 88 |
+
vector<int> v(2, 0);
|
| 89 |
+
|
| 90 |
+
v[0]=startAndEnd.first;
|
| 91 |
+
|
| 92 |
+
v[1]=startAndEnd.second;
|
| 93 |
+
|
| 94 |
+
result.push_back(v);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
return result;
|
| 99 |
+
}
|
pool/shard010/C++/0111257_describelocalgatewayroutetablesresponse.cpp
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright 2013-2021 Paul Colby
|
| 3 |
+
|
| 4 |
+
This file is part of QtAws.
|
| 5 |
+
|
| 6 |
+
QtAws is free software: you can redistribute it and/or modify
|
| 7 |
+
it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
(at your option) any later version.
|
| 10 |
+
|
| 11 |
+
QtAws is distributed in the hope that it will be useful,
|
| 12 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
GNU Lesser General Public License for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
along with the QtAws. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "describelocalgatewayroutetablesresponse.h"
|
| 21 |
+
#include "describelocalgatewayroutetablesresponse_p.h"
|
| 22 |
+
|
| 23 |
+
#include <QDebug>
|
| 24 |
+
#include <QNetworkReply>
|
| 25 |
+
#include <QXmlStreamReader>
|
| 26 |
+
|
| 27 |
+
namespace QtAws {
|
| 28 |
+
namespace EC2 {
|
| 29 |
+
|
| 30 |
+
/*!
|
| 31 |
+
* \class QtAws::EC2::DescribeLocalGatewayRouteTablesResponse
|
| 32 |
+
* \brief The DescribeLocalGatewayRouteTablesResponse class provides an interace for EC2 DescribeLocalGatewayRouteTables responses.
|
| 33 |
+
*
|
| 34 |
+
* \inmodule QtAwsEC2
|
| 35 |
+
*
|
| 36 |
+
* <fullname>Amazon Elastic Compute Cloud</fullname>
|
| 37 |
+
*
|
| 38 |
+
* Amazon Elastic Compute Cloud (Amazon EC2) provides secure and resizable computing capacity in the AWS Cloud. Using
|
| 39 |
+
* Amazon EC2 eliminates the need to invest in hardware up front, so you can develop and deploy applications faster. Amazon
|
| 40 |
+
* Virtual Private Cloud (Amazon VPC) enables you to provision a logically isolated section of the AWS Cloud where you can
|
| 41 |
+
* launch AWS resources in a virtual network that you've defined. Amazon Elastic Block Store (Amazon EBS) provides block
|
| 42 |
+
* level storage volumes for use with EC2 instances. EBS volumes are highly available and reliable storage volumes that can
|
| 43 |
+
* be attached to any running instance and used like a hard
|
| 44 |
+
*
|
| 45 |
+
* drive>
|
| 46 |
+
*
|
| 47 |
+
* To learn more, see the following
|
| 48 |
+
*
|
| 49 |
+
* resources> <ul> <li>
|
| 50 |
+
*
|
| 51 |
+
* Amazon EC2: <a href="http://aws.amazon.com/ec2">AmazonEC2 product page</a>, <a
|
| 52 |
+
* href="http://aws.amazon.com/documentation/ec2">Amazon EC2 documentation</a>
|
| 53 |
+
*
|
| 54 |
+
* </p </li> <li>
|
| 55 |
+
*
|
| 56 |
+
* Amazon EBS: <a href="http://aws.amazon.com/ebs">Amazon EBS product page</a>, <a
|
| 57 |
+
* href="http://aws.amazon.com/documentation/ebs">Amazon EBS documentation</a>
|
| 58 |
+
*
|
| 59 |
+
* </p </li> <li>
|
| 60 |
+
*
|
| 61 |
+
* Amazon VPC: <a href="http://aws.amazon.com/vpc">Amazon VPC product page</a>, <a
|
| 62 |
+
* href="http://aws.amazon.com/documentation/vpc">Amazon VPC documentation</a>
|
| 63 |
+
*
|
| 64 |
+
* </p </li> <li>
|
| 65 |
+
*
|
| 66 |
+
* AWS VPN: <a href="http://aws.amazon.com/vpn">AWS VPN product page</a>, <a
|
| 67 |
+
* href="http://aws.amazon.com/documentation/vpn">AWS VPN documentation</a>
|
| 68 |
+
*
|
| 69 |
+
* \sa Ec2Client::describeLocalGatewayRouteTables
|
| 70 |
+
*/
|
| 71 |
+
|
| 72 |
+
/*!
|
| 73 |
+
* Constructs a DescribeLocalGatewayRouteTablesResponse object for \a reply to \a request, with parent \a parent.
|
| 74 |
+
*/
|
| 75 |
+
DescribeLocalGatewayRouteTablesResponse::DescribeLocalGatewayRouteTablesResponse(
|
| 76 |
+
const DescribeLocalGatewayRouteTablesRequest &request,
|
| 77 |
+
QNetworkReply * const reply,
|
| 78 |
+
QObject * const parent)
|
| 79 |
+
: Ec2Response(new DescribeLocalGatewayRouteTablesResponsePrivate(this), parent)
|
| 80 |
+
{
|
| 81 |
+
setRequest(new DescribeLocalGatewayRouteTablesRequest(request));
|
| 82 |
+
setReply(reply);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/*!
|
| 86 |
+
* \reimp
|
| 87 |
+
*/
|
| 88 |
+
const DescribeLocalGatewayRouteTablesRequest * DescribeLocalGatewayRouteTablesResponse::request() const
|
| 89 |
+
{
|
| 90 |
+
Q_D(const DescribeLocalGatewayRouteTablesResponse);
|
| 91 |
+
return static_cast<const DescribeLocalGatewayRouteTablesRequest *>(d->request);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/*!
|
| 95 |
+
* \reimp
|
| 96 |
+
* Parses a successful EC2 DescribeLocalGatewayRouteTables \a response.
|
| 97 |
+
*/
|
| 98 |
+
void DescribeLocalGatewayRouteTablesResponse::parseSuccess(QIODevice &response)
|
| 99 |
+
{
|
| 100 |
+
//Q_D(DescribeLocalGatewayRouteTablesResponse);
|
| 101 |
+
QXmlStreamReader xml(&response);
|
| 102 |
+
/// @todo
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/*!
|
| 106 |
+
* \class QtAws::EC2::DescribeLocalGatewayRouteTablesResponsePrivate
|
| 107 |
+
* \brief The DescribeLocalGatewayRouteTablesResponsePrivate class provides private implementation for DescribeLocalGatewayRouteTablesResponse.
|
| 108 |
+
* \internal
|
| 109 |
+
*
|
| 110 |
+
* \inmodule QtAwsEC2
|
| 111 |
+
*/
|
| 112 |
+
|
| 113 |
+
/*!
|
| 114 |
+
* Constructs a DescribeLocalGatewayRouteTablesResponsePrivate object with public implementation \a q.
|
| 115 |
+
*/
|
| 116 |
+
DescribeLocalGatewayRouteTablesResponsePrivate::DescribeLocalGatewayRouteTablesResponsePrivate(
|
| 117 |
+
DescribeLocalGatewayRouteTablesResponse * const q) : Ec2ResponsePrivate(q)
|
| 118 |
+
{
|
| 119 |
+
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/*!
|
| 123 |
+
* Parses a EC2 DescribeLocalGatewayRouteTables response element from \a xml.
|
| 124 |
+
*/
|
| 125 |
+
void DescribeLocalGatewayRouteTablesResponsePrivate::parseDescribeLocalGatewayRouteTablesResponse(QXmlStreamReader &xml)
|
| 126 |
+
{
|
| 127 |
+
Q_ASSERT(xml.name() == QLatin1String("DescribeLocalGatewayRouteTablesResponse"));
|
| 128 |
+
Q_UNUSED(xml) ///< @todo
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
} // namespace EC2
|
| 132 |
+
} // namespace QtAws
|
pool/shard010/C++/0111259_decode_svc_test.cc
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
| 3 |
+
*
|
| 4 |
+
* Use of this source code is governed by a BSD-style license
|
| 5 |
+
* that can be found in the LICENSE file in the root of the source
|
| 6 |
+
* tree. An additional intellectual property rights grant can be found
|
| 7 |
+
* in the file PATENTS. All contributing project authors may
|
| 8 |
+
* be found in the AUTHORS file in the root of the source tree.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
#include <string>
|
| 13 |
+
|
| 14 |
+
#include "test/codec_factory.h"
|
| 15 |
+
#include "test/decode_test_driver.h"
|
| 16 |
+
#include "test/ivf_video_source.h"
|
| 17 |
+
#include "test/test_vectors.h"
|
| 18 |
+
#include "test/util.h"
|
| 19 |
+
|
| 20 |
+
namespace {
|
| 21 |
+
|
| 22 |
+
const unsigned int kNumFrames = 19;
|
| 23 |
+
|
| 24 |
+
class DecodeSvcTest : public ::libvpx_test::DecoderTest,
|
| 25 |
+
public ::libvpx_test::CodecTestWithParam<const char *> {
|
| 26 |
+
protected:
|
| 27 |
+
DecodeSvcTest() : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)) {}
|
| 28 |
+
virtual ~DecodeSvcTest() {}
|
| 29 |
+
|
| 30 |
+
virtual void PreDecodeFrameHook(
|
| 31 |
+
const libvpx_test::CompressedVideoSource &video,
|
| 32 |
+
libvpx_test::Decoder *decoder) {
|
| 33 |
+
if (video.frame_number() == 0)
|
| 34 |
+
decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER, spatial_layer_);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
virtual void DecompressedFrameHook(const vpx_image_t &img,
|
| 38 |
+
const unsigned int frame_number) {
|
| 39 |
+
ASSERT_EQ(img.d_w, width_);
|
| 40 |
+
ASSERT_EQ(img.d_h, height_);
|
| 41 |
+
total_frames_ = frame_number;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
int spatial_layer_;
|
| 45 |
+
unsigned int width_;
|
| 46 |
+
unsigned int height_;
|
| 47 |
+
unsigned int total_frames_;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
// SVC test vector is 1280x720, with 3 spatial layers, and 20 frames.
|
| 51 |
+
|
| 52 |
+
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
|
| 53 |
+
// spatial layer 0. Verify the resolution of each decoded frame and the total
|
| 54 |
+
// number of frames decoded. This results in 1/4x1/4 resolution (320x180).
|
| 55 |
+
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer0) {
|
| 56 |
+
const std::string filename = GET_PARAM(1);
|
| 57 |
+
std::unique_ptr<libvpx_test::CompressedVideoSource> video;
|
| 58 |
+
video.reset(new libvpx_test::IVFVideoSource(filename));
|
| 59 |
+
ASSERT_NE(video.get(), nullptr);
|
| 60 |
+
video->Init();
|
| 61 |
+
total_frames_ = 0;
|
| 62 |
+
spatial_layer_ = 0;
|
| 63 |
+
width_ = 320;
|
| 64 |
+
height_ = 180;
|
| 65 |
+
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
|
| 66 |
+
ASSERT_EQ(total_frames_, kNumFrames);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
|
| 70 |
+
// spatial layer 1. Verify the resolution of each decoded frame and the total
|
| 71 |
+
// number of frames decoded. This results in 1/2x1/2 resolution (640x360).
|
| 72 |
+
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer1) {
|
| 73 |
+
const std::string filename = GET_PARAM(1);
|
| 74 |
+
std::unique_ptr<libvpx_test::CompressedVideoSource> video;
|
| 75 |
+
video.reset(new libvpx_test::IVFVideoSource(filename));
|
| 76 |
+
ASSERT_NE(video.get(), nullptr);
|
| 77 |
+
video->Init();
|
| 78 |
+
total_frames_ = 0;
|
| 79 |
+
spatial_layer_ = 1;
|
| 80 |
+
width_ = 640;
|
| 81 |
+
height_ = 360;
|
| 82 |
+
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
|
| 83 |
+
ASSERT_EQ(total_frames_, kNumFrames);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
|
| 87 |
+
// spatial layer 2. Verify the resolution of each decoded frame and the total
|
| 88 |
+
// number of frames decoded. This results in the full resolution (1280x720).
|
| 89 |
+
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer2) {
|
| 90 |
+
const std::string filename = GET_PARAM(1);
|
| 91 |
+
std::unique_ptr<libvpx_test::CompressedVideoSource> video;
|
| 92 |
+
video.reset(new libvpx_test::IVFVideoSource(filename));
|
| 93 |
+
ASSERT_NE(video.get(), nullptr);
|
| 94 |
+
video->Init();
|
| 95 |
+
total_frames_ = 0;
|
| 96 |
+
spatial_layer_ = 2;
|
| 97 |
+
width_ = 1280;
|
| 98 |
+
height_ = 720;
|
| 99 |
+
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
|
| 100 |
+
ASSERT_EQ(total_frames_, kNumFrames);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
|
| 104 |
+
// spatial layer 10. Verify the resolution of each decoded frame and the total
|
| 105 |
+
// number of frames decoded. This is beyond the number of spatial layers, so
|
| 106 |
+
// the decoding should result in the full resolution (1280x720).
|
| 107 |
+
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer10) {
|
| 108 |
+
const std::string filename = GET_PARAM(1);
|
| 109 |
+
std::unique_ptr<libvpx_test::CompressedVideoSource> video;
|
| 110 |
+
video.reset(new libvpx_test::IVFVideoSource(filename));
|
| 111 |
+
ASSERT_NE(video.get(), nullptr);
|
| 112 |
+
video->Init();
|
| 113 |
+
total_frames_ = 0;
|
| 114 |
+
spatial_layer_ = 10;
|
| 115 |
+
width_ = 1280;
|
| 116 |
+
height_ = 720;
|
| 117 |
+
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
|
| 118 |
+
ASSERT_EQ(total_frames_, kNumFrames);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
VP9_INSTANTIATE_TEST_SUITE(
|
| 122 |
+
DecodeSvcTest, ::testing::ValuesIn(libvpx_test::kVP9TestVectorsSvc,
|
| 123 |
+
libvpx_test::kVP9TestVectorsSvc +
|
| 124 |
+
libvpx_test::kNumVP9TestVectorsSvc));
|
| 125 |
+
} // namespace
|
pool/shard010/C++/0111260_bitcoin.cpp
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* W.J. van der Laan 2011-2012
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#include <QApplication>
|
| 6 |
+
|
| 7 |
+
#include "bitcoingui.h"
|
| 8 |
+
#include "clientmodel.h"
|
| 9 |
+
#include "walletmodel.h"
|
| 10 |
+
#include "optionsmodel.h"
|
| 11 |
+
#include "guiutil.h"
|
| 12 |
+
#include "guiconstants.h"
|
| 13 |
+
#include "init.h"
|
| 14 |
+
#include "util.h"
|
| 15 |
+
#include "ui_interface.h"
|
| 16 |
+
#include "paymentserver.h"
|
| 17 |
+
#include "splashscreen.h"
|
| 18 |
+
|
| 19 |
+
#include <QMessageBox>
|
| 20 |
+
#include <QTextCodec>
|
| 21 |
+
#include <QLocale>
|
| 22 |
+
#include <QTimer>
|
| 23 |
+
#include <QTranslator>
|
| 24 |
+
#include <QLibraryInfo>
|
| 25 |
+
|
| 26 |
+
#ifdef Q_OS_MAC
|
| 27 |
+
#include "macdockiconhandler.h"
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
#if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
|
| 31 |
+
#define _BITCOIN_QT_PLUGINS_INCLUDED
|
| 32 |
+
#define __INSURE__
|
| 33 |
+
#include <QtPlugin>
|
| 34 |
+
Q_IMPORT_PLUGIN(qcncodecs)
|
| 35 |
+
Q_IMPORT_PLUGIN(qjpcodecs)
|
| 36 |
+
Q_IMPORT_PLUGIN(qtwcodecs)
|
| 37 |
+
Q_IMPORT_PLUGIN(qkrcodecs)
|
| 38 |
+
Q_IMPORT_PLUGIN(qtaccessiblewidgets)
|
| 39 |
+
#endif
|
| 40 |
+
|
| 41 |
+
// Declare meta types used for QMetaObject::invokeMethod
|
| 42 |
+
Q_DECLARE_METATYPE(bool*)
|
| 43 |
+
|
| 44 |
+
// Need a global reference for the notifications to find the GUI
|
| 45 |
+
static BitcoinGUI *guiref;
|
| 46 |
+
static SplashScreen *splashref;
|
| 47 |
+
|
| 48 |
+
static bool ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
|
| 49 |
+
{
|
| 50 |
+
// Message from network thread
|
| 51 |
+
if(guiref)
|
| 52 |
+
{
|
| 53 |
+
bool modal = (style & CClientUIInterface::MODAL);
|
| 54 |
+
bool ret = false;
|
| 55 |
+
// In case of modal message, use blocking connection to wait for user to click a button
|
| 56 |
+
QMetaObject::invokeMethod(guiref, "message",
|
| 57 |
+
modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
|
| 58 |
+
Q_ARG(QString, QString::fromStdString(caption)),
|
| 59 |
+
Q_ARG(QString, QString::fromStdString(message)),
|
| 60 |
+
Q_ARG(unsigned int, style),
|
| 61 |
+
Q_ARG(bool*, &ret));
|
| 62 |
+
return ret;
|
| 63 |
+
}
|
| 64 |
+
else
|
| 65 |
+
{
|
| 66 |
+
printf("%s: %s\n", caption.c_str(), message.c_str());
|
| 67 |
+
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
|
| 68 |
+
return false;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
static bool ThreadSafeAskFee(const mpq& nFeeRequired)
|
| 73 |
+
{
|
| 74 |
+
if(!guiref)
|
| 75 |
+
return false;
|
| 76 |
+
if(nFeeRequired < CTransaction::nMinTxFee || nFeeRequired <= nTransactionFee || fDaemon)
|
| 77 |
+
return true;
|
| 78 |
+
|
| 79 |
+
bool payFee = false;
|
| 80 |
+
|
| 81 |
+
QMetaObject::invokeMethod(guiref, "askFee", GUIUtil::blockingGUIThreadConnection(),
|
| 82 |
+
Q_ARG(mpq, nFeeRequired),
|
| 83 |
+
Q_ARG(bool*, &payFee));
|
| 84 |
+
|
| 85 |
+
return payFee;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
static void InitMessage(const std::string &message)
|
| 89 |
+
{
|
| 90 |
+
if(splashref)
|
| 91 |
+
{
|
| 92 |
+
splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(55,55,55));
|
| 93 |
+
qApp->processEvents();
|
| 94 |
+
}
|
| 95 |
+
printf("init message: %s\n", message.c_str());
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/*
|
| 99 |
+
Translate string to current locale using Qt.
|
| 100 |
+
*/
|
| 101 |
+
static std::string Translate(const char* psz)
|
| 102 |
+
{
|
| 103 |
+
return QCoreApplication::translate("bitcoin-core", psz).toStdString();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/* Handle runaway exceptions. Shows a message box with the problem and quits the program.
|
| 107 |
+
*/
|
| 108 |
+
static void handleRunawayException(std::exception *e)
|
| 109 |
+
{
|
| 110 |
+
PrintExceptionContinue(e, "Runaway exception");
|
| 111 |
+
QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. Scicoin can no longer continue safely and will quit.") + QString("\n\n") + QString::fromStdString(strMiscWarning));
|
| 112 |
+
exit(1);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
#ifndef BITCOIN_QT_TEST
|
| 116 |
+
int main(int argc, char *argv[])
|
| 117 |
+
{
|
| 118 |
+
// Command-line options take precedence:
|
| 119 |
+
ParseParameters(argc, argv);
|
| 120 |
+
|
| 121 |
+
// Internal string conversion is all UTF-8
|
| 122 |
+
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
|
| 123 |
+
QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
|
| 124 |
+
|
| 125 |
+
Q_INIT_RESOURCE(bitcoin);
|
| 126 |
+
QApplication app(argc, argv);
|
| 127 |
+
|
| 128 |
+
// Register meta types used for QMetaObject::invokeMethod
|
| 129 |
+
qRegisterMetaType< bool* >();
|
| 130 |
+
|
| 131 |
+
// Do this early as we don't want to bother initializing if we are just calling IPC
|
| 132 |
+
// ... but do it after creating app, so QCoreApplication::arguments is initialized:
|
| 133 |
+
if (PaymentServer::ipcSendCommandLine())
|
| 134 |
+
exit(0);
|
| 135 |
+
PaymentServer* paymentServer = new PaymentServer(&app);
|
| 136 |
+
|
| 137 |
+
// Install global event filter that makes sure that long tooltips can be word-wrapped
|
| 138 |
+
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
|
| 139 |
+
|
| 140 |
+
// ... then bitcoin.conf:
|
| 141 |
+
if (!boost::filesystem::is_directory(GetDataDir(false)))
|
| 142 |
+
{
|
| 143 |
+
// This message can not be translated, as translation is not initialized yet
|
| 144 |
+
// (which not yet possible because lang=XX can be overridden in bitcoin.conf in the data directory)
|
| 145 |
+
QMessageBox::critical(0, "Scicoin",
|
| 146 |
+
QString("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
|
| 147 |
+
return 1;
|
| 148 |
+
}
|
| 149 |
+
ReadConfigFile(mapArgs, mapMultiArgs);
|
| 150 |
+
|
| 151 |
+
// Application identification (must be set before OptionsModel is initialized,
|
| 152 |
+
// as it is used to locate QSettings)
|
| 153 |
+
QApplication::setOrganizationName("Scicoin");
|
| 154 |
+
QApplication::setOrganizationDomain("freico.in");
|
| 155 |
+
if(GetBoolArg("-testnet")) // Separate UI settings for testnet
|
| 156 |
+
QApplication::setApplicationName("Scicoin-Qt-testnet");
|
| 157 |
+
else
|
| 158 |
+
QApplication::setApplicationName("Scicoin-Qt");
|
| 159 |
+
|
| 160 |
+
// ... then GUI settings:
|
| 161 |
+
OptionsModel optionsModel;
|
| 162 |
+
|
| 163 |
+
// Get desired locale (e.g. "de_DE") from command line or use system locale
|
| 164 |
+
QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString()));
|
| 165 |
+
QString lang = lang_territory;
|
| 166 |
+
// Convert to "de" only by truncating "_DE"
|
| 167 |
+
lang.truncate(lang_territory.lastIndexOf('_'));
|
| 168 |
+
|
| 169 |
+
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
|
| 170 |
+
// Load language files for configured locale:
|
| 171 |
+
// - First load the translator for the base language, without territory
|
| 172 |
+
// - Then load the more specific locale translator
|
| 173 |
+
|
| 174 |
+
// Load e.g. qt_de.qm
|
| 175 |
+
if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
| 176 |
+
app.installTranslator(&qtTranslatorBase);
|
| 177 |
+
|
| 178 |
+
// Load e.g. qt_de_DE.qm
|
| 179 |
+
if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
| 180 |
+
app.installTranslator(&qtTranslator);
|
| 181 |
+
|
| 182 |
+
// Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
|
| 183 |
+
if (translatorBase.load(lang, ":/translations/"))
|
| 184 |
+
app.installTranslator(&translatorBase);
|
| 185 |
+
|
| 186 |
+
// Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
|
| 187 |
+
if (translator.load(lang_territory, ":/translations/"))
|
| 188 |
+
app.installTranslator(&translator);
|
| 189 |
+
|
| 190 |
+
// Subscribe to global signals from core
|
| 191 |
+
uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox);
|
| 192 |
+
uiInterface.ThreadSafeAskFee.connect(ThreadSafeAskFee);
|
| 193 |
+
uiInterface.InitMessage.connect(InitMessage);
|
| 194 |
+
uiInterface.Translate.connect(Translate);
|
| 195 |
+
|
| 196 |
+
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
|
| 197 |
+
// but before showing splash screen.
|
| 198 |
+
if (mapArgs.count("-?") || mapArgs.count("--help"))
|
| 199 |
+
{
|
| 200 |
+
GUIUtil::HelpMessageBox help;
|
| 201 |
+
help.showOrPrint();
|
| 202 |
+
return 1;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
#ifdef Q_OS_MAC
|
| 206 |
+
// on mac, also change the icon now because it would look strange to have a testnet splash (green) and a std app icon (orange)
|
| 207 |
+
if(GetBoolArg("-testnet")) {
|
| 208 |
+
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
|
| 209 |
+
}
|
| 210 |
+
#endif
|
| 211 |
+
|
| 212 |
+
SplashScreen splash(QPixmap(), 0);
|
| 213 |
+
if (GetBoolArg("-splash", true) && !GetBoolArg("-min"))
|
| 214 |
+
{
|
| 215 |
+
splash.show();
|
| 216 |
+
splash.setAutoFillBackground(true);
|
| 217 |
+
splashref = &splash;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
app.processEvents();
|
| 221 |
+
app.setQuitOnLastWindowClosed(false);
|
| 222 |
+
|
| 223 |
+
try
|
| 224 |
+
{
|
| 225 |
+
// Regenerate startup link, to fix links to old versions
|
| 226 |
+
if (GUIUtil::GetStartOnSystemStartup())
|
| 227 |
+
GUIUtil::SetStartOnSystemStartup(true);
|
| 228 |
+
|
| 229 |
+
boost::thread_group threadGroup;
|
| 230 |
+
|
| 231 |
+
BitcoinGUI window;
|
| 232 |
+
guiref = &window;
|
| 233 |
+
|
| 234 |
+
QTimer* pollShutdownTimer = new QTimer(guiref);
|
| 235 |
+
QObject::connect(pollShutdownTimer, SIGNAL(timeout()), guiref, SLOT(detectShutdown()));
|
| 236 |
+
pollShutdownTimer->start(200);
|
| 237 |
+
|
| 238 |
+
if(AppInit2(threadGroup))
|
| 239 |
+
{
|
| 240 |
+
{
|
| 241 |
+
// Put this in a block, so that the Model objects are cleaned up before
|
| 242 |
+
// calling Shutdown().
|
| 243 |
+
|
| 244 |
+
optionsModel.Upgrade(); // Must be done after AppInit2
|
| 245 |
+
|
| 246 |
+
if (splashref)
|
| 247 |
+
splash.finish(&window);
|
| 248 |
+
|
| 249 |
+
ClientModel clientModel(&optionsModel);
|
| 250 |
+
WalletModel walletModel(pwalletMain, &optionsModel);
|
| 251 |
+
|
| 252 |
+
window.setClientModel(&clientModel);
|
| 253 |
+
window.addWallet("~Default", &walletModel);
|
| 254 |
+
window.setCurrentWallet("~Default");
|
| 255 |
+
|
| 256 |
+
// If -min option passed, start window minimized.
|
| 257 |
+
if(GetBoolArg("-min"))
|
| 258 |
+
{
|
| 259 |
+
window.showMinimized();
|
| 260 |
+
}
|
| 261 |
+
else
|
| 262 |
+
{
|
| 263 |
+
window.show();
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
// Now that initialization/startup is done, process any command-line
|
| 267 |
+
// bitcoin: URIs
|
| 268 |
+
QObject::connect(paymentServer, SIGNAL(receivedURI(QString)), &window, SLOT(handleURI(QString)));
|
| 269 |
+
QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
|
| 270 |
+
|
| 271 |
+
app.exec();
|
| 272 |
+
|
| 273 |
+
window.hide();
|
| 274 |
+
window.setClientModel(0);
|
| 275 |
+
window.removeAllWallets();
|
| 276 |
+
guiref = 0;
|
| 277 |
+
}
|
| 278 |
+
// Shutdown the core and its threads, but don't exit Bitcoin-Qt here
|
| 279 |
+
threadGroup.interrupt_all();
|
| 280 |
+
threadGroup.join_all();
|
| 281 |
+
Shutdown();
|
| 282 |
+
}
|
| 283 |
+
else
|
| 284 |
+
{
|
| 285 |
+
threadGroup.interrupt_all();
|
| 286 |
+
threadGroup.join_all();
|
| 287 |
+
Shutdown();
|
| 288 |
+
return 1;
|
| 289 |
+
}
|
| 290 |
+
} catch (std::exception& e) {
|
| 291 |
+
handleRunawayException(&e);
|
| 292 |
+
} catch (...) {
|
| 293 |
+
handleRunawayException(NULL);
|
| 294 |
+
}
|
| 295 |
+
return 0;
|
| 296 |
+
}
|
| 297 |
+
#endif // BITCOIN_QT_TEST
|
pool/shard010/C++/0111266_CryptoKeyReader.cc
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 3 |
+
* or more contributor license agreements. See the NOTICE file
|
| 4 |
+
* distributed with this work for additional information
|
| 5 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 6 |
+
* to you under the Apache License, Version 2.0 (the
|
| 7 |
+
* "License"); you may not use this file except in compliance
|
| 8 |
+
* with the License. You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing,
|
| 13 |
+
* software distributed under the License is distributed on an
|
| 14 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 |
+
* KIND, either express or implied. See the License for the
|
| 16 |
+
* specific language governing permissions and limitations
|
| 17 |
+
* under the License.
|
| 18 |
+
*/
|
| 19 |
+
#include <fstream>
|
| 20 |
+
#include <sstream>
|
| 21 |
+
#include <pulsar/EncryptionKeyInfo.h>
|
| 22 |
+
#include <pulsar/CryptoKeyReader.h>
|
| 23 |
+
#include <pulsar/Result.h>
|
| 24 |
+
|
| 25 |
+
using namespace pulsar;
|
| 26 |
+
|
| 27 |
+
CryptoKeyReader::CryptoKeyReader() {}
|
| 28 |
+
CryptoKeyReader::~CryptoKeyReader() {}
|
| 29 |
+
|
| 30 |
+
Result CryptoKeyReader::getPublicKey(const std::string& keyName, std::map<std::string, std::string>& metadata,
|
| 31 |
+
EncryptionKeyInfo& encKeyInfo) const {
|
| 32 |
+
return ResultInvalidConfiguration;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
Result CryptoKeyReader::getPrivateKey(const std::string& keyName,
|
| 36 |
+
std::map<std::string, std::string>& metadata,
|
| 37 |
+
EncryptionKeyInfo& encKeyInfo) const {
|
| 38 |
+
return ResultInvalidConfiguration;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
DefaultCryptoKeyReader::DefaultCryptoKeyReader(const std::string& publicKeyPath,
|
| 42 |
+
const std::string& privateKeyPath) {
|
| 43 |
+
publicKeyPath_ = publicKeyPath;
|
| 44 |
+
privateKeyPath_ = privateKeyPath;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
DefaultCryptoKeyReader::~DefaultCryptoKeyReader() {}
|
| 48 |
+
|
| 49 |
+
void DefaultCryptoKeyReader::readFile(std::string fileName, std::string& fileContents) const {
|
| 50 |
+
std::ifstream ifs(fileName);
|
| 51 |
+
std::stringstream fileStream;
|
| 52 |
+
fileStream << ifs.rdbuf();
|
| 53 |
+
|
| 54 |
+
fileContents = fileStream.str();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
Result DefaultCryptoKeyReader::getPublicKey(const std::string& keyName,
|
| 58 |
+
std::map<std::string, std::string>& metadata,
|
| 59 |
+
EncryptionKeyInfo& encKeyInfo) const {
|
| 60 |
+
std::string keyContents;
|
| 61 |
+
readFile(publicKeyPath_, keyContents);
|
| 62 |
+
|
| 63 |
+
encKeyInfo.setKey(keyContents);
|
| 64 |
+
return ResultOk;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
Result DefaultCryptoKeyReader::getPrivateKey(const std::string& keyName,
|
| 68 |
+
std::map<std::string, std::string>& metadata,
|
| 69 |
+
EncryptionKeyInfo& encKeyInfo) const {
|
| 70 |
+
std::string keyContents;
|
| 71 |
+
readFile(privateKeyPath_, keyContents);
|
| 72 |
+
|
| 73 |
+
encKeyInfo.setKey(keyContents);
|
| 74 |
+
return ResultOk;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
CryptoKeyReaderPtr DefaultCryptoKeyReader::create(const std::string& publicKeyPath,
|
| 78 |
+
const std::string& privateKeyPath) {
|
| 79 |
+
return CryptoKeyReaderPtr(new DefaultCryptoKeyReader(publicKeyPath, privateKeyPath));
|
| 80 |
+
}
|
pool/shard010/C++/0111268_Jit_Branch.cpp
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2013 Dolphin Emulator Project
|
| 2 |
+
// Licensed under GPLv2
|
| 3 |
+
// Refer to the license.txt file included.
|
| 4 |
+
|
| 5 |
+
#include "Common/CommonTypes.h"
|
| 6 |
+
|
| 7 |
+
#include "Core/PowerPC/Jit64/Jit.h"
|
| 8 |
+
#include "Core/PowerPC/Jit64/JitAsm.h"
|
| 9 |
+
#include "Core/PowerPC/Jit64/JitRegCache.h"
|
| 10 |
+
|
| 11 |
+
// The branches are known good, or at least reasonably good.
|
| 12 |
+
// No need for a disable-mechanism.
|
| 13 |
+
|
| 14 |
+
// If defined, clears CR0 at blr and bl-s. If the assumption that
|
| 15 |
+
// flags never carry over between functions holds, then the task for
|
| 16 |
+
// an optimizer becomes much easier.
|
| 17 |
+
|
| 18 |
+
// #define ACID_TEST
|
| 19 |
+
|
| 20 |
+
// Zelda and many more games seem to pass the Acid Test.
|
| 21 |
+
|
| 22 |
+
using namespace Gen;
|
| 23 |
+
|
| 24 |
+
void Jit64::sc(UGeckoInstruction inst)
|
| 25 |
+
{
|
| 26 |
+
INSTRUCTION_START
|
| 27 |
+
JITDISABLE(bJITBranchOff);
|
| 28 |
+
|
| 29 |
+
gpr.Flush();
|
| 30 |
+
fpr.Flush();
|
| 31 |
+
MOV(32, PPCSTATE(pc), Imm32(js.compilerPC + 4));
|
| 32 |
+
LOCK();
|
| 33 |
+
OR(32, PPCSTATE(Exceptions), Imm32(EXCEPTION_SYSCALL));
|
| 34 |
+
WriteExceptionExit();
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void Jit64::rfi(UGeckoInstruction inst)
|
| 38 |
+
{
|
| 39 |
+
INSTRUCTION_START
|
| 40 |
+
JITDISABLE(bJITBranchOff);
|
| 41 |
+
|
| 42 |
+
gpr.Flush();
|
| 43 |
+
fpr.Flush();
|
| 44 |
+
// See Interpreter rfi for details
|
| 45 |
+
const u32 mask = 0x87C0FFFF;
|
| 46 |
+
const u32 clearMSR13 = 0xFFFBFFFF; // Mask used to clear the bit MSR[13]
|
| 47 |
+
// MSR = ((MSR & ~mask) | (SRR1 & mask)) & clearMSR13;
|
| 48 |
+
AND(32, PPCSTATE(msr), Imm32((~mask) & clearMSR13));
|
| 49 |
+
MOV(32, R(RSCRATCH), PPCSTATE_SRR1);
|
| 50 |
+
AND(32, R(RSCRATCH), Imm32(mask & clearMSR13));
|
| 51 |
+
OR(32, PPCSTATE(msr), R(RSCRATCH));
|
| 52 |
+
// NPC = SRR0;
|
| 53 |
+
MOV(32, R(RSCRATCH), PPCSTATE_SRR0);
|
| 54 |
+
WriteRfiExitDestInRSCRATCH();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void Jit64::bx(UGeckoInstruction inst)
|
| 58 |
+
{
|
| 59 |
+
INSTRUCTION_START
|
| 60 |
+
JITDISABLE(bJITBranchOff);
|
| 61 |
+
|
| 62 |
+
// We must always process the following sentence
|
| 63 |
+
// even if the blocks are merged by PPCAnalyst::Flatten().
|
| 64 |
+
if (inst.LK)
|
| 65 |
+
MOV(32, PPCSTATE_LR, Imm32(js.compilerPC + 4));
|
| 66 |
+
|
| 67 |
+
// If this is not the last instruction of a block,
|
| 68 |
+
// we will skip the rest process.
|
| 69 |
+
// Because PPCAnalyst::Flatten() merged the blocks.
|
| 70 |
+
if (!js.isLastInstruction)
|
| 71 |
+
{
|
| 72 |
+
return;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
gpr.Flush();
|
| 76 |
+
fpr.Flush();
|
| 77 |
+
|
| 78 |
+
u32 destination;
|
| 79 |
+
if (inst.AA)
|
| 80 |
+
destination = SignExt26(inst.LI << 2);
|
| 81 |
+
else
|
| 82 |
+
destination = js.compilerPC + SignExt26(inst.LI << 2);
|
| 83 |
+
#ifdef ACID_TEST
|
| 84 |
+
if (inst.LK)
|
| 85 |
+
AND(32, PPCSTATE(cr), Imm32(~(0xFF000000)));
|
| 86 |
+
#endif
|
| 87 |
+
if (destination == js.compilerPC)
|
| 88 |
+
{
|
| 89 |
+
//PanicAlert("Idle loop detected at %08x", destination);
|
| 90 |
+
// CALL(ProtectFunction(&CoreTiming::Idle, 0));
|
| 91 |
+
// JMP(Asm::testExceptions, true);
|
| 92 |
+
// make idle loops go faster
|
| 93 |
+
js.downcountAmount += 8;
|
| 94 |
+
}
|
| 95 |
+
WriteExit(destination, inst.LK, js.compilerPC + 4);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
// TODO - optimize to hell and beyond
|
| 99 |
+
// TODO - make nice easy to optimize special cases for the most common
|
| 100 |
+
// variants of this instruction.
|
| 101 |
+
void Jit64::bcx(UGeckoInstruction inst)
|
| 102 |
+
{
|
| 103 |
+
INSTRUCTION_START
|
| 104 |
+
JITDISABLE(bJITBranchOff);
|
| 105 |
+
|
| 106 |
+
// USES_CR
|
| 107 |
+
|
| 108 |
+
FixupBranch pCTRDontBranch;
|
| 109 |
+
if ((inst.BO & BO_DONT_DECREMENT_FLAG) == 0) // Decrement and test CTR
|
| 110 |
+
{
|
| 111 |
+
SUB(32, PPCSTATE_CTR, Imm8(1));
|
| 112 |
+
if (inst.BO & BO_BRANCH_IF_CTR_0)
|
| 113 |
+
pCTRDontBranch = J_CC(CC_NZ, true);
|
| 114 |
+
else
|
| 115 |
+
pCTRDontBranch = J_CC(CC_Z, true);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
FixupBranch pConditionDontBranch;
|
| 119 |
+
if ((inst.BO & BO_DONT_CHECK_CONDITION) == 0) // Test a CR bit
|
| 120 |
+
{
|
| 121 |
+
pConditionDontBranch = JumpIfCRFieldBit(inst.BI >> 2, 3 - (inst.BI & 3),
|
| 122 |
+
!(inst.BO_2 & BO_BRANCH_IF_TRUE));
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
if (inst.LK)
|
| 126 |
+
MOV(32, PPCSTATE_LR, Imm32(js.compilerPC + 4));
|
| 127 |
+
|
| 128 |
+
u32 destination;
|
| 129 |
+
if (inst.AA)
|
| 130 |
+
destination = SignExt16(inst.BD << 2);
|
| 131 |
+
else
|
| 132 |
+
destination = js.compilerPC + SignExt16(inst.BD << 2);
|
| 133 |
+
|
| 134 |
+
gpr.Flush(FLUSH_MAINTAIN_STATE);
|
| 135 |
+
fpr.Flush(FLUSH_MAINTAIN_STATE);
|
| 136 |
+
WriteExit(destination, inst.LK, js.compilerPC + 4);
|
| 137 |
+
|
| 138 |
+
if ((inst.BO & BO_DONT_CHECK_CONDITION) == 0)
|
| 139 |
+
SetJumpTarget( pConditionDontBranch );
|
| 140 |
+
if ((inst.BO & BO_DONT_DECREMENT_FLAG) == 0)
|
| 141 |
+
SetJumpTarget( pCTRDontBranch );
|
| 142 |
+
|
| 143 |
+
if (!analyzer.HasOption(PPCAnalyst::PPCAnalyzer::OPTION_CONDITIONAL_CONTINUE))
|
| 144 |
+
{
|
| 145 |
+
gpr.Flush();
|
| 146 |
+
fpr.Flush();
|
| 147 |
+
WriteExit(js.compilerPC + 4);
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
void Jit64::bcctrx(UGeckoInstruction inst)
|
| 152 |
+
{
|
| 153 |
+
INSTRUCTION_START
|
| 154 |
+
JITDISABLE(bJITBranchOff);
|
| 155 |
+
|
| 156 |
+
// bcctrx doesn't decrement and/or test CTR
|
| 157 |
+
_dbg_assert_msg_(POWERPC, inst.BO_2 & BO_DONT_DECREMENT_FLAG, "bcctrx with decrement and test CTR option is invalid!");
|
| 158 |
+
|
| 159 |
+
if (inst.BO_2 & BO_DONT_CHECK_CONDITION)
|
| 160 |
+
{
|
| 161 |
+
// BO_2 == 1z1zz -> b always
|
| 162 |
+
|
| 163 |
+
//NPC = CTR & 0xfffffffc;
|
| 164 |
+
gpr.Flush();
|
| 165 |
+
fpr.Flush();
|
| 166 |
+
|
| 167 |
+
MOV(32, R(RSCRATCH), PPCSTATE_CTR);
|
| 168 |
+
if (inst.LK_3)
|
| 169 |
+
MOV(32, PPCSTATE_LR, Imm32(js.compilerPC + 4)); // LR = PC + 4;
|
| 170 |
+
AND(32, R(RSCRATCH), Imm32(0xFFFFFFFC));
|
| 171 |
+
WriteExitDestInRSCRATCH(inst.LK_3, js.compilerPC + 4);
|
| 172 |
+
}
|
| 173 |
+
else
|
| 174 |
+
{
|
| 175 |
+
// Rare condition seen in (just some versions of?) Nintendo's NES Emulator
|
| 176 |
+
|
| 177 |
+
// BO_2 == 001zy -> b if false
|
| 178 |
+
// BO_2 == 011zy -> b if true
|
| 179 |
+
|
| 180 |
+
FixupBranch b = JumpIfCRFieldBit(inst.BI >> 2, 3 - (inst.BI & 3),
|
| 181 |
+
!(inst.BO_2 & BO_BRANCH_IF_TRUE));
|
| 182 |
+
MOV(32, R(RSCRATCH), PPCSTATE_CTR);
|
| 183 |
+
AND(32, R(RSCRATCH), Imm32(0xFFFFFFFC));
|
| 184 |
+
//MOV(32, PPCSTATE(pc), R(RSCRATCH)); => Already done in WriteExitDestInRSCRATCH()
|
| 185 |
+
if (inst.LK_3)
|
| 186 |
+
MOV(32, PPCSTATE_LR, Imm32(js.compilerPC + 4)); // LR = PC + 4;
|
| 187 |
+
|
| 188 |
+
gpr.Flush(FLUSH_MAINTAIN_STATE);
|
| 189 |
+
fpr.Flush(FLUSH_MAINTAIN_STATE);
|
| 190 |
+
WriteExitDestInRSCRATCH(inst.LK_3, js.compilerPC + 4);
|
| 191 |
+
// Would really like to continue the block here, but it ends. TODO.
|
| 192 |
+
SetJumpTarget(b);
|
| 193 |
+
|
| 194 |
+
if (!analyzer.HasOption(PPCAnalyst::PPCAnalyzer::OPTION_CONDITIONAL_CONTINUE))
|
| 195 |
+
{
|
| 196 |
+
gpr.Flush();
|
| 197 |
+
fpr.Flush();
|
| 198 |
+
WriteExit(js.compilerPC + 4);
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
void Jit64::bclrx(UGeckoInstruction inst)
|
| 204 |
+
{
|
| 205 |
+
INSTRUCTION_START
|
| 206 |
+
JITDISABLE(bJITBranchOff);
|
| 207 |
+
|
| 208 |
+
FixupBranch pCTRDontBranch;
|
| 209 |
+
if ((inst.BO & BO_DONT_DECREMENT_FLAG) == 0) // Decrement and test CTR
|
| 210 |
+
{
|
| 211 |
+
SUB(32, PPCSTATE_CTR, Imm8(1));
|
| 212 |
+
if (inst.BO & BO_BRANCH_IF_CTR_0)
|
| 213 |
+
pCTRDontBranch = J_CC(CC_NZ, true);
|
| 214 |
+
else
|
| 215 |
+
pCTRDontBranch = J_CC(CC_Z, true);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
FixupBranch pConditionDontBranch;
|
| 219 |
+
if ((inst.BO & BO_DONT_CHECK_CONDITION) == 0) // Test a CR bit
|
| 220 |
+
{
|
| 221 |
+
pConditionDontBranch = JumpIfCRFieldBit(inst.BI >> 2, 3 - (inst.BI & 3),
|
| 222 |
+
!(inst.BO_2 & BO_BRANCH_IF_TRUE));
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// This below line can be used to prove that blr "eats flags" in practice.
|
| 226 |
+
// This observation could let us do some useful optimizations.
|
| 227 |
+
#ifdef ACID_TEST
|
| 228 |
+
AND(32, PPCSTATE(cr), Imm32(~(0xFF000000)));
|
| 229 |
+
#endif
|
| 230 |
+
|
| 231 |
+
MOV(32, R(RSCRATCH), PPCSTATE_LR);
|
| 232 |
+
AND(32, R(RSCRATCH), Imm32(0xFFFFFFFC));
|
| 233 |
+
if (inst.LK)
|
| 234 |
+
MOV(32, PPCSTATE_LR, Imm32(js.compilerPC + 4));
|
| 235 |
+
|
| 236 |
+
gpr.Flush(FLUSH_MAINTAIN_STATE);
|
| 237 |
+
fpr.Flush(FLUSH_MAINTAIN_STATE);
|
| 238 |
+
WriteBLRExit();
|
| 239 |
+
|
| 240 |
+
if ((inst.BO & BO_DONT_CHECK_CONDITION) == 0)
|
| 241 |
+
SetJumpTarget( pConditionDontBranch );
|
| 242 |
+
if ((inst.BO & BO_DONT_DECREMENT_FLAG) == 0)
|
| 243 |
+
SetJumpTarget( pCTRDontBranch );
|
| 244 |
+
|
| 245 |
+
if (!analyzer.HasOption(PPCAnalyst::PPCAnalyzer::OPTION_CONDITIONAL_CONTINUE))
|
| 246 |
+
{
|
| 247 |
+
gpr.Flush();
|
| 248 |
+
fpr.Flush();
|
| 249 |
+
WriteExit(js.compilerPC + 4);
|
| 250 |
+
}
|
| 251 |
+
}
|
pool/shard010/C++/0111275_best_time_to_buy_and_sell_stock.cpp
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include <vector>
|
| 3 |
+
|
| 4 |
+
using std::cout;
|
| 5 |
+
using std::endl;
|
| 6 |
+
using std::vector;
|
| 7 |
+
|
| 8 |
+
class Solution {
|
| 9 |
+
public:
|
| 10 |
+
typedef vector<int>::size_type s_t;
|
| 11 |
+
int maxProfit(vector<int>& prices) {
|
| 12 |
+
if (prices.size() < 2)
|
| 13 |
+
return 0;
|
| 14 |
+
vector<int> dp(prices.size(), 0);
|
| 15 |
+
s_t min = 0;
|
| 16 |
+
for (s_t i = 1, iend = prices.size(); i < iend; ++i) {
|
| 17 |
+
int tmp = prices[i] - prices[min];
|
| 18 |
+
min = prices[min] < prices[i] ? min : i;
|
| 19 |
+
dp[i] = dp[i-1] < tmp ? tmp : dp[i-1];
|
| 20 |
+
}
|
| 21 |
+
return dp[prices.size()-1];
|
| 22 |
+
}
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
int main(void)
|
| 26 |
+
{
|
| 27 |
+
int array[] = {1, 2, 3, 4};
|
| 28 |
+
vector<int> vec(array, array+sizeof(array)/sizeof(array[0]));
|
| 29 |
+
cout << Solution().maxProfit(vec) << endl;
|
| 30 |
+
|
| 31 |
+
}
|
pool/shard010/C++/0111278_SetSelectionCommand.cpp
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2011 Apple Inc. All rights reserved.
|
| 3 |
+
*
|
| 4 |
+
* Redistribution and use in source and binary forms, with or without
|
| 5 |
+
* modification, are permitted provided that the following conditions
|
| 6 |
+
* are met:
|
| 7 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 8 |
+
* notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
* documentation and/or other materials provided with the distribution.
|
| 12 |
+
*
|
| 13 |
+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
| 14 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 16 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
| 17 |
+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 18 |
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 19 |
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 20 |
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
| 21 |
+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 22 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 23 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include "config.h"
|
| 27 |
+
#include "SetSelectionCommand.h"
|
| 28 |
+
|
| 29 |
+
#include "Document.h"
|
| 30 |
+
#include "Frame.h"
|
| 31 |
+
|
| 32 |
+
namespace WebCore {
|
| 33 |
+
|
| 34 |
+
SetSelectionCommand::SetSelectionCommand(const VisibleSelection& selection, FrameSelection::SetSelectionOptions options)
|
| 35 |
+
: SimpleEditCommand(selection.base().anchorNode()->document())
|
| 36 |
+
, m_options(options)
|
| 37 |
+
, m_selectionToSet(selection)
|
| 38 |
+
{
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
void SetSelectionCommand::doApply()
|
| 42 |
+
{
|
| 43 |
+
FrameSelection& selection = frame().selection();
|
| 44 |
+
|
| 45 |
+
if (selection.shouldChangeSelection(m_selectionToSet) && !m_selectionToSet.isNoneOrOrphaned()) {
|
| 46 |
+
selection.setSelection(m_selectionToSet, m_options);
|
| 47 |
+
setEndingSelection(m_selectionToSet);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
void SetSelectionCommand::doUnapply()
|
| 52 |
+
{
|
| 53 |
+
FrameSelection& selection = frame().selection();
|
| 54 |
+
|
| 55 |
+
if (selection.shouldChangeSelection(startingSelection()) && !startingSelection().isNoneOrOrphaned())
|
| 56 |
+
selection.setSelection(startingSelection(), m_options);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
} // namespace WebCore
|
pool/shard010/C++/0111279_unnamed_event.cc
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010-2016, Google Inc.
|
| 2 |
+
// All rights reserved.
|
| 3 |
+
//
|
| 4 |
+
// Redistribution and use in source and binary forms, with or without
|
| 5 |
+
// modification, are permitted provided that the following conditions are
|
| 6 |
+
// met:
|
| 7 |
+
//
|
| 8 |
+
// * Redistributions of source code must retain the above copyright
|
| 9 |
+
// notice, this list of conditions and the following disclaimer.
|
| 10 |
+
// * Redistributions in binary form must reproduce the above
|
| 11 |
+
// copyright notice, this list of conditions and the following disclaimer
|
| 12 |
+
// in the documentation and/or other materials provided with the
|
| 13 |
+
// distribution.
|
| 14 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 15 |
+
// contributors may be used to endorse or promote products derived from
|
| 16 |
+
// this software without specific prior written permission.
|
| 17 |
+
//
|
| 18 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 21 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 24 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 25 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 26 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 27 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 28 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
|
| 30 |
+
#include "base/unnamed_event.h"
|
| 31 |
+
|
| 32 |
+
#ifdef OS_WIN
|
| 33 |
+
#include <windows.h>
|
| 34 |
+
#else // OS_WIN
|
| 35 |
+
#include <errno.h>
|
| 36 |
+
#include <pthread.h>
|
| 37 |
+
#include <sys/time.h>
|
| 38 |
+
#endif // OS_WIN
|
| 39 |
+
|
| 40 |
+
#include "base/logging.h"
|
| 41 |
+
#include "base/port.h"
|
| 42 |
+
|
| 43 |
+
namespace gbase {
|
| 44 |
+
|
| 45 |
+
#ifdef OS_WIN
|
| 46 |
+
UnnamedEvent::UnnamedEvent()
|
| 47 |
+
: handle_(::CreateEvent(NULL, FALSE, FALSE, NULL)) {
|
| 48 |
+
// Use Auto reset mode of Win32 Event. (2nd arg of CreateEvent).
|
| 49 |
+
// pthread_cond_signal: auto reset mode.
|
| 50 |
+
// pthread_cond_broadcast: manual reset mode.
|
| 51 |
+
if (NULL == handle_.get()) {
|
| 52 |
+
LOG(ERROR) << "CreateEvent failed: " << ::GetLastError();
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
UnnamedEvent::~UnnamedEvent() {}
|
| 57 |
+
|
| 58 |
+
bool UnnamedEvent::IsAvailable() const {
|
| 59 |
+
return (NULL != handle_.get());
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
bool UnnamedEvent::Notify() {
|
| 63 |
+
if (!IsAvailable()) {
|
| 64 |
+
LOG(WARNING) << "Event object is not available";
|
| 65 |
+
return false;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
if (!::SetEvent(handle_.get())) {
|
| 69 |
+
LOG(ERROR) << "SetEvent failed: " << ::GetLastError();
|
| 70 |
+
return false;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
return true;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
bool UnnamedEvent::Wait(int msec) {
|
| 77 |
+
if (!IsAvailable()) {
|
| 78 |
+
return true; // assume that it is already raised
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if (msec < 0) {
|
| 82 |
+
msec = INFINITE;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return WAIT_TIMEOUT !=
|
| 86 |
+
::WaitForSingleObject(handle_.get(), msec);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
#else // OS_WIN
|
| 90 |
+
|
| 91 |
+
namespace {
|
| 92 |
+
class ScopedPthreadMutexLock {
|
| 93 |
+
public:
|
| 94 |
+
explicit ScopedPthreadMutexLock(pthread_mutex_t *mutex) : mutex_(mutex) {
|
| 95 |
+
pthread_mutex_lock(mutex_);
|
| 96 |
+
}
|
| 97 |
+
~ScopedPthreadMutexLock() {
|
| 98 |
+
pthread_mutex_unlock(mutex_);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
private:
|
| 102 |
+
pthread_mutex_t *mutex_;
|
| 103 |
+
DISALLOW_COPY_AND_ASSIGN(ScopedPthreadMutexLock);
|
| 104 |
+
};
|
| 105 |
+
} // namespace
|
| 106 |
+
|
| 107 |
+
UnnamedEvent::UnnamedEvent() : notified_(false) {
|
| 108 |
+
pthread_mutex_init(&mutex_, NULL);
|
| 109 |
+
pthread_cond_init(&cond_, NULL);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// It is necessary to ensure that no threads wait for this event before the
|
| 113 |
+
// destruction.
|
| 114 |
+
UnnamedEvent::~UnnamedEvent() {
|
| 115 |
+
pthread_mutex_destroy(&mutex_);
|
| 116 |
+
pthread_cond_destroy(&cond_);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
bool UnnamedEvent::IsAvailable() const {
|
| 120 |
+
return true;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
bool UnnamedEvent::Notify() {
|
| 124 |
+
{
|
| 125 |
+
ScopedPthreadMutexLock lock(&mutex_);
|
| 126 |
+
notified_ = true;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Note: Need to awake all threads waiting for this event. Otherwise
|
| 130 |
+
// some thread would start to work incorrectly in some cases.
|
| 131 |
+
// An example error scenario is:
|
| 132 |
+
// - there are four threads, A, B, C and D.
|
| 133 |
+
// - A and B are producers. C and D are consumers.
|
| 134 |
+
// - C and D start to wait this event.
|
| 135 |
+
// - Then A notifies.
|
| 136 |
+
// - A takes the lock.
|
| 137 |
+
// - set notified_ true.
|
| 138 |
+
// - A releases the lock.
|
| 139 |
+
// - Then before A sends a signal to awake a thread (either C or D),
|
| 140 |
+
// B takes the lock.
|
| 141 |
+
// - A sends a signal, but both C and D are sleeping as the lock is
|
| 142 |
+
// still taken by B.
|
| 143 |
+
// - B releases the lock. So one of the thread (let's assume C for this
|
| 144 |
+
// example) starts to run, because it can take the lock.
|
| 145 |
+
// - B also sends a signal again.
|
| 146 |
+
// - C overrides notified_ to false, and releases the lock.
|
| 147 |
+
// - At last, D starts to run wrongly.
|
| 148 |
+
// The broadcast and while (in Wait) idiom is a popular way to fix such
|
| 149 |
+
// cases.
|
| 150 |
+
pthread_cond_broadcast(&cond_);
|
| 151 |
+
return true;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
bool UnnamedEvent::Wait(int msec) {
|
| 155 |
+
ScopedPthreadMutexLock lock(&mutex_);
|
| 156 |
+
if (!notified_) {
|
| 157 |
+
// Need to wait actually.
|
| 158 |
+
if (msec < 0) {
|
| 159 |
+
// Wait forever.
|
| 160 |
+
while (!notified_) {
|
| 161 |
+
pthread_cond_wait(&cond_, &mutex_);
|
| 162 |
+
}
|
| 163 |
+
} else {
|
| 164 |
+
// Wait with time out.
|
| 165 |
+
struct timeval tv;
|
| 166 |
+
if (gettimeofday(&tv, NULL) != 0) {
|
| 167 |
+
LOG(ERROR) << "Failed to take the current time: " << errno;
|
| 168 |
+
return false;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
struct timespec timeout;
|
| 172 |
+
timeout.tv_sec = tv.tv_sec + msec / 1000;
|
| 173 |
+
timeout.tv_nsec = 1000 * (tv.tv_usec + 1000 * (msec % 1000));
|
| 174 |
+
|
| 175 |
+
// if tv_nsec >= 10^9, pthread_cond_timedwait may return EINVAL
|
| 176 |
+
while (timeout.tv_nsec >= 1000000000) {
|
| 177 |
+
timeout.tv_sec++;
|
| 178 |
+
timeout.tv_nsec -= 1000000000;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
int result = 0;
|
| 182 |
+
while (!notified_ && result == 0) {
|
| 183 |
+
result = pthread_cond_timedwait(&cond_, &mutex_, &timeout);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
if (result != 0) {
|
| 187 |
+
// Time out.
|
| 188 |
+
return false;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
DCHECK(notified_);
|
| 193 |
+
notified_ = false;
|
| 194 |
+
return true;
|
| 195 |
+
}
|
| 196 |
+
#endif // OS_WIN
|
| 197 |
+
} // namespace gbase
|
pool/shard010/C++/0111283_connect_test.cpp
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) Kai Blin <kai.blin@gmail.com> 2007
|
| 3 |
+
|
| 4 |
+
This program is free software; you can redistribute it and/or modify
|
| 5 |
+
it under the terms of the GNU General Public License as published by
|
| 6 |
+
the Free Software Foundation; version 2 of the License.
|
| 7 |
+
|
| 8 |
+
This program is distributed in the hope that it will be useful,
|
| 9 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 10 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 11 |
+
GNU General Public License for more details.
|
| 12 |
+
|
| 13 |
+
You should have received a copy of the GNU General Public License
|
| 14 |
+
along with this program; if not, write to the Free Software
|
| 15 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
| 16 |
+
|
| 17 |
+
A client/server connect test for dplay.
|
| 18 |
+
*/
|
| 19 |
+
#define INITGUID
|
| 20 |
+
#define _WIN32_DCOM
|
| 21 |
+
#include <dplay8.h>
|
| 22 |
+
#include <dplobby.h>
|
| 23 |
+
#include <cstdio>
|
| 24 |
+
#include <vector>
|
| 25 |
+
|
| 26 |
+
// {EF016237-BEEE-402a-A2D6-A2694C109574}
|
| 27 |
+
DEFINE_GUID(CONNECT_TEST,
|
| 28 |
+
0xef016237, 0xbeee, 0x402a, 0xa2, 0xd6, 0xa2, 0x69, 0x4c, 0x10, 0x95, 0x74);
|
| 29 |
+
|
| 30 |
+
typedef struct _dp_player_list {
|
| 31 |
+
DPID dpid;
|
| 32 |
+
char name[15];
|
| 33 |
+
DWORD flags;
|
| 34 |
+
struct _dp_player_list *next;
|
| 35 |
+
} dp_player_list;
|
| 36 |
+
|
| 37 |
+
//------------------------ Globals ----------------------
|
| 38 |
+
IDirectPlay8Peer *pDP = NULL;
|
| 39 |
+
IDirectPlay8Address *pDP_addr = NULL;
|
| 40 |
+
BOOL is_server = FALSE;
|
| 41 |
+
|
| 42 |
+
//------------------ Function prototypes ----------------
|
| 43 |
+
DWORD handleArgs(int argc, char **argv);
|
| 44 |
+
HRESULT WINAPI dPlayMsgHandler(void * user_context, DWORD msg_id, void * msg_buff);
|
| 45 |
+
HRESULT initDPlay();
|
| 46 |
+
void cleanupDPlay();
|
| 47 |
+
HRESULT enumDPlaySP();
|
| 48 |
+
HRESULT getDPlayAddr();
|
| 49 |
+
HRESULT hostGame();
|
| 50 |
+
|
| 51 |
+
int main(int argc, char** argv)
|
| 52 |
+
{
|
| 53 |
+
HRESULT hr;
|
| 54 |
+
DWORD dwresult;
|
| 55 |
+
MSG msg;
|
| 56 |
+
BOOL done = FALSE;
|
| 57 |
+
int i = 0;
|
| 58 |
+
|
| 59 |
+
if((dwresult = handleArgs(argc, argv)) == -1)
|
| 60 |
+
{
|
| 61 |
+
return dwresult;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
if(FAILED(hr = CoInitialize(NULL)))
|
| 65 |
+
{
|
| 66 |
+
return -1;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if(FAILED(hr = initDPlay()))
|
| 70 |
+
{
|
| 71 |
+
fprintf(stderr, "Failed to init dplay: 0x%08x\n", hr);
|
| 72 |
+
goto cleanup;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
if(FAILED(hr = enumDPlaySP()))
|
| 76 |
+
{
|
| 77 |
+
fprintf(stderr, "Failed enumerating service providers: 0x%08x\n", hr);
|
| 78 |
+
goto cleanup;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if(FAILED(hr = getDPlayAddr()))
|
| 82 |
+
{
|
| 83 |
+
fprintf(stderr, "Failed to get IDirectPlay8Address com object: 0x%08x\n", hr);
|
| 84 |
+
goto cleanup;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if(is_server)
|
| 88 |
+
{
|
| 89 |
+
printf("Selected server mode, hosting a game.\n");
|
| 90 |
+
if(FAILED(hr = hostGame()))
|
| 91 |
+
{
|
| 92 |
+
fprintf(stderr, "Failed to host game: 0x%08x\n", hr);
|
| 93 |
+
goto cleanup;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
else
|
| 97 |
+
{
|
| 98 |
+
printf("Selected client mode, enumerating games.\n");
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
#if 0
|
| 102 |
+
while(!done)
|
| 103 |
+
{
|
| 104 |
+
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
| 105 |
+
{
|
| 106 |
+
TranslateMessage(&msg);
|
| 107 |
+
DispatchMessage(&msg);
|
| 108 |
+
}
|
| 109 |
+
else
|
| 110 |
+
{
|
| 111 |
+
// fake game loop
|
| 112 |
+
++i;
|
| 113 |
+
if(is_server)
|
| 114 |
+
printf("S");
|
| 115 |
+
else
|
| 116 |
+
printf("c");
|
| 117 |
+
if(i > 25)
|
| 118 |
+
break;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
#endif
|
| 122 |
+
puts("Press any key to exit.");
|
| 123 |
+
getchar();
|
| 124 |
+
|
| 125 |
+
cleanup:
|
| 126 |
+
cleanupDPlay();
|
| 127 |
+
CoUninitialize();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
DWORD handleArgs(int argc, char **argv)
|
| 131 |
+
{
|
| 132 |
+
if(argc < 2)
|
| 133 |
+
{
|
| 134 |
+
is_server = FALSE;
|
| 135 |
+
return 0;
|
| 136 |
+
}
|
| 137 |
+
if(strcmp(argv[1], "server") == 0)
|
| 138 |
+
is_server = TRUE;
|
| 139 |
+
|
| 140 |
+
return 0;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
HRESULT WINAPI dPlayMsgHandler(void * user_context, DWORD msg_id, void * msg_buff)
|
| 144 |
+
{
|
| 145 |
+
return S_OK;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
HRESULT enumDPlaySP()
|
| 149 |
+
{
|
| 150 |
+
HRESULT hr;
|
| 151 |
+
DWORD items = 0, size = 0, i;
|
| 152 |
+
DPN_SERVICE_PROVIDER_INFO *dp_sp_info, *dp_sp_item;
|
| 153 |
+
|
| 154 |
+
hr = pDP->EnumServiceProviders(NULL, NULL, NULL, &size, &items, 0);
|
| 155 |
+
|
| 156 |
+
if(hr != DPNERR_BUFFERTOOSMALL)
|
| 157 |
+
{
|
| 158 |
+
fprintf(stderr, "Failed to get the service provider array size: 0x%08x\n", hr);
|
| 159 |
+
return hr;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
dp_sp_info = static_cast<DPN_SERVICE_PROVIDER_INFO *>(CoTaskMemAlloc(size));
|
| 163 |
+
|
| 164 |
+
if(FAILED(hr = pDP->EnumServiceProviders(NULL, NULL, dp_sp_info, &size, &items, 0)))
|
| 165 |
+
{
|
| 166 |
+
fprintf(stderr, "Failed to enumerate service providers: 0x%08x\n", hr);
|
| 167 |
+
return hr;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
dp_sp_item = dp_sp_info;
|
| 171 |
+
printf("Found %d providers:\n", items);
|
| 172 |
+
for(i = 0; i < items; ++i)
|
| 173 |
+
{
|
| 174 |
+
printf("Provider: %S\n", dp_sp_item->pwszName);
|
| 175 |
+
++dp_sp_item;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
CoTaskMemFree(dp_sp_info);
|
| 179 |
+
return hr;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
HRESULT getDPlayAddr()
|
| 183 |
+
{
|
| 184 |
+
HRESULT hr;
|
| 185 |
+
|
| 186 |
+
if(FAILED(hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Address,
|
| 187 |
+
(LPVOID *)&pDP_addr)))
|
| 188 |
+
{
|
| 189 |
+
fprintf(stderr, "Failed to create IDirectPlay8Address instance: 0x%08x\n", hr);
|
| 190 |
+
return hr;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
if(FAILED(pDP_addr->SetSP(&CLSID_DP8SP_TCPIP)))
|
| 194 |
+
{
|
| 195 |
+
fprintf(stderr, "Failed to set TCP/IP service provider: 0x%08x\n", hr);
|
| 196 |
+
return hr;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
printf("Loaded the TCP/IP service provider.\n");
|
| 200 |
+
return hr;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
HRESULT hostGame()
|
| 204 |
+
{
|
| 205 |
+
HRESULT hr;
|
| 206 |
+
DPN_APPLICATION_DESC app_desc;
|
| 207 |
+
|
| 208 |
+
ZeroMemory(&app_desc, sizeof(DPN_APPLICATION_DESC));
|
| 209 |
+
app_desc.dwSize = sizeof(DPN_APPLICATION_DESC);
|
| 210 |
+
app_desc.guidApplication = CONNECT_TEST;
|
| 211 |
+
|
| 212 |
+
if(FAILED(hr = pDP->Host(&app_desc, &pDP_addr, 1, NULL, NULL, NULL, DPNHOST_OKTOQUERYFORADDRESSING)))
|
| 213 |
+
{
|
| 214 |
+
fprintf(stderr, "Failed to host a game: 0x%08x\n", hr);
|
| 215 |
+
return hr;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
printf("Hosted game.\n");
|
| 219 |
+
|
| 220 |
+
return hr;
|
| 221 |
+
}
|
| 222 |
+
|
pool/shard010/C++/0111284_main.cpp
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <string>
|
| 2 |
+
#include <iostream>
|
| 3 |
+
#include <fstream>
|
| 4 |
+
#include <streambuf>
|
| 5 |
+
#include <algorithm>
|
| 6 |
+
|
| 7 |
+
#include <evm2wasm.h>
|
| 8 |
+
|
| 9 |
+
using namespace std;
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
int main(int argc, char **argv) {
|
| 13 |
+
if (argc < 2) {
|
| 14 |
+
cerr << "Usage: " << argv[0] << " <EVM file> [--wast]" << endl;
|
| 15 |
+
return 1;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
bool wast = false;
|
| 19 |
+
if (argc == 3) {
|
| 20 |
+
wast = (string(argv[2]) == "--wast");
|
| 21 |
+
if (!wast) {
|
| 22 |
+
cerr << "Usage: " << argv[0] << " <EVM file> [--wast]" << endl;
|
| 23 |
+
return 1;
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
ifstream input(argv[1]);
|
| 28 |
+
if (!input.is_open()) {
|
| 29 |
+
cerr << "File not found: " << argv[1] << endl;
|
| 30 |
+
return 1;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
string str(
|
| 34 |
+
(std::istreambuf_iterator<char>(input)),
|
| 35 |
+
std::istreambuf_iterator<char>()
|
| 36 |
+
);
|
| 37 |
+
|
| 38 |
+
// clean input of any whitespace (including space and new lines)
|
| 39 |
+
str.erase(remove_if(str.begin(), str.end(), [](unsigned char x){return std::isspace(x);}), str.end());
|
| 40 |
+
|
| 41 |
+
if (wast) {
|
| 42 |
+
cout << evm2wasm::evmhex2wast(str);
|
| 43 |
+
} else {
|
| 44 |
+
cout << evm2wasm::evmhex2wasm(str);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return 0;
|
| 48 |
+
}
|
pool/shard010/C++/0111285_speedwidget.cpp
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Bittorrent Client using Qt and libtorrent.
|
| 3 |
+
* Copyright (C) 2015 Anton Lashkov <lenton_91@mail.ru>
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or
|
| 6 |
+
* modify it under the terms of the GNU General Public License
|
| 7 |
+
* as published by the Free Software Foundation; either version 2
|
| 8 |
+
* of the License, or (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 18 |
+
*
|
| 19 |
+
* In addition, as a special exception, the copyright holders give permission to
|
| 20 |
+
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
| 21 |
+
* modified versions of it that use the same license as the "OpenSSL" library),
|
| 22 |
+
* and distribute the linked executables. You must obey the GNU General Public
|
| 23 |
+
* License in all respects for all of the code used other than "OpenSSL". If you
|
| 24 |
+
* modify file(s), you may extend this exception to your version of the file(s),
|
| 25 |
+
* but you are not obligated to do so. If you do not wish to do so, delete this
|
| 26 |
+
* exception statement from your version.
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
#include "speedwidget.h"
|
| 30 |
+
|
| 31 |
+
#include <QVBoxLayout>
|
| 32 |
+
#include <QHBoxLayout>
|
| 33 |
+
#include <QLabel>
|
| 34 |
+
#include <QMenu>
|
| 35 |
+
#include <QSignalMapper>
|
| 36 |
+
|
| 37 |
+
#include <libtorrent/session_status.hpp>
|
| 38 |
+
|
| 39 |
+
#include "propertieswidget.h"
|
| 40 |
+
#include "base/bittorrent/session.h"
|
| 41 |
+
#include "base/bittorrent/sessionstatus.h"
|
| 42 |
+
#include "base/preferences.h"
|
| 43 |
+
#include "base/utils/misc.h"
|
| 44 |
+
|
| 45 |
+
ComboBoxMenuButton::ComboBoxMenuButton(QWidget *parent, QMenu *menu)
|
| 46 |
+
: QComboBox(parent)
|
| 47 |
+
, m_menu(menu)
|
| 48 |
+
{
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
void ComboBoxMenuButton::showPopup()
|
| 52 |
+
{
|
| 53 |
+
QPoint p = mapToGlobal(QPoint(0, height()));
|
| 54 |
+
m_menu->exec(p);
|
| 55 |
+
QComboBox::hidePopup();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
SpeedWidget::SpeedWidget(PropertiesWidget *parent)
|
| 60 |
+
: QWidget(parent)
|
| 61 |
+
{
|
| 62 |
+
m_layout = new QVBoxLayout(this);
|
| 63 |
+
m_layout->setContentsMargins(0, 0, 0, 0);
|
| 64 |
+
|
| 65 |
+
m_hlayout = new QHBoxLayout();
|
| 66 |
+
m_hlayout->setContentsMargins(0, 0, 0, 0);
|
| 67 |
+
|
| 68 |
+
m_periodLabel = new QLabel("<b>" + tr("Period:") + "</b>");
|
| 69 |
+
|
| 70 |
+
m_periodCombobox = new QComboBox();
|
| 71 |
+
m_periodCombobox->addItem(tr("1 Minute"));
|
| 72 |
+
m_periodCombobox->addItem(tr("5 Minutes"));
|
| 73 |
+
m_periodCombobox->addItem(tr("30 Minutes"));
|
| 74 |
+
m_periodCombobox->addItem(tr("6 Hours"));
|
| 75 |
+
|
| 76 |
+
connect(m_periodCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(onPeriodChange(int)));
|
| 77 |
+
|
| 78 |
+
m_graphsMenu = new QMenu();
|
| 79 |
+
m_graphsMenu->addAction(tr("Total Upload"));
|
| 80 |
+
m_graphsMenu->addAction(tr("Total Download"));
|
| 81 |
+
m_graphsMenu->addAction(tr("Payload Upload"));
|
| 82 |
+
m_graphsMenu->addAction(tr("Payload Download"));
|
| 83 |
+
m_graphsMenu->addAction(tr("Overhead Upload"));
|
| 84 |
+
m_graphsMenu->addAction(tr("Overhead Download"));
|
| 85 |
+
m_graphsMenu->addAction(tr("DHT Upload"));
|
| 86 |
+
m_graphsMenu->addAction(tr("DHT Download"));
|
| 87 |
+
m_graphsMenu->addAction(tr("Tracker Upload"));
|
| 88 |
+
m_graphsMenu->addAction(tr("Tracker Download"));
|
| 89 |
+
|
| 90 |
+
m_graphsMenuActions = m_graphsMenu->actions();
|
| 91 |
+
m_graphsSignalMapper = new QSignalMapper();
|
| 92 |
+
|
| 93 |
+
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) {
|
| 94 |
+
QAction *action = m_graphsMenuActions.at(id);
|
| 95 |
+
action->setCheckable(true);
|
| 96 |
+
action->setChecked(true);
|
| 97 |
+
connect(action, SIGNAL(changed()), m_graphsSignalMapper, SLOT(map()));
|
| 98 |
+
m_graphsSignalMapper->setMapping(action, id);
|
| 99 |
+
}
|
| 100 |
+
connect(m_graphsSignalMapper, SIGNAL(mapped(int)), this, SLOT(onGraphChange(int)));
|
| 101 |
+
|
| 102 |
+
m_graphsButton = new ComboBoxMenuButton(this, m_graphsMenu);
|
| 103 |
+
m_graphsButton->addItem(tr("Select Graphs"));
|
| 104 |
+
|
| 105 |
+
m_hlayout->addWidget(m_periodLabel);
|
| 106 |
+
m_hlayout->addWidget(m_periodCombobox);
|
| 107 |
+
m_hlayout->addStretch();
|
| 108 |
+
m_hlayout->addWidget(m_graphsButton);
|
| 109 |
+
|
| 110 |
+
m_plot = new SpeedPlotView(this);
|
| 111 |
+
|
| 112 |
+
m_layout->addLayout(m_hlayout);
|
| 113 |
+
m_layout->addWidget(m_plot);
|
| 114 |
+
|
| 115 |
+
loadSettings();
|
| 116 |
+
|
| 117 |
+
m_isUpdating = true;
|
| 118 |
+
m_updateFuture = QtConcurrent::run(this, &SpeedWidget::update);
|
| 119 |
+
|
| 120 |
+
m_plot->show();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
SpeedWidget::~SpeedWidget()
|
| 124 |
+
{
|
| 125 |
+
qDebug("SpeedWidget::~SpeedWidget() ENTER");
|
| 126 |
+
|
| 127 |
+
m_isUpdating = false;
|
| 128 |
+
m_updateFuture.waitForFinished();
|
| 129 |
+
|
| 130 |
+
saveSettings();
|
| 131 |
+
|
| 132 |
+
qDebug("SpeedWidget::~SpeedWidget() EXIT");
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
void SpeedWidget::update()
|
| 136 |
+
{
|
| 137 |
+
while (m_isUpdating) {
|
| 138 |
+
|
| 139 |
+
BitTorrent::SessionStatus btStatus = BitTorrent::Session::instance()->status();
|
| 140 |
+
|
| 141 |
+
m_plot->pushXPoint(QDateTime::currentDateTime().toTime_t());
|
| 142 |
+
m_plot->pushYPoint(SpeedPlotView::UP, btStatus.uploadRate());
|
| 143 |
+
m_plot->pushYPoint(SpeedPlotView::DOWN, btStatus.downloadRate());
|
| 144 |
+
m_plot->pushYPoint(SpeedPlotView::PAYLOAD_UP, btStatus.payloadUploadRate());
|
| 145 |
+
m_plot->pushYPoint(SpeedPlotView::PAYLOAD_DOWN, btStatus.payloadDownloadRate());
|
| 146 |
+
m_plot->pushYPoint(SpeedPlotView::OVERHEAD_UP, btStatus.ipOverheadUploadRate());
|
| 147 |
+
m_plot->pushYPoint(SpeedPlotView::OVERHEAD_DOWN, btStatus.ipOverheadDownloadRate());
|
| 148 |
+
m_plot->pushYPoint(SpeedPlotView::DHT_UP, btStatus.dhtUploadRate());
|
| 149 |
+
m_plot->pushYPoint(SpeedPlotView::DHT_DOWN, btStatus.dhtDownloadRate());
|
| 150 |
+
m_plot->pushYPoint(SpeedPlotView::TRACKER_UP, btStatus.trackerUploadRate());
|
| 151 |
+
m_plot->pushYPoint(SpeedPlotView::TRACKER_DOWN, btStatus.trackerDownloadRate());
|
| 152 |
+
|
| 153 |
+
QMetaObject::invokeMethod(this, "graphUpdate", Qt::QueuedConnection);
|
| 154 |
+
Utils::Misc::msleep(1000);
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
void SpeedWidget::graphUpdate()
|
| 159 |
+
{
|
| 160 |
+
m_plot->replot();
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
void SpeedWidget::onPeriodChange(int period)
|
| 164 |
+
{
|
| 165 |
+
m_plot->setViewableLastPoints(static_cast<SpeedPlotView::TimePeriod>(period));
|
| 166 |
+
graphUpdate();
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
void SpeedWidget::onGraphChange(int id)
|
| 170 |
+
{
|
| 171 |
+
QAction *action = m_graphsMenuActions.at(id);
|
| 172 |
+
m_plot->setGraphEnable(static_cast<SpeedPlotView::GraphID>(id), action->isChecked());
|
| 173 |
+
|
| 174 |
+
graphUpdate();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
void SpeedWidget::loadSettings()
|
| 178 |
+
{
|
| 179 |
+
Preferences *preferences = Preferences::instance();
|
| 180 |
+
|
| 181 |
+
int periodIndex = preferences->getSpeedWidgetPeriod();
|
| 182 |
+
m_periodCombobox->setCurrentIndex(periodIndex);
|
| 183 |
+
onPeriodChange(static_cast<SpeedPlotView::TimePeriod>(periodIndex));
|
| 184 |
+
|
| 185 |
+
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) {
|
| 186 |
+
QAction *action = m_graphsMenuActions.at(id);
|
| 187 |
+
bool enable = preferences->getSpeedWidgetGraphEnable(id);
|
| 188 |
+
|
| 189 |
+
action->setChecked(enable);
|
| 190 |
+
m_plot->setGraphEnable(static_cast<SpeedPlotView::GraphID>(id), enable);
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
void SpeedWidget::saveSettings() const
|
| 195 |
+
{
|
| 196 |
+
Preferences *preferences = Preferences::instance();
|
| 197 |
+
|
| 198 |
+
preferences->setSpeedWidgetPeriod(m_periodCombobox->currentIndex());
|
| 199 |
+
|
| 200 |
+
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) {
|
| 201 |
+
QAction *action = m_graphsMenuActions.at(id);
|
| 202 |
+
preferences->setSpeedWidgetGraphEnable(id, action->isChecked());
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
pool/shard010/C++/0111286_camera_self_filter_server.cpp
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*********************************************************************
|
| 2 |
+
*
|
| 3 |
+
* Software License Agreement (BSD License)
|
| 4 |
+
*
|
| 5 |
+
* Copyright (c) 2008, Robert Bosch LLC.
|
| 6 |
+
* All rights reserved.
|
| 7 |
+
*
|
| 8 |
+
* Redistribution and use in source and binary forms, with or without
|
| 9 |
+
* modification, are permitted provided that the following conditions
|
| 10 |
+
* are met:
|
| 11 |
+
*
|
| 12 |
+
* * Redistributions of source code must retain the above copyright
|
| 13 |
+
* notice, this list of conditions and the following disclaimer.
|
| 14 |
+
* * Redistributions in binary form must reproduce the above
|
| 15 |
+
* copyright notice, this list of conditions and the following
|
| 16 |
+
* disclaimer in the documentation and/or other materials provided
|
| 17 |
+
* with the distribution.
|
| 18 |
+
* * Neither the name of the Robert Bosch nor the names of its
|
| 19 |
+
* contributors may be used to endorse or promote products derived
|
| 20 |
+
* from this software without specific prior written permission.
|
| 21 |
+
*
|
| 22 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 23 |
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 24 |
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 25 |
+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 26 |
+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 27 |
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 28 |
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 29 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 30 |
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 31 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 32 |
+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 33 |
+
* POSSIBILITY OF SUCH DAMAGE.
|
| 34 |
+
*
|
| 35 |
+
*********************************************************************/
|
| 36 |
+
|
| 37 |
+
/*
|
| 38 |
+
* camera_self_filter.cpp
|
| 39 |
+
*
|
| 40 |
+
* Created on: Oct 6, 2010
|
| 41 |
+
* Author: christian
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
#include <cstdio>
|
| 45 |
+
|
| 46 |
+
#include <ros/ros.h>
|
| 47 |
+
#include <opencv/cv.h>
|
| 48 |
+
#include <opencv/highgui.h>
|
| 49 |
+
#include "cv_bridge/CvBridge.h"
|
| 50 |
+
#include "sensor_msgs/Image.h"
|
| 51 |
+
#include "sensor_msgs/CameraInfo.h"
|
| 52 |
+
#include "image_transport/image_transport.h"
|
| 53 |
+
#include <image_geometry/pinhole_camera_model.h>
|
| 54 |
+
|
| 55 |
+
#define GL_GLEXT_PROTOTYPES
|
| 56 |
+
#include <GL/gl.h>
|
| 57 |
+
#include <GL/glext.h>
|
| 58 |
+
#include <GL/freeglut.h>
|
| 59 |
+
|
| 60 |
+
#include "camera_self_filter/robotMeshModel.h"
|
| 61 |
+
#include "camera_self_filter/mask.h"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
RobotMeshModel* robmod=NULL;
|
| 65 |
+
IplImage* ipl_maskBGRA = NULL;
|
| 66 |
+
IplImage* ipl_maskBW = NULL;
|
| 67 |
+
|
| 68 |
+
bool inverted;
|
| 69 |
+
sensor_msgs::CvBridge bridge;
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
void initializeGL ()
|
| 73 |
+
{
|
| 74 |
+
glClearColor(0, 0, 0, 0);
|
| 75 |
+
// glEnable(GL_LIGHTING);
|
| 76 |
+
// glEnable(GL_LIGHT0);
|
| 77 |
+
glEnable(GL_NORMALIZE);
|
| 78 |
+
glEnable(GL_COLOR_MATERIAL);
|
| 79 |
+
glEnable(GL_CULL_FACE);
|
| 80 |
+
glEnable(GL_DEPTH_TEST);
|
| 81 |
+
glShadeModel(GL_SMOOTH);
|
| 82 |
+
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
| 83 |
+
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
| 84 |
+
GL_LINEAR_MIPMAP_LINEAR);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
//function that draws the robot at current state
|
| 90 |
+
void display() {
|
| 91 |
+
|
| 92 |
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
| 93 |
+
|
| 94 |
+
robmod->setCamera();
|
| 95 |
+
robmod->setCameraPose();
|
| 96 |
+
robmod->paintRobot();
|
| 97 |
+
glReadPixels(0, 0, robmod->cam_info_->width, robmod->cam_info_->height , GL_BGRA, GL_UNSIGNED_BYTE, ipl_maskBGRA->imageData);
|
| 98 |
+
|
| 99 |
+
glutSwapBuffers();
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
sensor_msgs::ImagePtr calc_and_publish_BWMask(const ros::Time time_stamp, const std::string frame_id ){
|
| 105 |
+
robmod->updateRobotLinks(time_stamp);
|
| 106 |
+
glutPostRedisplay();
|
| 107 |
+
glutMainLoopEvent();
|
| 108 |
+
cvCvtColor(ipl_maskBGRA, ipl_maskBW, CV_BGRA2GRAY);
|
| 109 |
+
cvFlip(ipl_maskBW);
|
| 110 |
+
if (inverted)
|
| 111 |
+
cvNot(ipl_maskBW,ipl_maskBW);
|
| 112 |
+
|
| 113 |
+
sensor_msgs::ImagePtr img_msg = sensor_msgs::CvBridge::cvToImgMsg(ipl_maskBW);
|
| 114 |
+
img_msg->header.frame_id = frame_id;
|
| 115 |
+
img_msg->header.stamp = time_stamp;
|
| 116 |
+
return img_msg;
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
bool calcMaskCB(camera_self_filter::maskRequest& req, camera_self_filter::maskResponse& res){
|
| 123 |
+
sensor_msgs::ImagePtr img = calc_and_publish_BWMask(req.header.stamp, req.header.frame_id);
|
| 124 |
+
res.mask_image = *img;
|
| 125 |
+
return true;
|
| 126 |
+
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
int main(int argc, char **argv) {
|
| 131 |
+
glutInit(&argc, argv);
|
| 132 |
+
ros::init(argc, argv, "robot_self_filter");
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
//create selfilter service
|
| 136 |
+
ros::NodeHandle nh;
|
| 137 |
+
ros::NodeHandle nh_priv("~");
|
| 138 |
+
|
| 139 |
+
//set parameters
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
std::string camera_topic;
|
| 143 |
+
std::string camera_info_topic;
|
| 144 |
+
|
| 145 |
+
nh_priv.param("inverted",inverted, false);
|
| 146 |
+
nh_priv.param<std::string>("camera_topic", camera_topic, "/wide_stereo/right/image_rect_color" );
|
| 147 |
+
nh_priv.param<std::string>("camera_info_topic", camera_info_topic, "/wide_stereo/right/camera_info" );
|
| 148 |
+
|
| 149 |
+
ROS_INFO("camera topic %s", camera_topic.c_str());
|
| 150 |
+
ROS_INFO("camera info %s", camera_info_topic.c_str());
|
| 151 |
+
|
| 152 |
+
//create robot model
|
| 153 |
+
robmod = new RobotMeshModel;
|
| 154 |
+
|
| 155 |
+
//initialize glut
|
| 156 |
+
glutInitWindowSize (robmod->cam_info_->width, robmod->cam_info_->height);
|
| 157 |
+
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
glutCreateWindow ("dummy");
|
| 161 |
+
glutHideWindow();
|
| 162 |
+
|
| 163 |
+
initializeGL();
|
| 164 |
+
// Register glut callbacks:
|
| 165 |
+
glutDisplayFunc (display);
|
| 166 |
+
|
| 167 |
+
ipl_maskBGRA = cvCreateImage(cvSize( robmod->cam_info_->width, robmod->cam_info_->height), IPL_DEPTH_8U, 4);
|
| 168 |
+
ipl_maskBW = cvCreateImage(cvSize( robmod->cam_info_->width, robmod->cam_info_->height), IPL_DEPTH_8U, 1);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
ros::ServiceServer mask_service = nh.advertiseService("self_mask", calcMaskCB );
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
ros::spin();
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
//clean up
|
| 181 |
+
cvReleaseImage(&ipl_maskBGRA);
|
| 182 |
+
cvReleaseImage(&ipl_maskBW);
|
| 183 |
+
delete robmod;
|
| 184 |
+
return 0;
|
| 185 |
+
}
|
| 186 |
+
|
pool/shard010/C++/0111288_CAirbusStaticPort.cpp
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// qt-plus
|
| 3 |
+
#include "CLogger.h"
|
| 4 |
+
|
| 5 |
+
// Quick3D
|
| 6 |
+
#include "CConsoleBoard.h"
|
| 7 |
+
#include "C3DScene.h"
|
| 8 |
+
#include "CAtmosphere.h"
|
| 9 |
+
#include "CAircraft.h"
|
| 10 |
+
|
| 11 |
+
// Application
|
| 12 |
+
#include "CAirbusStaticPort.h"
|
| 13 |
+
|
| 14 |
+
using namespace Math;
|
| 15 |
+
|
| 16 |
+
//-------------------------------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
CComponent* CAirbusStaticPort::instantiator(C3DScene* pScene)
|
| 19 |
+
{
|
| 20 |
+
return new CAirbusStaticPort(pScene);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
//-------------------------------------------------------------------------------------------------
|
| 24 |
+
|
| 25 |
+
CAirbusStaticPort::CAirbusStaticPort(C3DScene* pScene)
|
| 26 |
+
: CComponent(pScene)
|
| 27 |
+
{
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
//-------------------------------------------------------------------------------------------------
|
| 31 |
+
|
| 32 |
+
CAirbusStaticPort::~CAirbusStaticPort()
|
| 33 |
+
{
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
//-------------------------------------------------------------------------------------------------
|
| 37 |
+
|
| 38 |
+
void CAirbusStaticPort::update(double dDeltaTime)
|
| 39 |
+
{
|
| 40 |
+
QSP<CAircraft> pAircraft = QSP_CAST(CAircraft, root());
|
| 41 |
+
|
| 42 |
+
if (pAircraft)
|
| 43 |
+
{
|
| 44 |
+
double dPressure = CAtmosphere::getInstance()->pressure_Nm2(pAircraft->geoloc().Altitude) * N_TO_KG;
|
| 45 |
+
|
| 46 |
+
pushData(CAirbusData(m_sName, adStatic_Pressure_kgm2, dPressure));
|
| 47 |
+
|
| 48 |
+
LOG_VALUE(QString("%1 (PRS KGM2)").arg(m_sName),
|
| 49 |
+
QString("%1")
|
| 50 |
+
.arg(QString::number(dPressure, 'f', 4))
|
| 51 |
+
);
|
| 52 |
+
}
|
| 53 |
+
}
|
pool/shard010/C++/0111293_MSOfficeTextStripper.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <string.h>
|
| 3 |
+
#include "MSOfficeTextStripper.h"
|
| 4 |
+
|
| 5 |
+
#ifdef WIN32
|
| 6 |
+
#include <windows.h>
|
| 7 |
+
#endif
|
| 8 |
+
|
| 9 |
+
using namespace std;
|
| 10 |
+
FX_NS_DEF(plugin);
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
MSOfficeTextStripper::MSOfficeTextStripper(void)
|
| 14 |
+
: m_pTextBuffer(NULL)
|
| 15 |
+
, m_nTextPos(0)
|
| 16 |
+
, m_nTextSize(0)
|
| 17 |
+
{
|
| 18 |
+
m_pAnalyze = new Analyze(this);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
MSOfficeTextStripper::~MSOfficeTextStripper(void)
|
| 22 |
+
{
|
| 23 |
+
if (m_pTextBuffer)
|
| 24 |
+
{
|
| 25 |
+
delete m_pTextBuffer;
|
| 26 |
+
m_pTextBuffer = NULL;
|
| 27 |
+
}
|
| 28 |
+
m_nTextSize = 0;
|
| 29 |
+
m_nTextPos = 0;
|
| 30 |
+
delete m_pAnalyze;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
char* MSOfficeTextStripper::strip(const char* szFileName)
|
| 34 |
+
{
|
| 35 |
+
m_nTextPos = 0;
|
| 36 |
+
|
| 37 |
+
FILE* hFile = fopen(szFileName, "rb");
|
| 38 |
+
if (!hFile)
|
| 39 |
+
return NULL;
|
| 40 |
+
|
| 41 |
+
const char* p = szFileName;
|
| 42 |
+
while(*p)
|
| 43 |
+
p++;
|
| 44 |
+
p--;
|
| 45 |
+
if (*p == L't')
|
| 46 |
+
m_pAnalyze->parsePPT(hFile);
|
| 47 |
+
else if (*p == L's')
|
| 48 |
+
m_pAnalyze->parseXLS(hFile);
|
| 49 |
+
else
|
| 50 |
+
m_pAnalyze->parseDOC(hFile);
|
| 51 |
+
|
| 52 |
+
fclose(hFile);
|
| 53 |
+
|
| 54 |
+
if (m_nTextPos > 0 )
|
| 55 |
+
return m_pTextBuffer;
|
| 56 |
+
return NULL;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void MSOfficeTextStripper::output_paragraph(unsigned short int *buffer)
|
| 60 |
+
{
|
| 61 |
+
size_t len = wcslen((const wchar_t*)buffer);
|
| 62 |
+
if (!m_pTextBuffer || (m_nTextSize - m_nTextPos < len) )
|
| 63 |
+
growBuffer(0);
|
| 64 |
+
#ifdef WIN32
|
| 65 |
+
int nRet = WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)buffer, (int)len,
|
| 66 |
+
m_pTextBuffer + m_nTextPos, (int)m_nTextSize - m_nTextPos, NULL, NULL);
|
| 67 |
+
if (nRet > 0)
|
| 68 |
+
{
|
| 69 |
+
m_nTextPos += nRet;
|
| 70 |
+
}
|
| 71 |
+
#else
|
| 72 |
+
mbstate_t state;
|
| 73 |
+
memset( &state, 0, sizeof(state) );
|
| 74 |
+
wchar_t const* tmp = (wchar_t const*)buffer;
|
| 75 |
+
size_t nRet = wcsrtombs(m_pTextBuffer + m_nTextPos,&tmp,m_nTextSize - m_nTextPos,&state);
|
| 76 |
+
if (nRet != (size_t)-1)
|
| 77 |
+
m_nTextPos += nRet;
|
| 78 |
+
#endif
|
| 79 |
+
if (m_nTextSize - m_nTextPos > 0)
|
| 80 |
+
m_pTextBuffer[m_nTextPos++] = ' ';
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
void MSOfficeTextStripper::growBuffer(size_t nGrowLen)
|
| 84 |
+
{
|
| 85 |
+
size_t nNewLen = m_nTextSize + nGrowLen;
|
| 86 |
+
if (nNewLen < (m_nTextSize << 1) )
|
| 87 |
+
nNewLen = (m_nTextSize << 1);
|
| 88 |
+
if (nNewLen < (size_t)DEFAULT_TEXTBUF_SIZE)
|
| 89 |
+
nNewLen = DEFAULT_TEXTBUF_SIZE;
|
| 90 |
+
char* pBuf = new char[nNewLen];
|
| 91 |
+
if (m_nTextPos > 0)
|
| 92 |
+
memcpy(pBuf,m_pTextBuffer,m_nTextPos);
|
| 93 |
+
delete[] m_pTextBuffer;
|
| 94 |
+
m_pTextBuffer = pBuf;
|
| 95 |
+
m_nTextSize = nNewLen;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
FX_NS_END
|
pool/shard010/C++/0111295_dfsalgo.cpp
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* Copyright © 2016 Oakware - All Rights Reserved
|
| 3 |
+
*
|
| 4 |
+
* Github : <https://github.com/Oakware>
|
| 5 |
+
* Authors: Ivan Kondratuk <i.o.kondratuk@gmail.com>
|
| 6 |
+
*
|
| 7 |
+
* This file is part of Graph Builder.
|
| 8 |
+
*
|
| 9 |
+
* Graph Builder is free software: you can redistribute it and/or modify
|
| 10 |
+
* it under the terms of the GNU General Public License as published by
|
| 11 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 12 |
+
* (at your option) any later version.
|
| 13 |
+
*
|
| 14 |
+
* Graph Builder is distributed in the hope that it will be useful,
|
| 15 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 |
+
* GNU General Public License for more details.
|
| 18 |
+
*
|
| 19 |
+
* You should have received a copy of the GNU General Public License
|
| 20 |
+
* along with Graph Builder. If not, see <http://www.gnu.org/licenses/>.
|
| 21 |
+
*****************************************************************************/
|
| 22 |
+
|
| 23 |
+
#include "dfsalgo.h"
|
| 24 |
+
#include "AlgoPlugins/graphreset.h"
|
| 25 |
+
|
| 26 |
+
#define asleep() if(!sl->sleep(params.sleepTime)) return false;
|
| 27 |
+
|
| 28 |
+
DfsAlgo::DfsAlgo(QObject *par):
|
| 29 |
+
QObject(par)
|
| 30 |
+
{
|
| 31 |
+
sl = new Sleeper(this);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
bool DfsAlgo::run(AbstractGraph *gr, int sver){
|
| 35 |
+
VectorListGS sgr = gr->getGraphModel().toVectorList(); // Return if
|
| 36 |
+
if(sgr.count() <= 1) return false; // no vertexes
|
| 37 |
+
|
| 38 |
+
QBitArray vis(sgr.count()); // Variables
|
| 39 |
+
QStack <int> st;
|
| 40 |
+
int conComp = 1;
|
| 41 |
+
|
| 42 |
+
st << sver; vis[sver] = true;
|
| 43 |
+
resetGraph(gr, "#03A9F4", params.ri.color);
|
| 44 |
+
AG_CHANGE_VER_PARAM((*gr), sver, color, "#7E57C2")
|
| 45 |
+
|
| 46 |
+
while(!st.empty()){
|
| 47 |
+
asleep();
|
| 48 |
+
|
| 49 |
+
int i, v = st.top();
|
| 50 |
+
for(i=0; i<sgr[v].count(); ++i)
|
| 51 |
+
if(!vis[sgr[v][i].to]) break;
|
| 52 |
+
|
| 53 |
+
if(i < sgr[v].count()){
|
| 54 |
+
i = sgr[v][i].to;
|
| 55 |
+
st << i;
|
| 56 |
+
vis[i] = true;
|
| 57 |
+
|
| 58 |
+
AG_CHANGE_VER_PARAM((*gr), i, color, "#7E57C2")
|
| 59 |
+
AG_CHANGE_VER_PARAM((*gr), v, color, "#bdc3c7")
|
| 60 |
+
AG_CHANGE_RIB_PARAM((*gr), ABrib(v,i), color, "#E64A19")
|
| 61 |
+
}else{
|
| 62 |
+
st.pop();
|
| 63 |
+
AG_CHANGE_VER_PARAM((*gr), v, color, "#2c3e50")
|
| 64 |
+
if(!st.empty()){
|
| 65 |
+
AG_CHANGE_VER_PARAM((*gr), st.top(), color, "#7E57C2")
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if(st.empty()){
|
| 70 |
+
for(int i=1; i<sgr.count(); ++i){
|
| 71 |
+
if(!vis[i]){
|
| 72 |
+
st << i; vis[i] = true;
|
| 73 |
+
AG_CHANGE_VER_PARAM((*gr), i, color, "#7E57C2")
|
| 74 |
+
++conComp; break;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
result = tr("Finished.");
|
| 81 |
+
if(!gr->isOriented()){
|
| 82 |
+
result += '\n';
|
| 83 |
+
result += tr("Connected components count: ")
|
| 84 |
+
+ QString::number(conComp);
|
| 85 |
+
}
|
| 86 |
+
return true;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void DfsAlgo::stop(){
|
| 90 |
+
sl->stop();
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
QString DfsAlgo::name(){
|
| 94 |
+
return tr("DFS");
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
QString DfsAlgo::qmlDialog(){
|
| 98 |
+
return "qrc:/DFS/ResDialog.qml";
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
QString DfsAlgo::getResult(){
|
| 102 |
+
return result;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
void DfsAlgo::setParams(const plugParams &pp){
|
| 106 |
+
params = pp;
|
| 107 |
+
}
|
pool/shard010/C++/0111298_DeferredRenderPipeline.cpp
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "DeferredRenderPipeline.h"
|
| 2 |
+
#include "SceneManager.h"
|
| 3 |
+
#include "MeshRendererComponent.h"
|
| 4 |
+
#include "Lighting.h"
|
| 5 |
+
|
| 6 |
+
using namespace std;
|
| 7 |
+
using namespace AnEngine::Game;
|
| 8 |
+
using namespace AnEngine::RenderCore;
|
| 9 |
+
|
| 10 |
+
namespace AnEngine::RenderCore
|
| 11 |
+
{
|
| 12 |
+
void DeferredRenderPipeline::OnRender(std::mutex& sceneResMutex)
|
| 13 |
+
{
|
| 14 |
+
FenceContext::Instance()->WaitAllFence();
|
| 15 |
+
|
| 16 |
+
/* GBuffer阶段,渲染所有摄像机的 GBuffer、Depth、Normal */
|
| 17 |
+
//lock_guard<mutex> lock(sceneResMutex);
|
| 18 |
+
GBuffer();
|
| 19 |
+
|
| 20 |
+
/* 对于场景中的每一个光源,绘制其深度图,以生成阴影。 */
|
| 21 |
+
//lock_guard<mutex> lock(sceneResMutex);
|
| 22 |
+
DepthPreLight();
|
| 23 |
+
|
| 24 |
+
/* 阴影 */
|
| 25 |
+
FenceContext::Instance()->WaitAllFence();
|
| 26 |
+
Shadow();
|
| 27 |
+
|
| 28 |
+
/* 反射 */
|
| 29 |
+
|
| 30 |
+
/* 使用前向渲染处理半透明物体 */
|
| 31 |
+
|
| 32 |
+
/* 天空盒 */
|
| 33 |
+
|
| 34 |
+
/* 全屏后处理 */
|
| 35 |
+
FenceContext::Instance()->WaitAllFence();
|
| 36 |
+
PostProcess();
|
| 37 |
+
|
| 38 |
+
/* 绘制UI组件 */
|
| 39 |
+
UI();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
void DeferredRenderPipeline::GBuffer()
|
| 43 |
+
{
|
| 44 |
+
var scene = Game::SceneManager::ActiveScene();
|
| 45 |
+
// 网格渲染器是 ECS 组织的
|
| 46 |
+
var objs = scene->GetGroupOfType<Component::MeshRenderer>(); // 从场景中获取所有的 Mesh Renderer 组件进行渲染
|
| 47 |
+
const auto& mrs = *objs;
|
| 48 |
+
var[list, allocator] = GraphicsContext::GetOne();
|
| 49 |
+
var ilist = list->GetCommandList();
|
| 50 |
+
var iallocator = allocator->GetAllocator();
|
| 51 |
+
ThrowIfFailed(iallocator->Reset());
|
| 52 |
+
|
| 53 |
+
ThrowIfFailed(ilist->Close());
|
| 54 |
+
GraphicsContext::Push(list, allocator);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void DeferredRenderPipeline::DepthPreLight()
|
| 58 |
+
{
|
| 59 |
+
var scene = Game::SceneManager::ActiveScene();
|
| 60 |
+
// 灯光是 Behaviour 组织的
|
| 61 |
+
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
void DeferredRenderPipeline::Shadow()
|
| 65 |
+
{
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void DeferredRenderPipeline::UI()
|
| 69 |
+
{
|
| 70 |
+
}
|
| 71 |
+
void DeferredRenderPipeline::PostProcess()
|
| 72 |
+
{
|
| 73 |
+
}
|
| 74 |
+
}
|
pool/shard010/C++/0111302_QGis.cpp
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/************************************************************************************
|
| 2 |
+
TerraME - a software platform for multiple scale spatially-explicit dynamic modeling.
|
| 3 |
+
Copyright (C) 2001-2017 INPE and TerraLAB/UFOP -- www.terrame.org
|
| 4 |
+
|
| 5 |
+
This code is part of the TerraME framework.
|
| 6 |
+
This framework is free software; you can redistribute it and/or
|
| 7 |
+
modify it under the terms of the GNU Lesser General Public
|
| 8 |
+
License as published by the Free Software Foundation; either
|
| 9 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 10 |
+
|
| 11 |
+
You should have received a copy of the GNU Lesser General Public
|
| 12 |
+
License along with this library.
|
| 13 |
+
|
| 14 |
+
The authors reassure the license terms regarding the warranties.
|
| 15 |
+
They specifically disclaim any warranties, including, but not limited to,
|
| 16 |
+
the implied warranties of merchantability and fitness for a particular purpose.
|
| 17 |
+
The framework provided hereunder is on an "as is" basis, and the authors have no
|
| 18 |
+
obligation to provide maintenance, support, updates, enhancements, or modifications.
|
| 19 |
+
In no event shall INPE and TerraLAB / UFOP be held liable to any party for direct,
|
| 20 |
+
indirect, special, incidental, or consequential damages arising out of the use
|
| 21 |
+
of this software and its documentation.
|
| 22 |
+
*************************************************************************************/
|
| 23 |
+
|
| 24 |
+
#include "QGis.h"
|
| 25 |
+
|
| 26 |
+
#include <boost/filesystem.hpp>
|
| 27 |
+
|
| 28 |
+
#include "QgsReader.h"
|
| 29 |
+
#include "QgsWriter.h"
|
| 30 |
+
#include "Utils.h"
|
| 31 |
+
|
| 32 |
+
terrame::qgis::QGis& terrame::qgis::QGis::getInstance()
|
| 33 |
+
{
|
| 34 |
+
static terrame::qgis::QGis instance;
|
| 35 |
+
return instance;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
terrame::qgis::QGisProject terrame::qgis::QGis::read(const std::string& qgsfile)
|
| 39 |
+
{
|
| 40 |
+
QgsReader reader;
|
| 41 |
+
reader.setPostgisRole(user, password);
|
| 42 |
+
return reader.read(qgsfile);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void terrame::qgis::QGis::write(const QGisProject& qgp)
|
| 46 |
+
{
|
| 47 |
+
QgsWriter writer;
|
| 48 |
+
|
| 49 |
+
if (boost::filesystem::exists(qgp.getFile()))
|
| 50 |
+
{
|
| 51 |
+
QGisProject fileQgp = getInstance().read(qgp.getFile());
|
| 52 |
+
std::vector<QGisLayer> layersInFile = fileQgp.getLayers();
|
| 53 |
+
std::vector<QGisLayer> layersParam = qgp.getLayers();
|
| 54 |
+
std::vector<QGisLayer> layersToAdd = fileQgp.getLayersDiff(qgp);
|
| 55 |
+
std::vector<QGisLayer> layersToRemove = qgp.getLayersDiff(fileQgp);
|
| 56 |
+
|
| 57 |
+
if(layersToAdd.size() > 0)
|
| 58 |
+
{
|
| 59 |
+
writer.addLayers(qgp, layersToAdd);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
if(layersToRemove.size() > 0)
|
| 63 |
+
{
|
| 64 |
+
writer.removeLayers(qgp, layersToRemove);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
else
|
| 68 |
+
{
|
| 69 |
+
writer.create(qgp);
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void terrame::qgis::QGis::setPostgisRole(const std::string& user,
|
| 74 |
+
const std::string& password)
|
| 75 |
+
{
|
| 76 |
+
this->user = user;
|
| 77 |
+
this->password = password;
|
| 78 |
+
}
|
pool/shard010/C++/0111303_enumliterals.cpp
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "enumliterals.h"
|
| 2 |
+
|
| 3 |
+
#include "dock/pages/model/enumliteralsmodel.h"
|
| 4 |
+
|
| 5 |
+
EnumLiterals::EnumLiterals(QWidget* parent) : PageBase(parent),ui(new Ui_GenericTable()),m_pModel(0)
|
| 6 |
+
{
|
| 7 |
+
ui->setupUi(this);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
EnumLiterals::~EnumLiterals()
|
| 11 |
+
{
|
| 12 |
+
delete ui;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
void EnumLiterals::setCurrentObject(UMLObject* o)
|
| 16 |
+
{
|
| 17 |
+
if (!m_pModel) {
|
| 18 |
+
m_pModel = new EnumLiteralsModel(this);
|
| 19 |
+
ui->m_pTable->setModel(m_pModel);
|
| 20 |
+
ui->m_pTable->horizontalHeader()->setResizeMode(0,QHeaderView::Stretch);
|
| 21 |
+
for (int i=1;i<m_pModel->columnCount();i++) {
|
| 22 |
+
ui->m_pTable->horizontalHeader()->setResizeMode(i,QHeaderView::ResizeToContents);
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
m_pModel->setCurrentObject(o);
|
| 26 |
+
}
|
pool/shard010/C++/0111308_playerwatcher.cpp
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "playerwatcher.h"
|
| 2 |
+
|
| 3 |
+
#include "playerinterface.h"
|
| 4 |
+
#include "propertiesinterface.h"
|
| 5 |
+
|
| 6 |
+
#include <QDBusConnection>
|
| 7 |
+
#include <QDBusServiceWatcher>
|
| 8 |
+
|
| 9 |
+
#include <iostream>
|
| 10 |
+
|
| 11 |
+
using namespace std;
|
| 12 |
+
using namespace CppUtilities;
|
| 13 |
+
|
| 14 |
+
namespace DBusSoundRecorder {
|
| 15 |
+
|
| 16 |
+
inline ostream &operator<<(ostream &stream, const QString &str)
|
| 17 |
+
{
|
| 18 |
+
return stream << str.toLocal8Bit().data();
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
PlayerWatcher::PlayerWatcher(const QString &appName, bool ignorePlaybackStatus, QObject *parent)
|
| 22 |
+
: QObject(parent)
|
| 23 |
+
, m_mediaPlayerInterfaceName(QStringLiteral("org.mpris.MediaPlayer2.%1").arg(appName))
|
| 24 |
+
, m_mediaPlayerServiceWatcher(
|
| 25 |
+
new QDBusServiceWatcher(m_mediaPlayerInterfaceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this))
|
| 26 |
+
, m_propertiesInterface(new OrgFreedesktopDBusPropertiesInterface(
|
| 27 |
+
m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this))
|
| 28 |
+
, m_playerInterface(new OrgMprisMediaPlayer2PlayerInterface(
|
| 29 |
+
m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this))
|
| 30 |
+
, m_isPlaying(false)
|
| 31 |
+
, m_isAd(false)
|
| 32 |
+
, m_trackNumber(0)
|
| 33 |
+
, m_diskNumber(0)
|
| 34 |
+
, m_silent(false)
|
| 35 |
+
, m_ignorePlaybackStatus(ignorePlaybackStatus)
|
| 36 |
+
{
|
| 37 |
+
if (!connect(m_mediaPlayerServiceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &PlayerWatcher::serviceOwnerChanged)) {
|
| 38 |
+
cout << "Warning: Unable to connect \"serviceOwnerChanged\" signal of service watcher." << endl;
|
| 39 |
+
}
|
| 40 |
+
// The code below might not work with some players:
|
| 41 |
+
//if(!connect(m_propertiesInterface, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, this, &PlayerWatcher::propertiesChanged)) {
|
| 42 |
+
// cout << "Warning: Unable to connect \"PropertiesChanged\" signal of properties interface." << endl;
|
| 43 |
+
//}
|
| 44 |
+
// However, the following seems to work always:
|
| 45 |
+
if (!QDBusConnection::sessionBus().connect(m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"),
|
| 46 |
+
QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"), this, SLOT(propertiesChanged()))) {
|
| 47 |
+
cout << "Warning: Unable to connect \"PropertiesChanged\" signal of properties interface." << endl;
|
| 48 |
+
}
|
| 49 |
+
propertiesChanged();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void PlayerWatcher::play()
|
| 53 |
+
{
|
| 54 |
+
m_playerInterface->Play();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void PlayerWatcher::stop()
|
| 58 |
+
{
|
| 59 |
+
m_playerInterface->Stop();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
void PlayerWatcher::pause()
|
| 63 |
+
{
|
| 64 |
+
m_playerInterface->Pause();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
void PlayerWatcher::playPause()
|
| 68 |
+
{
|
| 69 |
+
m_playerInterface->PlayPause();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
void PlayerWatcher::serviceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner)
|
| 73 |
+
{
|
| 74 |
+
if (oldOwner.isEmpty()) {
|
| 75 |
+
cerr << "MPRIS service \"" << service << "\" is now online" << endl;
|
| 76 |
+
}
|
| 77 |
+
if (newOwner.isEmpty()) {
|
| 78 |
+
cerr << "MPRIS service \"" << service << "\" went offline" << endl;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void PlayerWatcher::propertiesChanged()
|
| 83 |
+
{
|
| 84 |
+
// get meta data
|
| 85 |
+
QVariantMap metadata = m_playerInterface->metadata();
|
| 86 |
+
m_isAd = metadata.value(QStringLiteral("mpris:trackid")).toString().startsWith(QLatin1String("spotify:ad"));
|
| 87 |
+
QString title = metadata.value(QStringLiteral("xesam:title")).toString();
|
| 88 |
+
QString album = metadata.value(QStringLiteral("xesam:album")).toString();
|
| 89 |
+
QString artist = metadata.value(QStringLiteral("xesam:artist")).toString();
|
| 90 |
+
bool isPlaying;
|
| 91 |
+
if (m_ignorePlaybackStatus) {
|
| 92 |
+
// determine playback status by checking whether there is a song title
|
| 93 |
+
isPlaying = !title.isEmpty();
|
| 94 |
+
} else {
|
| 95 |
+
isPlaying = !m_playerInterface->playbackStatus().compare(QLatin1String("playing"), Qt::CaseInsensitive);
|
| 96 |
+
}
|
| 97 |
+
if (isPlaying) {
|
| 98 |
+
if (!m_isPlaying) {
|
| 99 |
+
cerr << "Playback started" << endl;
|
| 100 |
+
}
|
| 101 |
+
// use title, album and artist to identify song
|
| 102 |
+
if (m_title != title || m_album != album || m_artist != artist) {
|
| 103 |
+
// next song playing
|
| 104 |
+
m_title = title;
|
| 105 |
+
m_album = album;
|
| 106 |
+
m_artist = artist;
|
| 107 |
+
// read additional meta data
|
| 108 |
+
m_year = metadata.value(QStringLiteral("xesam:contentCreated")).toString();
|
| 109 |
+
m_genre = metadata.value(QStringLiteral("xesam:genre")).toString();
|
| 110 |
+
m_trackNumber = metadata.value(QStringLiteral("xesam:tracknumber")).toUInt();
|
| 111 |
+
if (!m_trackNumber) {
|
| 112 |
+
m_trackNumber = metadata.value(QStringLiteral("xesam:trackNumber")).toUInt();
|
| 113 |
+
}
|
| 114 |
+
m_diskNumber = metadata.value(QStringLiteral("xesam:discnumber")).toUInt();
|
| 115 |
+
if (!m_diskNumber) {
|
| 116 |
+
m_diskNumber = metadata.value(QStringLiteral("xesam:discNumber")).toUInt();
|
| 117 |
+
}
|
| 118 |
+
m_length = TimeSpan(metadata.value(QStringLiteral("mpris:length")).toULongLong() * 10);
|
| 119 |
+
// notify
|
| 120 |
+
cerr << "Next song: " << m_title << endl;
|
| 121 |
+
if (!m_isPlaying && !m_silent) {
|
| 122 |
+
m_isPlaying = true;
|
| 123 |
+
emit playbackStarted();
|
| 124 |
+
}
|
| 125 |
+
if (!m_silent) {
|
| 126 |
+
m_isPlaying = true;
|
| 127 |
+
emit nextSong();
|
| 128 |
+
}
|
| 129 |
+
} else if (!m_isPlaying) {
|
| 130 |
+
if (!m_silent) {
|
| 131 |
+
m_isPlaying = true;
|
| 132 |
+
emit playbackStarted();
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
} else if (m_isPlaying) {
|
| 136 |
+
m_isPlaying = false;
|
| 137 |
+
cerr << "Playback stopped" << endl;
|
| 138 |
+
if (!m_silent) {
|
| 139 |
+
emit playbackStopped();
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
void PlayerWatcher::notificationReceived()
|
| 145 |
+
{
|
| 146 |
+
cout << "It works!" << endl;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
void PlayerWatcher::seeked(qlonglong pos)
|
| 150 |
+
{
|
| 151 |
+
cerr << "Seeked: " << pos << endl;
|
| 152 |
+
}
|
| 153 |
+
} // namespace DBusSoundRecorder
|